Skip to content

Commit

Permalink
Move self_log* to the logical_* callables
Browse files Browse the repository at this point in the history
  • Loading branch information
SadiinsoSnowfall authored Jan 15, 2025
1 parent 77f3c9a commit 0e06d4d
Show file tree
Hide file tree
Showing 50 changed files with 1,140 additions and 885 deletions.
25 changes: 13 additions & 12 deletions include/eve/arch/cpu/logical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <eve/concept/vectorizable.hpp>
#include <eve/detail/abi.hpp>
#include <eve/traits/as_integer.hpp>
#include <eve/traits/common_value.hpp>

#include <bitset>
#include <cstring>
Expand Down Expand Up @@ -87,35 +88,35 @@ namespace eve
EVE_FORCEINLINE constexpr logical operator!() const noexcept { return {!value_}; }

template<arithmetic_scalar_value U>
friend EVE_FORCEINLINE logical operator&&(logical const& v, logical<U> const& w) noexcept
friend EVE_FORCEINLINE common_logical_t<T, U> operator&&(logical const& v, logical<U> const& w) noexcept
{
return logical{v.value() && w.value()};
return common_logical_t<T, U>{v.value() && w.value()};
}

friend EVE_FORCEINLINE logical operator&&(logical const& v, bool const& w) noexcept
{
return logical{v.value() && w};
return w ? v : logical{false};
}

friend EVE_FORCEINLINE logical operator&&(bool const& v, logical const& w) noexcept
{
return logical{v && w.value()};
return v ? w : logical{false};
}

template<arithmetic_scalar_value U>
friend EVE_FORCEINLINE logical operator||(logical const& v, logical<U> const& w) noexcept
friend EVE_FORCEINLINE common_logical_t<T, U> operator||(logical const& v, logical<U> const& w) noexcept
{
return logical{v.value() || w.value()};
return common_logical_t<T, U>{v.value() || w.value()};
}

friend EVE_FORCEINLINE logical operator||(logical const& v, bool const& w) noexcept
{
return logical{v.value() || w};
return w ? logical{true} : v;
}

friend EVE_FORCEINLINE logical operator||(bool const& v, logical const& w) noexcept
{
return logical{v || w.value()};
return v ? logical{true} : w;
}

//==============================================================================================
Expand All @@ -139,9 +140,9 @@ namespace eve
// Comparison operators
//==============================================================================================
template<scalar_value U>
friend EVE_FORCEINLINE logical operator==(logical const& v, logical<U> const& w) noexcept
friend EVE_FORCEINLINE common_logical_t<T, U> operator==(logical const& v, logical<U> const& w) noexcept
{
return v.value() == w.value();
return common_logical_t<T, U>{v.value() == w.value()};
}

friend EVE_FORCEINLINE logical operator==(logical const& v, bool w) noexcept
Expand All @@ -155,9 +156,9 @@ namespace eve
}

template<scalar_value U>
friend EVE_FORCEINLINE logical operator!=(logical const& v, logical<U> const& w) noexcept
friend EVE_FORCEINLINE common_logical_t<T, U> operator!=(logical const& v, logical<U> const& w) noexcept
{
return v.value() != w.value();
return common_logical_t<T, U>{v.value() != w.value()};
}

friend EVE_FORCEINLINE logical operator!=(logical const& v, bool w) noexcept
Expand Down
30 changes: 18 additions & 12 deletions include/eve/arch/cpu/logical_wide.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <eve/detail/function/make.hpp>
#include <eve/detail/function/slice.hpp>
#include <eve/detail/function/subscript.hpp>
#include <eve/module/core/regular/logical_and.hpp>
#include <eve/module/core/regular/logical_or.hpp>

