Skip to content

Commit

Permalink
changed impl & added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SadiinsoSnowfall committed Nov 22, 2024
1 parent 858d6c4 commit 1c91a23
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
23 changes: 17 additions & 6 deletions include/eve/arch/cpu/logical_wide.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@

namespace eve
{
namespace detail
{
template<typename T, typename N>
struct logical_split_type_helper
{ };

template<typename T, typename N>
requires(N::value > 1)
struct logical_split_type_helper<T, N>
{
//! Type representing a logical of the same type but with a cardinal half the size
using split_type = logical<wide<T, typename N::split_type>>;
};
}

//================================================================================================
//! @addtogroup simd_types
//! @{
Expand All @@ -52,7 +67,8 @@ namespace eve
//================================================================================================
template<arithmetic_scalar_value Type, typename Cardinal>
struct EVE_MAY_ALIAS logical<wide<Type,Cardinal>>
: detail::wide_storage<as_logical_register_t<Type, Cardinal, abi_t<Type, Cardinal>>>
: detail::wide_storage<as_logical_register_t<Type, Cardinal, abi_t<Type, Cardinal>>>,
detail::logical_split_type_helper<Type, Cardinal>
{
using storage_base = detail::wide_storage<as_logical_register_t<Type, Cardinal, abi_t<Type, Cardinal>>>;

Expand Down Expand Up @@ -80,11 +96,6 @@ namespace eve
//! Type representing a logical wide of the same type but with a cardinal twice the size
using combined_type = logical<wide<Type, typename Cardinal::combined_type>>;

//! Type representing a logical wide of the same type but with a cardinal half the size
template<typename N = Cardinal>
requires (N::Value > 1)
using split_type = logical<typename wide<Type, N>::split_type>;

//! @brief Generates a eve::wide from a different type `T` and cardinal `N`.
//! If unspecified, `N` is computed as `expected_cardinal_t<T>`.
template<typename T, typename N = expected_cardinal_t<T>> using rebind = logical<wide<T,N>>;
Expand Down
23 changes: 17 additions & 6 deletions include/eve/arch/cpu/wide.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@

#include <type_traits>

namespace eve::detail
{
template<typename T, typename N>
struct wide_split_type_helper
{ };

template<typename T, typename N>
requires(N::value > 1)
struct wide_split_type_helper<T, N>
{
//! Type representing a wide of the same type but with a cardinal half the size
using split_type = wide<T, typename N::split_type>;
};
}

#if !defined(EVE_DOXYGEN_INVOKED)
namespace eve
{
Expand Down Expand Up @@ -66,7 +81,8 @@ namespace eve
//================================================================================================
template<arithmetic_scalar_value Type, typename Cardinal>
struct EVE_MAY_ALIAS wide
: detail::wide_storage<as_register_t<Type, Cardinal, abi_t<Type, Cardinal>>>
: detail::wide_storage<as_register_t<Type, Cardinal, abi_t<Type, Cardinal>>>,
detail::wide_split_type_helper<Type, Cardinal>
{
using storage_base = detail::wide_storage<as_register_t<Type, Cardinal, abi_t<Type, Cardinal>>>;

Expand All @@ -91,11 +107,6 @@ namespace eve
//! Type representing a wide of the same type but with a cardinal twice the size
using combined_type = wide<Type, typename Cardinal::combined_type>;

//! Type representing a wide of the same type but with a cardinal half the size
template<typename N = Cardinal>
requires (N::Value > 1)
using split_type = wide<Type, typename N::split_type>;

//! @brief Generates a eve::wide from a different type `T` and cardinal `N`.
//! If unspecified, `N` is computed as `expected_cardinal_t<T>`.
template<typename T, typename N = expected_cardinal_t<T>> using rebind = wide<T, N>;
Expand Down
16 changes: 16 additions & 0 deletions test/unit/api/regular/logicals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
//==================================================================================================
// type tests
//==================================================================================================
template<typename T>
constexpr typename T::split_type test_split(T) { return {}; }

TTS_CASE_TPL( "Check return types of logical operators on wide", eve::test::simd::all_types)
<typename T>(tts::type<T>)
{
using v_t = eve::element_type_t<T>;
using c_t = eve::cardinal_t<T>;

TTS_EXPR_IS( eve::logical<T>() && eve::logical<T>() , eve::logical<T>);
TTS_EXPR_IS( eve::logical<T>() && eve::logical<v_t>(), eve::logical<T>);
Expand All @@ -23,6 +27,18 @@ TTS_CASE_TPL( "Check return types of logical operators on wide", eve::test::simd
TTS_EXPR_IS( eve::logical<T>() || eve::logical<v_t>(), eve::logical<T>);
TTS_EXPR_IS( eve::logical<v_t>() || eve::logical<T>() , eve::logical<T>);
TTS_EXPR_IS( !eve::logical<T>() , eve::logical<T>);

if constexpr (c_t::value == 1)
{
auto x = eve::logical<T>{};
TTS_EXPECT_NOT_COMPILES(x, { test_split(x); });
}
else
{
TTS_EXPR_IS((typename eve::logical<T>::split_type){}, eve::logical<typename T::split_type>);
}

TTS_EXPR_IS((typename eve::logical<T>::combined_type){}, eve::logical<typename T::combined_type>);
};

//==================================================================================================
Expand Down
25 changes: 25 additions & 0 deletions test/unit/api/regular/wide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,28 @@ TTS_CASE_TPL("Check eve::wide insert/set", eve::test::simd::all_types)
}
}
};

//==================================================================================================
// Split/Combine
//==================================================================================================
template<typename T>
constexpr typename T::split_type test_split(T) { return {}; }

TTS_CASE_TPL("Check eve::wide split_type/combined_type", eve::test::simd::all_types)
<typename T>(tts::type<T>)
{
using v_t = eve::element_type_t<T>;
using c_t = eve::cardinal_t<T>;

if constexpr (c_t::value == 1)
{
auto x = T{};
TTS_EXPECT_NOT_COMPILES(x, { test_split(x); });
}
else
{
TTS_EXPR_IS((typename T::split_type){}, (eve::wide<v_t, typename c_t::split_type>));
}

TTS_EXPR_IS((typename T::combined_type){}, (eve::wide<v_t, typename c_t::combined_type>));
};

0 comments on commit 1c91a23

Please sign in to comment.