Skip to content

Commit

Permalink
Implements complex rsqrt
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlap authored Dec 13, 2022
1 parent 4bd7df6 commit 4e766d7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 13 deletions.
3 changes: 2 additions & 1 deletion include/eve/arch/arm/sve/top_bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ requires(current_api >= sve && !has_aggregated_abi_v<Logical>) struct top_bits<L
static constexpr std::ptrdiff_t static_size = logical_type::size();
static constexpr bool is_aggregated = false;

using half_logical = logical<wide<scalar_type, eve::fixed<static_size / 2>>>;
static constexpr auto half_size = (static_size/2 > 0) ? static_size/2 : 1;
using half_logical = logical<wide<scalar_type, eve::fixed<half_size>>>;
using storage_type = logical<wide<scalar_type>>;

static constexpr std::ptrdiff_t bits_per_element = sizeof(scalar_type);
Expand Down
4 changes: 3 additions & 1 deletion include/eve/arch/cpu/top_bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ namespace detail
static constexpr bool is_aggregated = has_aggregated_abi_v<logical_type> ||
(has_emulated_abi_v<logical_type> && static_size > 64);

static constexpr auto half_size = (static_size/2 > 0) ? static_size/2 : 1;

//! logical or half size
using half_logical = logical<wide<scalar_type, eve::fixed<static_size / 2>>>;
using half_logical = logical<wide<scalar_type, eve::fixed<half_size>>>;

private:
EVE_FORCEINLINE static auto storage_type_impl()
Expand Down
2 changes: 1 addition & 1 deletion include/eve/arch/cpu/wide.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace eve
template<typename S0, typename... Ss>
explicit EVE_FORCEINLINE wide(S0 const& v0, Ss const&...vs) noexcept
requires kumi::sized_product_type<Type, sizeof...(Ss) + 1>
: storage_base(kumi::map([]<typename W>(auto const& n, W const&) { return W {n}; },
: storage_base(kumi::map([]<typename W>(auto const& n, W const&) { return W{n}; },
kumi::make_tuple(v0, vs...),
*this))
{}
Expand Down
3 changes: 2 additions & 1 deletion include/eve/arch/x86/top_bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ requires(current_api >= avx512 && !has_aggregated_abi_v<Logical>) struct top_bit
static constexpr std::ptrdiff_t static_size = logical_type::size();
static constexpr bool is_aggregated = false;

using half_logical = logical<wide<scalar_type, eve::fixed<static_size / 2>>>;
static constexpr auto half_size = (static_size/2 > 0) ? static_size/2 : 1;
using half_logical = logical<wide<scalar_type, eve::fixed<half_size>>>;

private:
static constexpr std::ptrdiff_t storage_cardinal = []
Expand Down
19 changes: 12 additions & 7 deletions include/eve/concept/scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,31 @@

namespace eve
{
template<typename T>
concept plain_scalar_value
= !(std::is_same_v<T, bool> || std::is_same_v<T, long double>)
&& (std::is_floating_point_v<T> || std::is_integral_v<T>);

namespace detail
{
template<typename T>
constexpr bool scalar_tuple()
constexpr bool is_plain() noexcept
{
return !(std::is_same_v<T, bool> || std::is_same_v<T, long double>)
&& (std::is_floating_point_v<T> || std::is_integral_v<T>);
}

template<typename T>
constexpr bool scalar_tuple() noexcept
{
if constexpr(!kumi::product_type<T>) return false;
else
{
constexpr auto f = []<typename M>(M) { return std::bool_constant<plain_scalar_value<M>>{}; };
constexpr auto f = []<typename M>(M) { return std::bool_constant<is_plain<M>()>{}; };
using flt_t = kumi::result::flatten_all_t<kumi::as_tuple_t<T>, decltype(f)>;
return kumi::all_of( flt_t{}, [](bool b) { return b; } );
}
}
}

template<typename T>
concept plain_scalar_value = detail::is_plain<T>();

template<typename T>
concept product_scalar_value = detail::scalar_tuple<T>();

Expand Down
3 changes: 2 additions & 1 deletion include/eve/module/complex/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ namespace eve
using underlying_type = underlying_type_t<Type>;

/// Default constructor
explicit complex(Type r = 0) noexcept : parent{r,0} {}
complex() noexcept : parent{0,0} {}
explicit complex(Type r ) noexcept : parent{r,0} {}
complex(Type r, Type i) noexcept : parent{r,i} {}

/// Stream insertion operator
Expand Down
11 changes: 11 additions & 0 deletions include/eve/module/complex/detail/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ namespace eve::detail
return if_else(negimag, conj(res), res);
}

//===-------------------------------------------------------------------------------------------
// Unary functions : rsqrt
//===-------------------------------------------------------------------------------------------
template<typename Z>
EVE_FORCEINLINE auto complex_unary_dispatch( eve::tag::rsqrt_
, Z const& z
) noexcept
{
return rec(sqrt(z));
}

//===-------------------------------------------------------------------------------------------
//=== cosh
//===-------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion include/eve/module/complex/regular/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace eve

template<typename T> struct as_complex;

template<floating_scalar_value T> struct as_complex<T>
template<scalar_value T> struct as_complex<T>
{
using type = eve::complex<T>;
};
Expand Down

0 comments on commit 4e766d7

Please sign in to comment.