Skip to content

Commit

Permalink
Move self_bitor into the callable bit_or (#1956)
Browse files Browse the repository at this point in the history
  • Loading branch information
SadiinsoSnowfall authored Sep 12, 2024
1 parent 075bfc4 commit ff3d0c0
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 283 deletions.
18 changes: 8 additions & 10 deletions include/eve/arch/cpu/wide.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,43 +452,41 @@ namespace eve
requires(!kumi::product_type<Type> && supports_bitwise_call<wide, V>)
#endif
{
return detail::self_bitor(w, o);
w = bit_or(w, o);
return w;
}

//! @brief Performs a bitwise or between all lanes of two wide instances.
//! Do not participate to overload resolution if both wide doesn't has the same `sizeof`
template<scalar_value U, typename M>
friend EVE_FORCEINLINE wide operator|(wide const& v, wide<U, M> const& w) noexcept
friend EVE_FORCEINLINE wide operator|(wide const& a, wide<U, M> const& b) noexcept
#if !defined(EVE_DOXYGEN_INVOKED)
requires(!kumi::product_type<Type> && supports_bitwise_call<wide, wide<U, M>>)
#endif
{
wide that = v;
return that |= w;
return bit_or(a, b);
}

//! @brief Performs a bitwise or between all lanes of a scalar and a eve::wide
//! Do not participate to overload resolution if `sizeof(Type) != sizeof(S)`
template<scalar_value S>
friend EVE_FORCEINLINE wide operator|(wide const& v, S w) noexcept
friend EVE_FORCEINLINE wide operator|(wide const& w, S s) noexcept
#if !defined(EVE_DOXYGEN_INVOKED)
requires(!kumi::product_type<Type> && supports_bitwise_call<wide, S>)
#endif
{
auto that = v;
return that |= bit_cast(w, as<Type> {});
return bit_or(w, bit_cast(s, as<Type>{}));
}

//! @brief Performs a bitwise or between all lanes of a scalar and a eve::wide
//! Do not participate to overload resolution if `sizeof(Type) != sizeof(S)`
template<scalar_value S>
friend EVE_FORCEINLINE wide<S, Cardinal> operator|(S v, wide const& w) noexcept
friend EVE_FORCEINLINE wide<S, Cardinal> operator|(S s, wide const& w) noexcept
#if !defined(EVE_DOXYGEN_INVOKED)
requires(!kumi::product_type<Type> && supports_bitwise_call<S, wide>)
#endif
{
auto u = bit_cast(w, as<typename wide::template rebind<S, Cardinal>>());
return u |= v;
return bit_or(bit_cast(w, as<wide<S, Cardinal>>{}), s);
}

//! @brief Performs a bitwise xor on all the wide lanes and assign the result to the current one
Expand Down
1 change: 0 additions & 1 deletion include/eve/detail/function/compounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <eve/arch.hpp>
#include <eve/detail/function/simd/common/bit_compounds.hpp>
#include <eve/detail/function/operators.hpp>

#if defined(EVE_INCLUDE_X86_HEADER)
# include <eve/detail/function/simd/x86/bit_compounds.hpp>
Expand Down
34 changes: 0 additions & 34 deletions include/eve/detail/function/operators.hpp

This file was deleted.

71 changes: 0 additions & 71 deletions include/eve/detail/function/simd/arm/neon/bit_compounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,75 +133,4 @@ namespace eve::detail

return v;
}

