Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move self_logand to the logical_and callable #1959

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
22ff6e8
take 1
SadiinsoSnowfall Sep 11, 2024
c165f5a
added backends
SadiinsoSnowfall Sep 11, 2024
011a5c3
typo
SadiinsoSnowfall Sep 11, 2024
54b73bd
allow booleans in common_logical
SadiinsoSnowfall Sep 19, 2024
40c67a6
fixed common_logical impl
SadiinsoSnowfall Sep 19, 2024
f2a1dc8
fix
SadiinsoSnowfall Sep 19, 2024
131b561
fixed missing case for bool x bool
SadiinsoSnowfall Sep 20, 2024
29abcbd
riscv fix
SadiinsoSnowfall Sep 20, 2024
7ea3c77
avx512 fix
SadiinsoSnowfall Sep 20, 2024
07fd843
fix resolution problem
SadiinsoSnowfall Sep 24, 2024
b309af1
fix
SadiinsoSnowfall Sep 26, 2024
3594603
made common_logical more commutative
SadiinsoSnowfall Sep 26, 2024
959832b
fix NO_SIMD
SadiinsoSnowfall Sep 30, 2024
374bbc0
fix
SadiinsoSnowfall Sep 30, 2024
c7bdc8a
changed common_logical behaviour
SadiinsoSnowfall Nov 29, 2024
6090b71
fix
SadiinsoSnowfall Nov 29, 2024
78b12f2
revert new behaviour
SadiinsoSnowfall Dec 2, 2024
758da64
added a new logical elementwise callable type
SadiinsoSnowfall Dec 2, 2024
43e77ee
new behaviour
SadiinsoSnowfall Dec 6, 2024
cb68b56
[ci skip] stash
SadiinsoSnowfall Dec 9, 2024
98a2a82
fix
SadiinsoSnowfall Dec 10, 2024
413396c
fixed NOSIMD + improved operator|| codegen + fixed shadowing
SadiinsoSnowfall Dec 11, 2024
d9c231e
fix
SadiinsoSnowfall Dec 11, 2024
75ec64f
fix typo
SadiinsoSnowfall Dec 12, 2024
c9b000c
fix impls
SadiinsoSnowfall Dec 12, 2024
d88cb08
SVE fix
SadiinsoSnowfall Dec 12, 2024
0e35da3
review fixes
SadiinsoSnowfall Dec 13, 2024
eba6e03
rename concept
SadiinsoSnowfall Dec 13, 2024
8f33961
fix missing includes in wide
SadiinsoSnowfall Dec 16, 2024
eaaa7d0
moved relaxed_logical_scalar_value
SadiinsoSnowfall Dec 16, 2024
25eb612
renamed logical_ops to logical_test
SadiinsoSnowfall Dec 16, 2024
1882295
revert useless changes to strict_elementwise_callable
SadiinsoSnowfall Dec 16, 2024
9903a9b
adjusted comment
SadiinsoSnowfall Dec 16, 2024
1cae9a1
refactor AVX512 code
SadiinsoSnowfall Dec 16, 2024
b446032
revert is_equal return types
SadiinsoSnowfall Dec 16, 2024
742d79d
more comments
SadiinsoSnowfall Dec 16, 2024
6a33114
preemptive fix for comparison operators
SadiinsoSnowfall Dec 17, 2024
1d51da6
Clarify logical_elementwise_callable behavior
jfalcou Dec 17, 2024
a87e245
review fix
SadiinsoSnowfall Dec 20, 2024
753bbeb
remove logical_elementwise_callable
SadiinsoSnowfall Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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};
SadiinsoSnowfall marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -30,6 +30,8 @@
#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/shl.hpp>
#include <eve/module/core/regular/shr.hpp>
#include <eve/memory/soa_ptr.hpp>
#include <eve/traits/product_type.hpp>

Expand Down
18 changes: 18 additions & 0 deletions include/eve/concept/scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,22 @@ 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::scalar_value` concept.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the scalar value here is ofc weird but w/e, I don't want to change it now.

//!
//! @groupheader{Examples}
//! - `eve::logical<char>`
//! - `float`
//! - `bool`
//================================================================================================
template <typename T>
concept relaxed_logical_scalar_value = scalar_value<T> || std::same_as<T, bool>;
//================================================================================================
//! @}
//================================================================================================
}
11 changes: 6 additions & 5 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;
(std::make_index_sequence<sizeof...(Us)-1>());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with this kumi change? This should probably go in upstream first, no? Or do we need to upgrade in lockstep?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upstreal is fixed already as externals CI pass.
This is probably some noise and should be turned back to Ts.

}
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_lognot(logical<wide<T, N>> v) 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 Down Expand Up @@ -50,64 +51,6 @@ 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_lognot(Wide const& v) noexcept
Expand All @@ -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>>());
SadiinsoSnowfall marked this conversation as resolved.
Show resolved Hide resolved
}
}

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

Expand All @@ -199,7 +142,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 @@ -213,7 +156,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 @@ -227,7 +170,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 @@ -241,7 +184,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
Loading