Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup useless/non-constexpr branchs #2025

Merged
merged 7 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions include/eve/arch/cpu/top_bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,32 @@ namespace detail
else return movemask(logical_type{}).first;
}

EVE_FORCEINLINE static constexpr std::ptrdiff_t bits_per_element_impl()
EVE_FORCEINLINE static consteval std::ptrdiff_t bits_per_element_impl()
{
if constexpr ( is_aggregated ) return top_bits<half_logical>::bits_per_element;
else return decltype(movemask(logical_type{}).second){}();
}

static constexpr bool is_cheap_impl()
static consteval bool is_cheap_impl()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same story here - we don't want the ifs to be constexpr when t doesn't have to. And I don't like consteval for no reason.

{
if ( has_emulated_abi_v<logical_type> ) return true;
if constexpr ( is_aggregated ) return top_bits<half_logical>::is_cheap;
if constexpr ( has_emulated_abi_v<logical_type> ) return true;
else if constexpr ( is_aggregated ) return top_bits<half_logical>::is_cheap;

if ( x86_abi<abi_type> ) return true;
if ( ppc_abi<abi_type> ) return true;
else if constexpr ( x86_abi<abi_type> ) return true;
else if constexpr ( ppc_abi<abi_type> ) return true;

if ( arm_abi<abi_type> )
else if constexpr ( arm_abi<abi_type> )
{
if ( static_size == 1 ) return true;
if ( static_size * sizeof(scalar_type) <= 4 ) return true;
if ( current_api >= eve::asimd )
if constexpr ( static_size == 1 ) return true;
else if constexpr ( static_size * sizeof(scalar_type) <= 4 ) return true;
else if constexpr ( current_api >= eve::asimd )
{
if ( sizeof(scalar_type) >= 2 ) return true;
if constexpr ( sizeof(scalar_type) >= 2 ) return true;
return static_size <= 8; // 16 chars is expensive
}
return false;
else return false;
}
return false;
else return false;
}

public:
Expand Down
8 changes: 4 additions & 4 deletions include/eve/arch/riscv/rvv_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ constexpr auto rvv_lmul_v = []
{
constexpr std::ptrdiff_t m1_len = __riscv_v_fixed_vlen;
constexpr std::ptrdiff_t min_len = m1_len * sizeof(scalar_type) / 8;
std::ptrdiff_t expected_len = sizeof(scalar_type) * 8 * cardinal::value;
std::ptrdiff_t reg_len = std::max(min_len, expected_len);
if( reg_len >= m1_len ) return static_cast<int>(reg_len / m1_len);
constexpr std::ptrdiff_t expected_len = sizeof(scalar_type) * 8 * cardinal::value;
constexpr std::ptrdiff_t reg_len = std::max(min_len, expected_len);
if constexpr ( reg_len >= m1_len ) return static_cast<int>(reg_len / m1_len);
else return -static_cast<int>(m1_len / reg_len);
}();

template<plain_scalar_value scalar_type, typename cardinal>
constexpr auto rvv_logical_ratio_v = []
{
auto lmul = rvv_lmul_v<scalar_type, cardinal>;
constexpr auto lmul = rvv_lmul_v<scalar_type, cardinal>;
constexpr auto element_size = sizeof(scalar_type) * 8;
return lmul > 0 ? element_size / lmul : element_size * (-lmul);
}();
Expand Down
76 changes: 42 additions & 34 deletions include/eve/module/core/named_shuffles/blend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace eve
struct blend_t
{
template<simd_value T, std::ptrdiff_t G, std::ptrdiff_t... I>
static constexpr auto pattern(eve::as<T>, eve::as<T>, eve::fixed<G>, pattern_t<I...>)
static consteval auto pattern(eve::as<T>, eve::as<T>, eve::fixed<G>, pattern_t<I...>)
{
static_assert(((0 <= I && I <= 1) && ...), "pattern for blend has to only contain 0 and 1");
static_assert(pattern_t<I...>::size() * G == T::size(), "pattern has wrong number of elements");
Expand All @@ -82,7 +82,7 @@ struct blend_t
}

template<simd_value T, std::ptrdiff_t G, std::ptrdiff_t... I>
static constexpr std::ptrdiff_t level(eve::as<T>, eve::as<T>, eve::fixed<G> g, pattern_t<I...> p)
static consteval std::ptrdiff_t level(eve::as<T>, eve::as<T>, eve::fixed<G> g, pattern_t<I...> p)
{
if constexpr( sizeof...(I) == 1 ) return 0;
else if constexpr( eve::has_aggregated_abi_v<T> )
Expand All @@ -95,53 +95,61 @@ struct blend_t
level(as<half_t> {}, as<half_t> {}, g, p1));
}

