Skip to content

Commit

Permalink
Converts self_lognot to logical_not callable
Browse files Browse the repository at this point in the history
  • Loading branch information
SadiinsoSnowfall authored Jan 9, 2025
1 parent fb093a0 commit a27bc48
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 62 deletions.
2 changes: 1 addition & 1 deletion include/eve/arch/cpu/logical_wide.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ namespace eve
//! Computes the logical complement of its parameter
friend EVE_FORCEINLINE auto operator!(logical const& v) noexcept
{
return detail::self_lognot(v);
return logical_not(v);
}

//==============================================================================================
Expand Down
3 changes: 2 additions & 1 deletion include/eve/arch/cpu/wide.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <eve/module/core/regular/mul.hpp>
#include <eve/module/core/regular/div.hpp>
#include <eve/module/core/regular/minus.hpp>
#include <eve/module/core/regular/logical_not.hpp>
#include <eve/memory/soa_ptr.hpp>
#include <eve/traits/product_type.hpp>

Expand Down Expand Up @@ -979,7 +980,7 @@ namespace eve
requires(!kumi::product_type<Type>)
#endif
{
return detail::self_lognot(v);
return logical_not(v);
}

//! Inserts a eve::wide into a output stream
Expand Down
5 changes: 0 additions & 5 deletions include/eve/detail/function/simd/arm/sve/friends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ requires(sve_abi<abi_t<T, N>> || sve_abi<abi_t<U, N>>)
}
}

template<arithmetic_scalar_value T, typename N>
EVE_FORCEINLINE auto
self_lognot(logical<wide<T, N>> v) noexcept -> logical<wide<T, N>>
requires sve_abi<abi_t<T, N>> { return svnot_z(sve_true<T>(), v); }

template<arithmetic_scalar_value T, typename N>
EVE_FORCEINLINE auto
self_neq(logical<wide<T, N>> v, logical<wide<T, N>> w) noexcept -> logical<wide<T, N>>
Expand Down
15 changes: 0 additions & 15 deletions include/eve/detail/function/simd/common/friends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,6 @@ namespace eve::detail
}
}

//================================================================================================
template<simd_value Wide>
EVE_FORCEINLINE auto self_lognot(Wide const& v) noexcept
{
if constexpr(has_native_abi_v<Wide>)
{
if constexpr( is_logical_v<Wide> ) return bit_cast(~v.bits(), as<Wide>{});
else return !to_logical(v);
}
else
{
return apply_over([]<typename E>(E const& e){ return as_logical_t<E>(!e); }, v);
}
}

//================================================================================================
template<simd_value Wide>
EVE_FORCEINLINE auto self_eq(Wide const& v,Wide const& w) noexcept
Expand Down
9 changes: 0 additions & 9 deletions include/eve/detail/function/simd/riscv/friends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,4 @@ requires(rvv_abi<abi_t<T, N>> || rvv_abi<abi_t<U, N>>)
return logical<wide<T, N>> {lv || lw, hv || hw};
}
}

template<arithmetic_scalar_value T, typename N>
EVE_FORCEINLINE auto
self_lognot(logical<wide<T, N>> v) noexcept -> logical<wide<T, N>>
requires rvv_abi<abi_t<T, N>>
{
return __riscv_vmnot(v, N::value);
}

}
13 changes: 0 additions & 13 deletions include/eve/detail/function/simd/x86/friends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,6 @@ requires(x86_abi<abi_t<T, N>> || x86_abi<abi_t<U, N>>)
}
}

//================================================================================================
template<arithmetic_scalar_value T, typename N>
EVE_FORCEINLINE auto
self_lognot(logical<wide<T, N>> v) noexcept requires x86_abi<abi_t<T, N>>
{
if constexpr( !abi_t<T, N>::is_wide_logical )
{
using l_t = logical<wide<T, N>>;
return l_t {~v.storage()};
}
else { return bit_cast(~v.bits(), as(v)); }
}

