Skip to content

Commit

Permalink
Callable for extract/insert
Browse files Browse the repository at this point in the history
  • Loading branch information
SadiinsoSnowfall authored Aug 28, 2024
1 parent bb381fe commit 5c21a5b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 27 deletions.
31 changes: 18 additions & 13 deletions include/eve/detail/function/simd/arm/sve/subscript.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,32 @@
#pragma once

#include <eve/detail/abi.hpp>
#include <eve/detail/alias.hpp>
#include <eve/detail/has_abi.hpp>
#include <eve/traits/element_type.hpp>
#include <eve/as.hpp>
#include <eve/arch/arm/sve/sve_true.hpp>

namespace eve::detail
{
template<typename T, typename N>
EVE_FORCEINLINE T
extract(wide<T, N> const& v, std::size_t i) noexcept requires sve_abi<abi_t<T, N>>

template<callable_options O, typename T, typename N>
EVE_FORCEINLINE T extract_(EVE_REQUIRES(sve_), O const&, wide<T, N> v, std::size_t i) noexcept
requires sve_abi<abi_t<T, N>>
{
return v.storage()[i];
}

template<typename T, typename N>
EVE_FORCEINLINE T
insert(wide<T, N>& v, std::size_t i, T x) noexcept requires sve_abi<abi_t<T, N>>
template<callable_options O, typename T, typename N>
EVE_FORCEINLINE void insert_(EVE_REQUIRES(sve_), O const&, wide<T, N>& v, std::size_t i, T x) noexcept
requires sve_abi<abi_t<T, N>>
{
return v.storage()[i] = x;
v.storage()[i] = x;
}

template<typename T, typename N>
EVE_FORCEINLINE logical<T>
extract(logical<wide<T, N>> const& v, std::size_t i) noexcept requires sve_abi<abi_t<T, N>>
template<callable_options O, typename T, typename N>
EVE_FORCEINLINE logical<T> extract_(EVE_REQUIRES(sve_), O const&, logical<wide<T, N>> v, std::size_t i) noexcept
requires sve_abi<abi_t<T, N>>
{
auto bits = [&]() -> typename logical<wide<T, N>>::bits_type
{
Expand All @@ -43,9 +48,9 @@ extract(logical<wide<T, N>> const& v, std::size_t i) noexcept requires sve_abi<a
return logical<T> {bits.get(i)};
}

template<typename T, typename N>
EVE_FORCEINLINE void
insert(logical<wide<T, N>>& v, std::size_t i, auto x) noexcept requires sve_abi<abi_t<T, N>>
template<callable_options O, typename T, typename N>
EVE_FORCEINLINE void insert_(EVE_REQUIRES(sve_), O const&, logical<wide<T, N>>& v, std::size_t i, auto x) noexcept
requires sve_abi<abi_t<T, N>>
{
using bits_type = typename logical<wide<T, N>>::bits_type;
using e_t = element_type_t<bits_type>;
Expand Down
8 changes: 4 additions & 4 deletions include/eve/detail/function/simd/common/subscript.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace eve::detail
//================================================================================================
// Extract value
//================================================================================================
template<typename Wide>
EVE_FORCEINLINE auto extract(Wide const& p, std::size_t i) noexcept
template<callable_options O, typename Wide>
EVE_FORCEINLINE auto extract_(EVE_REQUIRES(cpu_), O const&, Wide p, std::size_t i) noexcept
{
using abi_t = typename Wide::abi_type;

Expand Down Expand Up @@ -52,8 +52,8 @@ namespace eve::detail
//================================================================================================
// Insert value
//================================================================================================
template<typename Wide, typename Value>
EVE_FORCEINLINE void insert(Wide& p, std::size_t i, Value v) noexcept
template<callable_options O, typename Wide, typename Value>
EVE_FORCEINLINE void insert_(EVE_REQUIRES(cpu_), O const&, Wide& p, std::size_t i, Value v) noexcept
{
using type = element_type_t<Wide>;

Expand Down
18 changes: 9 additions & 9 deletions include/eve/detail/function/simd/x86/subscript.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

namespace eve::detail
{
//================================================================================================
//================================================================================================
// Extract value
//================================================================================================
template<typename T, typename N>
EVE_FORCEINLINE logical<T> extract(logical<wide<T,N>> const& p, std::size_t i) noexcept
requires x86_abi<abi_t<T, N>>
template<callable_options O, typename T, typename N>
EVE_FORCEINLINE logical<T> extract_(EVE_REQUIRES(sse2_), O const&, logical<wide<T,N>> p, std::size_t i) noexcept
requires x86_abi<abi_t<T, N>>
{
if constexpr( !abi_t<T, N>::is_wide_logical )
{
Expand All @@ -32,22 +32,22 @@ namespace eve::detail
static_assert(sizeof(bits_type) == sizeof(logical<T>));

auto s = p.storage();
std::memcpy(reinterpret_cast<bits_type*>(&data[0]),&s,sizeof(data));
std::memcpy(reinterpret_cast<bits_type*>(&data[0]), &s, sizeof(data));
return data[i];
}
}

//================================================================================================
// Insert value
//================================================================================================
template<typename T, typename N>
EVE_FORCEINLINE void insert(logical<wide<T,N>>& p, std::size_t i, auto v) noexcept
requires x86_abi<abi_t<T, N>>
template<callable_options O, typename T, typename N>
EVE_FORCEINLINE void insert_(EVE_REQUIRES(sse2_), O const&, logical<wide<T,N>>& p, std::size_t i, auto v) noexcept
requires x86_abi<abi_t<T, N>>
{
if constexpr( !abi_t<T, N>::is_wide_logical )
{
using i_t = typename logical<wide<T,N>>::storage_type::type;
p.storage().value = (p.storage().value & ~(i_t(1)<<i)) | ((v ? i_t(1) : 0)<<i);
p.storage().value = (p.storage().value & ~(i_t(1) << i)) | ((v ? i_t(1) : 0) << i);
}
else
{
Expand Down
33 changes: 32 additions & 1 deletion include/eve/detail/function/subscript.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,44 @@
#pragma once

#include <eve/arch.hpp>

namespace eve::detail
{
template<typename Options>
struct insert_t : callable<insert_t, Options>
{
template<typename Wide, typename Val>
EVE_FORCEINLINE constexpr void operator()(Wide& w, std::size_t idx, Val v) const noexcept
{
return EVE_DISPATCH_CALL(w, idx, v);
}

EVE_CALLABLE_OBJECT(insert_t, insert_);
};

inline constexpr auto insert = functor<insert_t>;

template<typename Options>
struct extract_t : callable<extract_t, Options>
{
template<typename Wide>
EVE_FORCEINLINE constexpr element_type_t<Wide> operator()(Wide w, std::size_t idx) const noexcept
{
return EVE_DISPATCH_CALL(w, idx);
}

EVE_CALLABLE_OBJECT(extract_t, extract_);
};

inline constexpr auto extract = functor<extract_t>;
}

#include <eve/detail/function/simd/common/subscript.hpp>

#if defined(EVE_INCLUDE_X86_HEADER)
# include <eve/detail/function/simd/x86/subscript.hpp>
#endif


#if defined(EVE_INCLUDE_SVE_HEADER)
# include <eve/detail/function/simd/arm/sve/subscript.hpp>
#endif

0 comments on commit 5c21a5b

Please sign in to comment.