#include <cstring>
#include <concepts>
Expand Down Expand Up @@ -274,42 +276,46 @@ namespace eve
//==============================================================================================
//! Perform a logical and operation between two eve::logical
template<typename U>
friend EVE_FORCEINLINE auto operator&&(logical const& v, logical<wide<U, Cardinal>> const& w) noexcept
friend EVE_FORCEINLINE common_logical_t<logical, logical<wide<U, Cardinal>>>
operator&&(logical const& a, logical<wide<U, Cardinal>> const& b) noexcept
{
return detail::self_logand(eve::current_api,v,w);
return logical_and(a, b);
}

//! Perform a logical and operation between a eve::logical and a scalar
template<scalar_value S>
friend EVE_FORCEINLINE auto operator&&(logical const& v, S w) noexcept
friend EVE_FORCEINLINE common_logical_t<logical, S> operator&&(logical const& w, S s) noexcept
{
return v && logical{w};
return logical_and(w, s);
}

//! Perform a logical and operation between a scalar and a eve::logical
template<scalar_value S>
friend EVE_FORCEINLINE auto operator&&(S v, logical const& w) noexcept
friend EVE_FORCEINLINE common_logical_t<S, logical> operator&&(S s, logical const& w) noexcept
{
return w && v;
return logical_and(s, w);
}

//! Perform a logical or operation between two eve::logical
template<typename U>
friend EVE_FORCEINLINE auto operator||(logical const& v, logical<wide<U, Cardinal>> const& w) noexcept
friend EVE_FORCEINLINE common_logical_t<logical, logical<wide<U, Cardinal>>>
operator||(logical const& a, logical<wide<U, Cardinal>> const& b) noexcept
{
return detail::self_logor(eve::current_api,v,w);
return logical_or(a, b);
}

//! Perform a logical or operation between a eve::logical and a scalar
friend EVE_FORCEINLINE auto operator||(logical const& v, scalar_value auto w) noexcept
template<scalar_value S>
friend EVE_FORCEINLINE common_logical_t<logical, S> operator||(logical const& w, S s) noexcept
{
return v || logical{w};
return logical_or(w, s);
}

//! Perform a logical or operation between a scalar and a eve::logical
friend EVE_FORCEINLINE auto operator||(scalar_value auto v, logical const& w) noexcept
template<scalar_value S>
friend EVE_FORCEINLINE common_logical_t<S, logical> operator||(S s, logical const& w) noexcept
{
return w || v;
return logical_or(s, w);
}

//! Computes the logical complement of its parameter
Expand Down
2 changes: 2 additions & 0 deletions include/eve/arch/cpu/wide.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <eve/module/core/regular/div.hpp>
#include <eve/module/core/regular/minus.hpp>
#include <eve/module/core/regular/logical_not.hpp>
#include <eve/module/core/regular/shl.hpp>
#include <eve/module/core/regular/shr.hpp>
#include <eve/memory/soa_ptr.hpp>
#include <eve/traits/product_type.hpp>

Expand Down
17 changes: 17 additions & 0 deletions include/eve/concept/scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,21 @@ concept arithmetic_scalar_value = plain_scalar_value<T> || product_scalar_value<
//================================================================================================
template<typename T>
concept scalar_value = arithmetic_scalar_value<T> || logical_scalar_value<T>;

//================================================================================================
//! @ingroup simd_concepts
//! @{
//! @concept relaxed_logical_scalar_value
//! @brief The concept `relaxed_logical_scalar_value<T>` is satisfied if and only if T is a
//! boolean value or satisfies the `eve::logical_scalar_value` concept.
//!
//! @groupheader{Examples}
//! - `eve::logical<char>`
//! - `bool`
//================================================================================================
template <typename T>
concept relaxed_logical_scalar_value = logical_scalar_value<T> || std::same_as<T, bool>;
//================================================================================================
//! @}
//================================================================================================
}
18 changes: 18 additions & 0 deletions include/eve/concept/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,22 @@ namespace eve
//================================================================================================
//! @}
//================================================================================================