//================================================================================================
template<arithmetic_scalar_value T, typename N>
EVE_FORCEINLINE as_logical_t<wide<T, N>>
Expand Down
24 changes: 24 additions & 0 deletions include/eve/module/core/regular/impl/simd/arm/sve/logical_not.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//==================================================================================================
/*
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once

#include <eve/arch/arm/sve/sve_true.hpp>
#include <eve/concept/value.hpp>
#include <eve/detail/abi.hpp>
#include <eve/detail/category.hpp>
#include <eve/forward.hpp>

namespace eve::detail
{
template<callable_options O, arithmetic_scalar_value T, typename N>
EVE_FORCEINLINE logical<wide<T, N>> logical_not_(EVE_REQUIRES(sve_), O const&, logical<wide<T, N>> v) noexcept
requires sve_abi<abi_t<T, N>>
{
return svnot_z(sve_true<T>(), v);
}
}
22 changes: 22 additions & 0 deletions include/eve/module/core/regular/impl/simd/riscv/logical_not.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//==================================================================================================
/*
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once

#include <eve/concept/value.hpp>
#include <eve/detail/category.hpp>
#include <eve/detail/implementation.hpp>

namespace eve::detail
{
template<callable_options O, arithmetic_scalar_value T, typename N>
EVE_FORCEINLINE logical<wide<T, N>> logical_not_(EVE_REQUIRES(rvv_), O const&, logical<wide<T, N>> v) noexcept
requires rvv_abi<abi_t<T, N>>
{
return __riscv_vmnot(v, N::value);
}
}
24 changes: 24 additions & 0 deletions include/eve/module/core/regular/impl/simd/x86/logical_not.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//==================================================================================================
/*
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once

#include <eve/concept/compatible.hpp>
#include <eve/concept/value.hpp>
#include <eve/detail/implementation.hpp>
#include <eve/module/core/regular/convert.hpp>

namespace eve::detail
{
template<arithmetic_scalar_value T, typename N, callable_options O>
EVE_FORCEINLINE logical<wide<T, N>> logical_not_(EVE_REQUIRES(avx512_), O const&, logical<wide<T, N>> v) noexcept
requires (x86_abi<abi_t<T, N>>)
{
using l_t = logical<wide<T, N>>;
return l_t {~v.storage()};
}
}
46 changes: 28 additions & 18 deletions include/eve/module/core/regular/logical_not.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@
#include <eve/concept/value.hpp>
#include <eve/detail/implementation.hpp>
#include <eve/detail/overload.hpp>
#include <eve/module/core/regular/is_eqz.hpp>
#include <eve/traits/as_logical.hpp>

#include <eve/module/core/regular/bit_cast.hpp>

namespace eve
{
template<typename Options>
struct logical_not_t : elementwise_callable<logical_not_t, Options>
struct logical_not_t : strict_elementwise_callable<logical_not_t, Options>
{
template<logical_value T>
constexpr EVE_FORCEINLINE auto operator()(T a) const noexcept -> as_logical_t<decltype(!a)>
{ return EVE_DISPATCH_CALL(a); }
template<value T>
constexpr EVE_FORCEINLINE as_logical_t<T> operator()(T a) const noexcept
{
return EVE_DISPATCH_CALL(a);
}

constexpr EVE_FORCEINLINE bool operator()(bool a) const noexcept
{ return EVE_DISPATCH_CALL(a); }
constexpr EVE_FORCEINLINE bool operator()(bool a) const noexcept
{
return !a;
}

EVE_CALLABLE_OBJECT(logical_not_t, logical_not_);
};
Expand Down Expand Up @@ -76,17 +79,24 @@ namespace eve
namespace detail
{
template<value T, callable_options O>
EVE_FORCEINLINE constexpr auto
logical_not_(EVE_REQUIRES(cpu_), O const &, T const& a) noexcept
EVE_FORCEINLINE constexpr auto logical_not_(EVE_REQUIRES(cpu_), O const&, T const& a) noexcept
requires has_native_abi_v<T>
{
return as_logical_t<T>(!a);
}

template<callable_options O>
EVE_FORCEINLINE constexpr auto
logical_not_(EVE_REQUIRES(cpu_), O const &, bool a) noexcept
{
return !a;
if constexpr (scalar_value<T>) return as_logical_t<T>(!a);
else if constexpr (logical_value<T>) return bit_cast(~(a.bits()), as{a});
else return !to_logical(a);
}
}
}

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

#if defined(EVE_INCLUDE_RISCV_HEADER)
# include <eve/module/core/regular/impl/simd/riscv/logical_not.hpp>
#endif

#if defined(EVE_INCLUDE_ARM_SVE_HEADER)
# include <eve/module/core/regular/impl/simd/arm/sve/logical_not.hpp>
#endif

0 comments on commit a27bc48

Please sign in to comment.