//================================================================================================
// |=
//================================================================================================
template<scalar_value T, value U, typename N>
EVE_FORCEINLINE bit_value_t<wide<T, N>, U>& self_bitor(wide<T, N> &self, U const &other) noexcept
requires((sizeof(wide<T, N>) == sizeof(U)) || (sizeof(T) == sizeof(U))) && arm_abi<abi_t<T, N>>
{
using type = wide<T, N>;

if constexpr( simd_value<U> && sizeof(self) == sizeof(other) )
{
auto bit_other = eve::bit_cast(other, as<type> {});
constexpr auto c = categorize<type>();

if constexpr( c == category::int64x1 ) self = vorr_s64 (self, bit_other);
else if constexpr( c == category::int32x2 ) self = vorr_s32 (self, bit_other);
else if constexpr( c == category::int16x4 ) self = vorr_s16 (self, bit_other);
else if constexpr( c == category::int8x8 ) self = vorr_s8 (self, bit_other);
else if constexpr( c == category::uint64x1 ) self = vorr_u64 (self, bit_other);
else if constexpr( c == category::uint32x2 ) self = vorr_u32 (self, bit_other);
else if constexpr( c == category::uint16x4 ) self = vorr_u16 (self, bit_other);
else if constexpr( c == category::uint8x8 ) self = vorr_u8 (self, bit_other);
else if constexpr( c == category::int64x2 ) self = vorrq_s64(self, bit_other);
else if constexpr( c == category::int32x4 ) self = vorrq_s32(self, bit_other);
else if constexpr( c == category::int16x8 ) self = vorrq_s16(self, bit_other);
else if constexpr( c == category::int8x16 ) self = vorrq_s8 (self, bit_other);
else if constexpr( c == category::uint64x2 ) self = vorrq_u64(self, bit_other);
else if constexpr( c == category::uint32x4 ) self = vorrq_u32(self, bit_other);
else if constexpr( c == category::uint16x8 ) self = vorrq_u16(self, bit_other);
else if constexpr( c == category::uint8x16 ) self = vorrq_u8 (self, bit_other);
else if constexpr( c == category::float32x2)
{
self = vreinterpret_f32_u32 ( vorr_u32( vreinterpret_u32_f32(self)
, vreinterpret_u32_f32(bit_other)
)
);
}
else if constexpr( c == category::float32x4)
{
self = vreinterpretq_f32_u32( vorrq_u32 ( vreinterpretq_u32_f32(self)
, vreinterpretq_u32_f32(bit_other)
)
);
}
else if constexpr( current_api >= asimd)
{
if constexpr( c == category::float64x1)
{
self = vreinterpret_f64_u64 ( vorr_u64( vreinterpret_u64_f64(self)
, vreinterpret_u64_f64(bit_other)
)
);
}
else if constexpr( c == category::float64x2)
{
self = vreinterpretq_f64_u64( vorrq_u64 ( vreinterpretq_u64_f64(self)
, vreinterpretq_u64_f64(bit_other)
)
);
}
}
}
else
{
auto bit_other = eve::bit_cast(other, as<T> {});
self = self_bitor(self, type {bit_other});
}

return self;
}
}
23 changes: 0 additions & 23 deletions include/eve/detail/function/simd/arm/sve/bit_compounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,4 @@ requires sve_abi<abi_t<T, N>>
return self;
}
}

template<scalar_value T, value U, typename N>
EVE_FORCEINLINE bit_value_t<wide<T, N>, U>&
self_bitor(wide<T, N>& self, U const& other) noexcept
requires((sizeof(wide<T, N>) == sizeof(U)) || (sizeof(T) == sizeof(U))) && sve_abi<abi_t<T, N>>
{
using type = wide<T, N>;

if constexpr( simd_value<U> )
{
using i_t = typename type::template rebind <as_integer_t<T, signed>,N>;
constexpr auto tgt = as<i_t>();
self = bit_cast ( i_t(svorr_x(sve_true<T>(), bit_cast(self,tgt), bit_cast(other,tgt)))
, as(self)
);
}
else
{
self = self_bitor(self, type{eve::bit_cast(other, as<T>{})});
}

return self;
}
}
36 changes: 0 additions & 36 deletions include/eve/detail/function/simd/common/bit_compounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,4 @@ namespace eve::detail
{
return self_shr(v,V);
}

//================================================================================================
// |=
//================================================================================================
template<scalar_value T, value U, typename N>
EVE_FORCEINLINE bit_value_t<wide<T, N>, U>&
self_bitor(wide<T, N> &self, U const &other) requires((sizeof(wide<T, N>) == sizeof(U))
|| (sizeof(T) == sizeof(U))) && non_native_abi<abi_t<T, N>>
{
using type = wide<T, N>;

if constexpr( scalar_value<U> )
{
auto bit_other = bit_cast(other, as<T> {});
return self_bitor(self, type {bit_other});
}
else
{
if constexpr( is_emulated_v<abi_t<T, N>> )
{
auto& data = self.storage();
apply<N::value>([&](auto... I)
{
using i_t = as_integer_t<T>;
using t_t = as<i_t>;
((data[I] = bit_cast( i_t(bit_cast(self.get(I),t_t{}) | bit_cast(other.get(I),t_t{})), as<T>{})), ...);
});
return self;
}
else if constexpr( is_aggregated_v<abi_t<T, N>> )
{
self.storage().for_each( [&](auto& s, auto const& o) { s |= o; }, other );
return self;
}
}
}
}
22 changes: 0 additions & 22 deletions include/eve/detail/function/simd/ppc/bit_compounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,4 @@ namespace eve::detail
v >>= i_t(s);
return v;
}

//================================================================================================
// |=
//================================================================================================
template<scalar_value T, value U, typename N>
EVE_FORCEINLINE bit_value_t<wide<T, N>, U>& self_bitor( wide<T,N>& self, U const& other )
requires( (sizeof(wide<T,N>) == sizeof(U)) || (sizeof(T) == sizeof(U)) ) && ppc_abi<abi_t<T, N>>
{
using type = wide<T,N>;

if constexpr( simd_value<U> && sizeof(self) == sizeof(other) )
{
self = vec_or(self.storage(), (typename type::storage_type)(other.storage()) );
}
else
{
auto bit_other = bit_cast(other , as<T>{});
self = vec_or(self.storage(), type{bit_other}.storage());
}

return self;
}
}
42 changes: 0 additions & 42 deletions include/eve/detail/function/simd/x86/bit_compounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,46 +199,4 @@ namespace eve::detail

return v;
}

