Skip to content

Commit

Permalink
made common_logical more commutative
Browse files Browse the repository at this point in the history
  • Loading branch information
SadiinsoSnowfall committed Sep 26, 2024
1 parent 7a50829 commit 48d1d7b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
15 changes: 8 additions & 7 deletions include/eve/module/core/regular/logical_and.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ namespace eve
template<callable_options O, typename T, typename U>
EVE_FORCEINLINE constexpr common_logical_t<T, U> logical_and_(EVE_REQUIRES(cpu_), O const&, T a, U b) noexcept
{
if constexpr ((scalar_value<T> || std::same_as<T, bool>) && (scalar_value<U> || std::same_as<U, bool>)) return a && b;
else if constexpr (std::same_as<T, bool>) return logical_and(U{a}, b);
else if constexpr (std::same_as<U, bool>) return logical_and(a, T{b});
else if constexpr (scalar_value<T> && simd_value<U>) return logical_and(as_wide_as_t<T, U>{a}, b);
else if constexpr (simd_value<T> && scalar_value<U>) return logical_and(a, T{b});
else if constexpr (std::same_as<typename T::bits_type, typename U::bits_type>) return bit_cast(a.bits() & b.bits(), as<as_logical_t<T>>{});
else return logical_and(a, convert(b, as<typename T::value_type>{}));
if constexpr ((scalar_value<T> || std::same_as<T, bool>)
&& (scalar_value<U> || std::same_as<U, bool>)) return a && b;
else if constexpr (std::same_as<T, bool>) return logical_and(U{a}, b);
else if constexpr (std::same_as<U, bool>) return logical_and(a, T{b});
else if constexpr (simd_value<T> && scalar_value<U>) return logical_and(a, T{b});
else if constexpr (scalar_value<T> && simd_value<U>) return logical_and(b, U{a});
else if constexpr (std::same_as<typename T::bits_type, typename U::bits_type>) return bit_cast(a.bits() & b.bits(), as<as_logical_t<T>>{});
else return logical_and(a, convert(b, as<typename T::value_type>{}));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/eve/traits/common_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ namespace eve::detail
) {
if constexpr (std::same_as<T, bool> && std::same_as<U, bool>) return find_common_logical_reducer<bool>{};
else if constexpr (simd_value<T>) return find_common_logical_reducer<as_logical_t<T>>{};
else if constexpr (simd_value<U>) return find_common_logical_reducer<as_logical_t<U>>{};
else if constexpr (std::same_as<T, bool>) return find_common_logical_reducer<as_logical_t<U>>{};
else if constexpr (std::same_as<U, bool>) return find_common_logical_reducer<as_logical_t<T>>{};
else if constexpr (scalar_value<U>) return find_common_logical_reducer<as_logical_t<T>>{};
else if constexpr (simd_value<U>) return find_common_logical_reducer<as_logical_t<as_wide_as_t<T, U>>>{};
else return find_common_logical_reducer<void>{};
}
};
Expand Down
10 changes: 4 additions & 6 deletions test/unit/meta/traits/common_logical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,15 @@ TTS_CASE_TPL("eve::common_logical on wide x wide"
using Wt = eve::wide<T>;
using Wu = eve::wide<U>;

using uWt = eve::as_wide_as_t<T, Wu>;

TTS_TYPE_IS((eve::common_logical_t<Wt, Wu>), eve::logical<Wt>);
TTS_TYPE_IS((eve::common_logical_t<Wt, eve::logical<Wu>>), eve::logical<Wt>);
TTS_TYPE_IS((eve::common_logical_t<eve::logical<Wt>, Wu>), eve::logical<Wt>);
TTS_TYPE_IS((eve::common_logical_t<eve::logical<Wt>, eve::logical<Wu>>), eve::logical<Wt>);

TTS_TYPE_IS((eve::common_logical_t<T, Wu>), eve::logical<uWt>);
TTS_TYPE_IS((eve::common_logical_t<T, eve::logical<Wu>>), eve::logical<uWt>);
TTS_TYPE_IS((eve::common_logical_t<eve::logical<T>, Wu>), eve::logical<uWt>);
TTS_TYPE_IS((eve::common_logical_t<eve::logical<T>, eve::logical<Wu>>), eve::logical<uWt>);
TTS_TYPE_IS((eve::common_logical_t<T, Wu>), eve::logical<Wu>);
TTS_TYPE_IS((eve::common_logical_t<T, eve::logical<Wu>>), eve::logical<Wu>);
TTS_TYPE_IS((eve::common_logical_t<eve::logical<T>, Wu>), eve::logical<Wu>);
TTS_TYPE_IS((eve::common_logical_t<eve::logical<T>, eve::logical<Wu>>), eve::logical<Wu>);

TTS_TYPE_IS((eve::common_logical_t<Wt, U>), eve::logical<Wt>);
TTS_TYPE_IS((eve::common_logical_t<Wt, eve::logical<U>>), eve::logical<Wt>);
Expand Down

0 comments on commit 48d1d7b

Please sign in to comment.