if( ((I == 0) && ...) ) return 0;
if( ((I == 1) && ...) ) return 0;
else if constexpr ( ((I == 0) && ...) ) return 0;
else if constexpr ( ((I == 1) && ...) ) return 0;

if( current_api >= sve ) return logical_simd_value<T> ? 6 : 2;
if( current_api >= avx512 ) return logical_simd_value<T> ? 6 : 2;
if( current_api >= vmx ) return 3;

const std::ptrdiff_t g_size = sizeof(element_type_t<T>) * G;
const std::size_t reg_size = sizeof(element_type_t<T>) * T::size();
const std::size_t count_from_x = ((I == 0) + ...);
const std::size_t count_from_y = ((I == 1) + ...);

if( current_api >= neon )
else if constexpr ( current_api >= sve ) return logical_simd_value<T> ? 6 : 2;
else if constexpr ( current_api >= avx512 ) return logical_simd_value<T> ? 6 : 2;
else if constexpr ( current_api >= vmx ) return 3;
else
{
if( current_api >= asimd && (count_from_x == 1 || count_from_y == 1) ) return 2;
return 3;
}
constexpr std::ptrdiff_t g_size = sizeof(element_type_t<T>) * G;
constexpr std::size_t reg_size = sizeof(element_type_t<T>) * T::size();
constexpr std::size_t count_from_x = ((I == 0) + ...);
constexpr std::size_t count_from_y = ((I == 1) + ...);

if( current_api >= sse2 )
{
if constexpr( current_api == avx && reg_size >= 32 && g_size <= 2 )
if constexpr ( current_api >= neon )
{
using half_t = decltype(T {}.slice(lower_));
auto [p0, p1] = detail::idxm::slice_pattern<pattern_t<I...>::size() / 2>(p);
auto l0 = level(as<half_t> {}, as<half_t> {}, g, p0);
auto l1 = level(as<half_t> {}, as<half_t> {}, g, p1);
return detail::idxm::add_shuffle_levels(std::array<std::ptrdiff_t, 3> {l0, l1, 4});
if constexpr ( current_api >= asimd && (count_from_x == 1 || count_from_y == 1) ) return 2;
else return 3;
}
else if constexpr ( current_api >= sse2 )
{
if constexpr( current_api == avx && reg_size >= 32 && g_size <= 2 )
{
using half_t = decltype(T {}.slice(lower_));
auto [p0, p1] = detail::idxm::slice_pattern<pattern_t<I...>::size() / 2>(p);
auto l0 = level(as<half_t> {}, as<half_t> {}, g, p0);
auto l1 = level(as<half_t> {}, as<half_t> {}, g, p1);
return detail::idxm::add_shuffle_levels(std::array<std::ptrdiff_t, 3> {l0, l1, 4});
}
else if constexpr ( current_api >= sse4_1 )
{
return g_size >= 4 ? 2 : 3;
}
else
{
if constexpr ( g_size >= 8 ) return 2;
else if constexpr ( g_size == 2 && reg_size == 4 ) return 6;
else return 7;
}
}
else
{
return 2;
}
if( current_api >= sse4_1 ) return g_size >= 4 ? 2 : 3;

if( g_size >= 8 ) return 2;
if( g_size == 2 && reg_size == 4 ) return 6;
return 7;
}

return 2;
}

template<simd_value T, std::ptrdiff_t G>
static constexpr auto
static consteval auto
pattern(eve::as<T> tgt, eve::as<T>, eve::fixed<G> g, pattern_formula auto gen)
{
return pattern(tgt, tgt, g, fix_pattern<T::size() / G>(gen));
}