//================================================================================================
// |=
//================================================================================================
template<scalar_value T, value U, typename N>
EVE_FORCEINLINE bit_value_t<wide<T, N>, U>& self_bitor(wide<T, N> &self, U const &other) noexcept
requires((sizeof(wide<T, N>) == sizeof(U)) || (sizeof(T) == sizeof(U))) && x86_abi<abi_t<T, N>>
{
using type = wide<T, N>;

if constexpr( scalar_value<U> )
{
auto bit_other = bit_cast(other, as<T> {});
return self_bitor(self, type {bit_other});
}
else if constexpr( simd_value<U> && sizeof(self) == sizeof(other) )
{
auto bits = bit_cast(other, as<type> {});
constexpr auto c = categorize<type>();
constexpr bool i = match(c, category::integer_);

if constexpr ( c == category::float64x8 ) self = _mm512_or_pd(self, bits);
else if constexpr ( c == category::float64x4 ) self = _mm256_or_pd(self, bits);
else if constexpr ( c == category::float64x2 ) self = _mm_or_pd (self, bits);
else if constexpr ( c == category::float32x16 ) self = _mm512_or_ps(self, bits);
else if constexpr ( c == category::float32x8 ) self = _mm256_or_ps(self, bits);
else if constexpr ( c == category::float32x4 ) self = _mm_or_ps (self, bits);
else if constexpr ( i && std::same_as<abi_t<T, N>,x86_512_> ) self = _mm512_or_si512(self, bits);
else if constexpr ( i && std::same_as<abi_t<T, N>,x86_256_> )
{
if constexpr ( current_api >= avx2 ) self = _mm256_or_si256(self, bits);
else self = _mm256_castps_si256
( _mm256_or_ps ( _mm256_castsi256_ps(self)
, _mm256_castsi256_ps(bits)
)
);
}
else if constexpr ( i && std::same_as<abi_t<T, N>,x86_128_> ) self = _mm_or_si128(self, bits);

return self;
}
}
}
35 changes: 22 additions & 13 deletions include/eve/module/core/regular/bit_or.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,24 @@ namespace eve
template<typename Options>
struct bit_or_t : strict_tuple_callable<bit_or_t, Options>
{
template<eve::value T0, value T1>
requires(eve::same_lanes_or_scalar<T0, T1>)
EVE_FORCEINLINE constexpr bit_value_t<T0, T1>
operator()(T0 t0, T1 t1) const noexcept
template<value T0, value T1>
EVE_FORCEINLINE constexpr bit_value_t<T0, T1> operator()(T0 t0, T1 t1) const noexcept
{
return EVE_DISPATCH_CALL(t0, t1);
}
template<eve::value T0, value T1, value... Ts>
requires(eve::same_lanes_or_scalar<T0, T1, Ts...>)
EVE_FORCEINLINE constexpr bit_value_t<T0, T1, Ts...>
operator()(T0 t0, T1 t1, Ts...ts) const noexcept

template<value T0, value T1, value... Ts>
EVE_FORCEINLINE constexpr bit_value_t<T0, T1, Ts...> operator()(T0 t0, T1 t1, Ts...ts) const noexcept
{
return EVE_DISPATCH_CALL(t0, t1, ts...);
}

template<kumi::non_empty_product_type Tup>
requires(eve::same_lanes_or_scalar_tuple<Tup>)
EVE_FORCEINLINE constexpr
kumi::apply_traits_t<eve::bit_value,Tup>
operator()(Tup const& t) const noexcept requires(kumi::size_v<Tup> >= 2)
{ return EVE_DISPATCH_CALL(t); }
EVE_FORCEINLINE constexpr kumi::apply_traits_t<bit_value, Tup> operator()(Tup const& t) const noexcept
requires (kumi::size_v<Tup> >= 2)
{
return EVE_DISPATCH_CALL(t);
}

EVE_CALLABLE_OBJECT(bit_or_t, bit_or_);
};
Expand Down Expand Up @@ -95,6 +92,18 @@ namespace eve

#include <eve/module/core/regular/impl/bit_or.hpp>

#if defined(EVE_INCLUDE_POWERPC_HEADER)
# include <eve/module/core/regular/impl/simd/ppc/bit_or.hpp>
#endif

#if defined(EVE_INCLUDE_X86_HEADER)
# include <eve/module/core/regular/impl/simd/x86/bit_or.hpp>
#endif

#if defined(EVE_INCLUDE_ARM_HEADER)
# include <eve/module/core/regular/impl/simd/arm/neon/bit_or.hpp>
#endif

#if defined(EVE_INCLUDE_SVE_HEADER)
# include <eve/module/core/regular/impl/simd/arm/sve/bit_or.hpp>
#endif
1 change: 0 additions & 1 deletion include/eve/module/core/regular/impl/bit_and.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#pragma once

#include <eve/concept/value.hpp>
#include <eve/detail/function/operators.hpp>

namespace eve::detail
{
Expand Down
Loading

0 comments on commit ff3d0c0

Please sign in to comment.