//================================================================================================
//! @ingroup simd_concepts
//! @{
//! @concept relaxed_logical_value
//! @brief The concept `relaxed_logical_value<T>` is satisfied if and only if T is a
//! boolean value or satisfies the `eve::logical_value` concept.
//!
//! @groupheader{Examples}
//! - `eve::logical<char>`
//! - `eve::logical<eve::wide<char>>`
//! - `bool`
//================================================================================================
template <typename T>
concept relaxed_logical_value = logical_value<T> || std::same_as<T, bool>;
//================================================================================================
//! @}
//================================================================================================
}
9 changes: 5 additions & 4 deletions include/eve/deps/kumi/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,18 +707,19 @@ namespace kumi
requires(sizeof...(Ts) == sizeof...(Us) && _::piecewise_ordered<tuple, tuple<Us...>>)
{
auto res = get<0>(lhs) < get<0>(rhs);

auto const order = [&]<typename Index>(Index i)
{
auto y_less_x_prev = rhs[i] < lhs[i];
auto x_less_y = lhs[index_t<Index::value+1>{}] < rhs[index_t<Index::value+1>{}];
res = res || (x_less_y && !y_less_x_prev);
return (x_less_y && !y_less_x_prev);
};
[&]<std::size_t... I>(std::index_sequence<I...>)

return [&]<std::size_t... I>(std::index_sequence<I...>)
{
(order(index_t<I>{}),...);
return (res || ... || order(index_t<I>{}));
}
(std::make_index_sequence<sizeof...(Ts)-1>());
return res;
}
template<typename... Us>
KUMI_TRIVIAL friend constexpr auto operator<=(tuple const &lhs, tuple<Us...> const &rhs) noexcept
Expand Down
37 changes: 0 additions & 37 deletions include/eve/detail/function/simd/arm/sve/friends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,6 @@ EVE_FORCEINLINE auto
self_geq(wide<T, N> v, wide<T, N> w) noexcept -> as_logical_t<wide<T, N>>
requires sve_abi<abi_t<T, N>> { return svcmpge(sve_true<T>(), v, w); }


// ---------------------------------------------------------

template<typename T, typename U, typename N>
EVE_FORCEINLINE auto
self_logand(sve_ const&, logical<wide<T,N>> v, logical<wide<U,N>> w) noexcept -> logical<wide<T, N>>
requires(sve_abi<abi_t<T, N>> || sve_abi<abi_t<U, N>>)
{
if constexpr(!is_aggregated_v<abi_t<T, N>>)
{
return svmov_z(v, convert(w, as<logical<T>>{}));
}
else
{
auto[lv,hv] = v.slice();
auto[lw,hw] = w.slice();
return logical<wide<T, N>>{ lv && lw, hv && hw};
}
}

template<typename T, typename U, typename N>
EVE_FORCEINLINE auto
self_logor(sve_ const&, logical<wide<T,N>> v, logical<wide<U,N>> w) noexcept -> logical<wide<T, N>>
requires(sve_abi<abi_t<T, N>> || sve_abi<abi_t<U, N>>)
{
if constexpr(!is_aggregated_v<abi_t<T, N>>)
{
return svorr_z(sve_true<T>(), v, convert(w, as<logical<T>>{}));
}
else
{
auto[lv,hv] = v.slice();
auto[lw,hw] = w.slice();
return logical<wide<T, N>>{ lv || lw, hv || hw};
}
}

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
71 changes: 7 additions & 64 deletions include/eve/detail/function/simd/common/friends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <eve/detail/function/bit_cast.hpp>
#include <eve/detail/is_native.hpp>
#include <eve/traits/product_type.hpp>
#include <eve/as_element.hpp>
#include <eve/forward.hpp>

// Register tag here so we can use them in tagged_dispatch situation
Expand All @@ -27,64 +28,6 @@ namespace eve

