Skip to content

Commit

Permalink
FIx #559 - Implement movemask for PPC to enable cheap top_bits operat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
jfalcou authored Jan 10, 2024
1 parent cc47120 commit 5d8a8f6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/eve/arch/cpu/top_bits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace detail
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;

if ( arm_abi<abi_type> )
{
Expand Down
4 changes: 4 additions & 0 deletions include/eve/detail/function/movemask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# include <eve/detail/function/simd/x86/movemask.hpp>
#endif

#if defined(EVE_INCLUDE_POWERPC_HEADER)
# include <eve/detail/function/simd/ppc/movemask.hpp>
#endif

#if defined(EVE_INCLUDE_ARM_HEADER)
# include <eve/detail/function/simd/arm/neon/movemask.hpp>
#endif
33 changes: 33 additions & 0 deletions include/eve/detail/function/simd/ppc/movemask.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//==================================================================================================
/*
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once

#include <eve/arch/logical.hpp>
#include <eve/detail/function/bit_cast.hpp>
#include <utility>

namespace eve::detail
{
// Adapted from this completely unsuspecting thread:
// https://stackoverflow.com/questions/33938584/on-powerpc-is-there-any-equivalent-of-intels-movemask-intrinsics
template<arithmetic_scalar_value T, typename N>
EVE_FORCEINLINE
std::pair<std::uint64_t,fixed<1>> movemask(logical<wide<T, N>> const &v) noexcept requires ppc_abi<abi_t<T, N>>
{
using vu8 = typename wide<T,N>::template rebind<std::uint8_t>;
vu8 mask([](auto i, auto c)
{
constexpr auto spacing = sizeof(T)*8;
// Any value above 128 means 0 so this always work without checking if i is above or below N
return (c-1-i) * spacing;
});

auto result = vec_vbpermq(bit_cast(v.bits(),as(mask)).storage(), mask.storage());
return {result[0], eve::lane<1>};
}
}
1 change: 1 addition & 0 deletions test/unit/arch/top_bits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ TTS_CASE_TPL( "Check top bits raw type", eve::test::simd::all_types)
using ABI = typename logical::abi_type;

if constexpr (eve::has_aggregated_abi_v<logical>) TTS_EXPECT(expect_array(tb_storage{}));
else if constexpr (std::same_as<ABI, eve::ppc_>) TTS_TYPE_IS(tb_storage, std::uint64_t);
else if constexpr (eve::current_api >= eve::sve ) TTS_TYPE_IS(tb_storage, eve::logical<eve::wide<v_t>>);
else if constexpr (eve::current_api >= eve::avx512 )
{
Expand Down

0 comments on commit 5d8a8f6

Please sign in to comment.