-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement fundamental_cardinal (#815)
The fundamental cardinal of a Type x ABI is the smallest cardinal we can use before having to let some lanes unused.
- Loading branch information
Showing
9 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//================================================================================================== | ||
/* | ||
EVE - Expressive Vector Engine | ||
Copyright : EVE Contributors & Maintainers | ||
SPDX-License-Identifier: MIT | ||
*/ | ||
//================================================================================================== | ||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <eve/arch/cardinals.hpp> | ||
#include <eve/arch/spec.hpp> | ||
#include <eve/detail/meta.hpp> | ||
#include <eve/detail/kumi.hpp> | ||
#include <type_traits> | ||
#include <limits> | ||
#include <utility> | ||
|
||
namespace eve | ||
{ | ||
//================================================================================================ | ||
//! @addtogroup arch | ||
//! @{ | ||
//! @struct fundamental_cardinal | ||
//! @brief Computes the fundamental cardinal of a given type | ||
//! | ||
//! **Required header:** `#include <eve/arch/fundamental_cardinal.hpp>` | ||
//! | ||
//! eve::fundamental_cardinal computed the cardinal of the smallest register able to store | ||
//! values of type `Type` for a given SIMD `ABI` with no uninitialized lanes. | ||
//! | ||
//! @tparam Type Type of value to assess | ||
//! @tparam ABI SIMD ABI to use as reference. Must models eve::regular_abi. | ||
//! | ||
//! #### Member types | ||
//! | ||
//! |Name | Definition | | ||
//! |:------|:-----------------------------------------| | ||
//! |`type` | The type of cardinal computed for `Type` | | ||
//! | ||
//! <br/> | ||
//! #### Helper types | ||
//! | ||
//! @code{.cpp} | ||
//! template<typename Type, regular_abi ABI = EVE_CURRENT_ABI> | ||
//! using fundamental_cardinal_t = typename fundamental_cardinal<Type, ABI>::type; | ||
//! @endcode | ||
//! | ||
//! <br/> | ||
//! #### Helper variable template | ||
//! | ||
//! @code{.cpp} | ||
//! template<typename Type, regular_abi ABI = EVE_CURRENT_ABI> | ||
//! inline constexpr auto fundamental_cardinal_v = fundamental_cardinal_t<Type, ABI>::value; | ||
//! @endcode | ||
//! | ||
//! @code{.cpp} | ||
//! // Cardinal template inline variable to use with functions like eve::load | ||
//! template<typename Type, typename ABI = EVE_CURRENT_ABI> | ||
//! inline constexpr fundamental_cardinal<Type,ABI> const fundamental = {}; | ||
//! @endcode | ||
//! @} | ||
//================================================================================================ | ||
template<typename Type, regular_abi ABI = EVE_CURRENT_ABI> | ||
struct fundamental_cardinal | ||
: fixed<ABI::template fundamental_cardinal<Type>> | ||
{ | ||
using type = fixed<ABI::template fundamental_cardinal<Type>>; | ||
}; | ||
|
||
template<typename Type, regular_abi ABI = EVE_CURRENT_ABI> | ||
using fundamental_cardinal_t = typename fundamental_cardinal<Type, ABI>::type; | ||
|
||
template<typename Type, regular_abi ABI = EVE_CURRENT_ABI> | ||
constexpr inline auto fundamental_cardinal_v = fundamental_cardinal<Type, ABI>::value; | ||
|
||
//================================================================================================ | ||
// product_type special case | ||
//================================================================================================ | ||
namespace detail | ||
{ | ||
template<typename T, regular_abi ABI> struct min_fundamental; | ||
|
||
template<typename... T, regular_abi ABI> | ||
struct min_fundamental<kumi::tuple<T...>,ABI> | ||
{ | ||
static constexpr std::ptrdiff_t value = std::min({fundamental_cardinal<T,ABI>::value...}); | ||
}; | ||
} | ||
|
||
template<kumi::product_type T, regular_abi ABI> | ||
struct fundamental_cardinal<T,ABI> : fixed<detail::min_fundamental<kumi::as_tuple_t<T>,ABI>::value> | ||
{ | ||
using type = fixed<detail::min_fundamental<kumi::as_tuple_t<T>,ABI>::value>; | ||
}; | ||
|
||
template<typename Type, typename ABI = EVE_CURRENT_ABI> | ||
inline constexpr fundamental_cardinal<Type,ABI> const fundamental = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//================================================================================================== | ||
/** | ||
EVE - Expressive Vector Engine | ||
Copyright : EVE Contributors & Maintainers | ||
SPDX-License-Identifier: MIT | ||
**/ | ||
//================================================================================================== | ||
#include "test.hpp" | ||
#include <eve/wide.hpp> | ||
#include <eve/arch/fundamental_cardinal.hpp> | ||
|
||
TTS_CASE("Check for 64 bits ABI fundamental cardinal") | ||
{ | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<double, eve::arm_64_>), 1); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<float , eve::arm_64_>), 2); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<short , eve::arm_64_>), 4); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<char , eve::arm_64_>), 8); | ||
}; | ||
|
||
TTS_CASE("Check for 128 bits ABI fundamental cardinal") | ||
{ | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<double, eve::arm_128_>), 1); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<float , eve::arm_128_>), 2); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<short , eve::arm_128_>), 4); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<char , eve::arm_128_>), 8); | ||
|
||
TTS_EQUAL( (eve::fundamental_cardinal_v<double, eve::ppc_>), 2 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<float , eve::ppc_>), 4 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<short , eve::ppc_>), 8 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<char , eve::ppc_>), 16 ); | ||
|
||
TTS_EQUAL( (eve::fundamental_cardinal_v<double, eve::x86_128_>), 2 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<float , eve::x86_128_>), 4 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<short , eve::x86_128_>), 8 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<char , eve::x86_128_>), 16 ); | ||
|
||
TTS_EQUAL( (eve::fundamental_cardinal_v<double, eve::emulated_>), 2 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<float , eve::emulated_>), 4 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<short , eve::emulated_>), 8 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<char , eve::emulated_>), 16 ); | ||
}; | ||
|
||
TTS_CASE("Check for 256 bits ABI fundamental cardinal") | ||
{ | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<double, eve::x86_256_>), 2 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<float , eve::x86_256_>), 4 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<short , eve::x86_256_>), 8 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<char , eve::x86_256_>), 16 ); | ||
}; | ||
|
||
TTS_CASE("Check for 512 bits ABI fundamental cardinal") | ||
{ | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<double, eve::x86_512_>), 2 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<float , eve::x86_512_>), 4 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<short , eve::x86_512_>), 8 ); | ||
TTS_EQUAL( (eve::fundamental_cardinal_v<char , eve::x86_512_>), 16 ); | ||
}; |