namespace eve::detail
{
//================================================================================================
template<typename T, typename U, typename N>
EVE_FORCEINLINE auto self_logand(cpu_ const&, logical<wide<T,N>> v, logical<wide<U,N>> w) noexcept
{
using abi_t = typename logical<wide<T,N>>::abi_type;
using abi_u = typename logical<wide<U,N>>::abi_type;

// Both arguments are aggregated, we can safely slice
if constexpr( is_aggregated_v<abi_t> && is_aggregated_v<abi_u> )
{
auto [vl, vh] = v.slice();
auto [wl, wh] = w.slice();
return logical<wide<T,N>> { self_logand(eve::current_api,vl, wl)
, self_logand(eve::current_api,vh, wh)
};
}
else
{
if constexpr( !is_aggregated_v<abi_t> && !is_aggregated_v<abi_u> && (sizeof(T) == sizeof(U)) )
{
return bit_cast ( v.bits() & w.bits(), as(v) );
}
else
{
return self_logand(cpu_{}, v, convert(w, as<logical<T>>()));
}
}
}

//================================================================================================
template<typename T, typename U, typename N>
EVE_FORCEINLINE auto self_logor(cpu_ const&, logical<wide<T,N>> v, logical<wide<U,N>> w) noexcept
{
using abi_t = typename logical<wide<T,N>>::abi_type;
using abi_u = typename logical<wide<U,N>>::abi_type;

// Both arguments are aggregated, we can safely slice
if constexpr( is_aggregated_v<abi_t> && is_aggregated_v<abi_u> )
{
auto [vl, vh] = v.slice();
auto [wl, wh] = w.slice();
return logical<wide<T,N>> { self_logor(eve::current_api,vl, wl)
, self_logor(eve::current_api,vh, wh)
};
}
else
{
if constexpr( !is_aggregated_v<abi_t> && !is_aggregated_v<abi_u> && (sizeof(T) == sizeof(U)) )
{
return bit_cast ( v.bits() | w.bits(), as(v) );
}
else
{
return self_logor(cpu_{}, v, convert(w, as<logical<T>>()));
}
}
}

//================================================================================================
template<simd_value Wide>
EVE_FORCEINLINE auto self_eq(Wide const& v,Wide const& w) noexcept
Expand All @@ -96,7 +39,7 @@ namespace eve::detail
}
else
{
return v.storage() == w.storage();
return convert(v.storage() == w.storage(), as_element<as_logical_t<Wide>>());
}
}

Expand Down Expand Up @@ -134,7 +77,7 @@ namespace eve::detail
}
else
{
return v.storage() != w.storage();
return convert(v.storage() != w.storage(), as_element<as_logical_t<Wide>>());
}
}

Expand All @@ -161,7 +104,7 @@ namespace eve::detail
{
if constexpr( product_type<Wide> )
{
return kumi::to_tuple(v) < kumi::to_tuple(w);
return convert(kumi::to_tuple(v) < kumi::to_tuple(w), as_element<as_logical_t<Wide>>());
}
else
{
Expand All @@ -175,7 +118,7 @@ namespace eve::detail
{
if constexpr( product_type<Wide> )
{
return kumi::to_tuple(v) <= kumi::to_tuple(w);
return convert(kumi::to_tuple(v) <= kumi::to_tuple(w), as_element<as_logical_t<Wide>>());
}
else
{
Expand All @@ -189,7 +132,7 @@ namespace eve::detail
{
if constexpr( product_type<Wide> )
{
return kumi::to_tuple(v) > kumi::to_tuple(w);
return convert(kumi::to_tuple(v) > kumi::to_tuple(w), as_element<as_logical_t<Wide>>());
}
else
{
Expand All @@ -203,7 +146,7 @@ namespace eve::detail
{
if constexpr( product_type<Wide> )
{
return kumi::to_tuple(v) >= kumi::to_tuple(w);
return convert(kumi::to_tuple(v) >= kumi::to_tuple(w), as_element<as_logical_t<Wide>>());
}
else
{
Expand Down
Loading

0 comments on commit 0e06d4d

Please sign in to comment.