From 4e766d7bd30d2348ec9a739ed81eb35cb62e58e1 Mon Sep 17 00:00:00 2001 From: jtlap Date: Tue, 13 Dec 2022 23:23:41 +0100 Subject: [PATCH] Implements complex rsqrt --- include/eve/arch/arm/sve/top_bits.hpp | 3 ++- include/eve/arch/cpu/top_bits.hpp | 4 +++- include/eve/arch/cpu/wide.hpp | 2 +- include/eve/arch/x86/top_bits.hpp | 3 ++- include/eve/concept/scalar.hpp | 19 ++++++++++++------- include/eve/module/complex/complex.hpp | 3 ++- include/eve/module/complex/detail/math.hpp | 11 +++++++++++ include/eve/module/complex/regular/traits.hpp | 2 +- 8 files changed, 34 insertions(+), 13 deletions(-) diff --git a/include/eve/arch/arm/sve/top_bits.hpp b/include/eve/arch/arm/sve/top_bits.hpp index a8a24ca1e0..21d9f27c87 100644 --- a/include/eve/arch/arm/sve/top_bits.hpp +++ b/include/eve/arch/arm/sve/top_bits.hpp @@ -23,7 +23,8 @@ requires(current_api >= sve && !has_aggregated_abi_v) struct top_bits>>; + static constexpr auto half_size = (static_size/2 > 0) ? static_size/2 : 1; + using half_logical = logical>>; using storage_type = logical>; static constexpr std::ptrdiff_t bits_per_element = sizeof(scalar_type); diff --git a/include/eve/arch/cpu/top_bits.hpp b/include/eve/arch/cpu/top_bits.hpp index 95f77bd98e..8c6abc69d7 100644 --- a/include/eve/arch/cpu/top_bits.hpp +++ b/include/eve/arch/cpu/top_bits.hpp @@ -94,8 +94,10 @@ namespace detail static constexpr bool is_aggregated = has_aggregated_abi_v || (has_emulated_abi_v && static_size > 64); + static constexpr auto half_size = (static_size/2 > 0) ? static_size/2 : 1; + //! logical or half size - using half_logical = logical>>; + using half_logical = logical>>; private: EVE_FORCEINLINE static auto storage_type_impl() diff --git a/include/eve/arch/cpu/wide.hpp b/include/eve/arch/cpu/wide.hpp index d8ecda7821..4a5f427cdd 100644 --- a/include/eve/arch/cpu/wide.hpp +++ b/include/eve/arch/cpu/wide.hpp @@ -162,7 +162,7 @@ namespace eve template explicit EVE_FORCEINLINE wide(S0 const& v0, Ss const&...vs) noexcept requires kumi::sized_product_type - : storage_base(kumi::map([](auto const& n, W const&) { return W {n}; }, + : storage_base(kumi::map([](auto const& n, W const&) { return W{n}; }, kumi::make_tuple(v0, vs...), *this)) {} diff --git a/include/eve/arch/x86/top_bits.hpp b/include/eve/arch/x86/top_bits.hpp index 3feb2e3dc6..1f78ebc14a 100644 --- a/include/eve/arch/x86/top_bits.hpp +++ b/include/eve/arch/x86/top_bits.hpp @@ -19,7 +19,8 @@ requires(current_api >= avx512 && !has_aggregated_abi_v) struct top_bit static constexpr std::ptrdiff_t static_size = logical_type::size(); static constexpr bool is_aggregated = false; - using half_logical = logical>>; + static constexpr auto half_size = (static_size/2 > 0) ? static_size/2 : 1; + using half_logical = logical>>; private: static constexpr std::ptrdiff_t storage_cardinal = [] diff --git a/include/eve/concept/scalar.hpp b/include/eve/concept/scalar.hpp index 7ee3edb766..544cdb8c12 100644 --- a/include/eve/concept/scalar.hpp +++ b/include/eve/concept/scalar.hpp @@ -17,26 +17,31 @@ namespace eve { -template -concept plain_scalar_value - = !(std::is_same_v || std::is_same_v) - && (std::is_floating_point_v || std::is_integral_v); - namespace detail { template - constexpr bool scalar_tuple() + constexpr bool is_plain() noexcept + { + return !(std::is_same_v || std::is_same_v) + && (std::is_floating_point_v || std::is_integral_v); + } + + template + constexpr bool scalar_tuple() noexcept { if constexpr(!kumi::product_type) return false; else { - constexpr auto f = [](M) { return std::bool_constant>{}; }; + constexpr auto f = [](M) { return std::bool_constant()>{}; }; using flt_t = kumi::result::flatten_all_t, decltype(f)>; return kumi::all_of( flt_t{}, [](bool b) { return b; } ); } } } +template +concept plain_scalar_value = detail::is_plain(); + template concept product_scalar_value = detail::scalar_tuple(); diff --git a/include/eve/module/complex/complex.hpp b/include/eve/module/complex/complex.hpp index 37e9726f2a..686dddd376 100644 --- a/include/eve/module/complex/complex.hpp +++ b/include/eve/module/complex/complex.hpp @@ -48,7 +48,8 @@ namespace eve using underlying_type = underlying_type_t; /// 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 diff --git a/include/eve/module/complex/detail/math.hpp b/include/eve/module/complex/detail/math.hpp index a0a4628b3b..fcb48de7cd 100644 --- a/include/eve/module/complex/detail/math.hpp +++ b/include/eve/module/complex/detail/math.hpp @@ -78,6 +78,17 @@ namespace eve::detail return if_else(negimag, conj(res), res); } + //===------------------------------------------------------------------------------------------- + // Unary functions : rsqrt + //===------------------------------------------------------------------------------------------- + template + EVE_FORCEINLINE auto complex_unary_dispatch( eve::tag::rsqrt_ + , Z const& z + ) noexcept + { + return rec(sqrt(z)); + } + //===------------------------------------------------------------------------------------------- //=== cosh //===------------------------------------------------------------------------------------------- diff --git a/include/eve/module/complex/regular/traits.hpp b/include/eve/module/complex/regular/traits.hpp index c6d5bdb4f5..beceaa58a0 100644 --- a/include/eve/module/complex/regular/traits.hpp +++ b/include/eve/module/complex/regular/traits.hpp @@ -15,7 +15,7 @@ namespace eve template struct as_complex; - template struct as_complex + template struct as_complex { using type = eve::complex; };