template<simd_value T, std::ptrdiff_t G, std::ptrdiff_t... I>
static constexpr auto level(eve::as<T> tgt, eve::as<T>, eve::fixed<G> g, pattern_formula auto gen)
static consteval auto level(eve::as<T> tgt, eve::as<T>, eve::fixed<G> g, pattern_formula auto gen)
{
return level(tgt, tgt, g, fix_pattern<T::size() / G>(gen));
}
Expand Down
64 changes: 32 additions & 32 deletions include/eve/module/core/named_shuffles/broadcast_lane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ namespace eve
struct broadcast_lane_t
{
template<simd_value T, std::ptrdiff_t G, std::ptrdiff_t I>
static constexpr auto pattern(eve::as<T>, eve::fixed<G>, eve::index_t<I>)
static consteval auto pattern(eve::as<T>, eve::fixed<G>, eve::index_t<I>)
{
static_assert(I < T::size() / G);
return eve::fix_pattern<T::size() / G>([](int, int) { return I; });
}

template<simd_value T, std::ptrdiff_t G, std::ptrdiff_t I>
static constexpr std::ptrdiff_t level(eve::as<T> tgt, eve::fixed<G> g, eve::index_t<I> i)
static consteval std::ptrdiff_t level(eve::as<T> tgt, eve::fixed<G> g, eve::index_t<I> i)
{
const std::size_t reg_size = sizeof(element_type_t<T>) * T::size();
const std::ptrdiff_t g_size = sizeof(element_type_t<T>) * G;
constexpr std::size_t reg_size = sizeof(element_type_t<T>) * T::size();
constexpr std::ptrdiff_t g_size = sizeof(element_type_t<T>) * G;

if constexpr( eve::has_aggregated_abi_v<T> )
{
Expand All @@ -80,47 +80,47 @@ struct broadcast_lane_t
else if constexpr( current_api >= vmx ) return 2;
else if constexpr( current_api >= sve )
{
if( !logical_value<T> ) return g_size > 8 ? 3 : 2;
if( G == 1 ) return 4;
if( g_size <= 8 ) return 6;
return 7;
if constexpr ( !logical_value<T> ) return g_size > 8 ? 3 : 2;
else if constexpr ( G == 1 ) return 4;
else if constexpr ( g_size <= 8 ) return 6;
else return 7;
}
else if constexpr( current_api >= neon )
{
if( current_api >= asimd ) return 2;
if( reg_size <= 8 ) return 2;
return 4;
if constexpr ( current_api >= asimd ) return 2;
else if constexpr ( reg_size <= 8 ) return 2;
else return 4;
}

// x86

if (current_api == avx512 && logical_value<T>)
if constexpr (current_api == avx512 && logical_value<T>)
{
if (G == 1) return 4;
return level(detail::mask_type(tgt), g, i) + 4;
if constexpr (G == 1) return 4;
else return level(detail::mask_type(tgt), g, i) + 4;
}

if (reg_size == 64)
else if constexpr (reg_size == 64)
{
if (g_size >= 16) return 2;
if (g_size >= 2) return 3;
return 4;
if constexpr (g_size >= 16) return 2;
else if constexpr (g_size >= 2) return 3;
else return 4;
}

if (reg_size == 32)
else if constexpr (reg_size == 32)
{
if (g_size >= 16) return 2;
if (current_api == avx) return 4;
if (g_size >= 8) return 2;
if (g_size >= 4) return 3;
if (g_size >= 2 && current_api == avx512) return 3;
return 4;
if constexpr (g_size >= 16) return 2;
if constexpr (current_api == avx) return 4;
if constexpr (g_size >= 8) return 2;
if constexpr (g_size >= 4) return 3;
if constexpr (g_size >= 2 && current_api == avx512) return 3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you see - now you push things to comile time switching instead of just evaluating. I don't know how this works under the hood, but it seems worse.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you expand on that a little bit ? I don't think I quite get it.

else return 4;
}
else
{
if constexpr ( g_size >= 4 ) return 2;
else if constexpr ( g_size == 2 && reg_size <= 8 ) return 2;
else if constexpr ( current_api >= ssse3 ) return 3;
else return 4;
}

if ( g_size >= 4 ) return 2;
if ( g_size == 2 && reg_size <= 8 ) return 2;
if ( current_api >= ssse3 ) return 3;
return 4;
}
};

Expand Down
Loading
Loading