E.V.E
v2023.02.15
Loading...
Searching...
No Matches

Detailed Description

Type conversions

convert, simd_cast,

  • conversion functions take two arguments a value and a scalar type to convert each lane of the value (the value itself, if it is scalar value)
  • The conversion can use the decorator eve::saturated in which case (sic) the result is saturated in the target type.

Variables

constexpr auto eve::as_value = functor<as_value_t>
 converts eve constant or just a value to a type.
constexpr auto eve::convert = functor<convert_t>
 Converts a value to another type.
constexpr auto eve::simd_cast = functor<simd_cast_t>
 casting bits between simd values.

Variable Documentation

◆ as_value

auto eve::as_value = functor<as_value_t>
inlineconstexpr

converts eve constant or just a value to a type.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template<eve::value From, eve::value T>
T as_value(From x, eve::as<T> t) noexcept;
template<eve::generator From, eve::value T>
T as_value(From from, eve::as<T> t) noexcept;
}
constexpr auto as_value
converts eve constant or just a value to a type.
Definition as_value.hpp:80
EVE Main Namespace.
Definition abi.hpp:19
Lightweight type-wrapper.
Definition as.hpp:29

Parameters

  • x: either something convertible to T or an of eve constant
  • t : Type wrapper instance embedding the type of the constant.

Return value

The call eve::as_value(as<T>()) returns a value of type T which is the conversion of x to type Target or the eve constant of type Target.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
std::cout << "---- simd" << '\n'
<< "<- as_value(pf, as<wide_ft>()) = " << eve::as_value(32.5, eve::as<wide_ft>()) << '\n'
<< "<- as_value(valmax, as<wide_it>()) = " << eve::as_value(eve::valmax, eve::as<wide_it>()) << '\n'
;
std::cout << "---- scalar" << '\n'
<< "<- as_value(valmax, as<float>()) = " << eve::as_value(eve::valmax, eve::as<float>()) << '\n';
return 0;
}
constexpr auto valmax
Computes the greatest representable value.
Definition valmax.hpp:67
Wrapper for SIMD registers.
Definition wide.hpp:94

◆ convert

auto eve::convert = functor<convert_t>
inlineconstexpr

Converts a value to another type.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
template<value T, scalar_value Target> Target convert( T x, as_<Target> t) noexcept; //1
// Semantic option
constexpr auto convert[saturated](/* any of the above overloads */) noexcept; // 2
}
constexpr auto convert
Converts a value to another type.
Definition convert.hpp:84
constexpr auto saturated
Keeps the result inside the range of its type instead of wrapping or overflowing.
Definition core.hpp:104

Parameters

Return value

  1. Elementwise conversion of x in the Target type is returned.
  2. The expression convert[saturated](x,t) computes a saturated conversion of x to the type wrapped by t
Note
In scalar mode Conversions operated by convert, follow the regular rules of C++ type conversion, including the cases leading to Undefined Behaviors.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.4, -1.0, -2.0, -3.0, -4.1};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 700u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> convert(wf0, as<int>()) = " << eve::convert(wf0, eve::as<int>()) << "\n";
std::cout << "-> convert(wu0, as<signed char>()) = " << eve::convert(wu0, eve::as<signed char>()) << "\n";
std::cout << "-> convert[saturated](wu0, as<signed char>()) = " << eve::convert[eve::saturated](wu0, eve::as<signed char>()) << "\n";
}

◆ simd_cast

auto eve::simd_cast = functor<simd_cast_t>
inlineconstexpr

casting bits between simd values.

Defined in Header

#include <eve/module/core.hpp>

This cast reinterprets one eve::simd_value as the other, if such reinterpretation is available. If the output is smaller in size, the extra bits are dropped. If the output is bigger, the value of extra bits is unspecified.

What can be simd_cast?

  • any eve::plain_simd_value to any other eve::plain_simd_value
  • product_simd_value to a product_simd_value iff each fields can be simd_cast to the corresponding field.
  • if is_wide_logical: logical_simd_value behaves same as plain_simd_value
  • if !is_wide_logical: any logical_simd_value can cast to any other logical_simd_value, but semantics changes, based on the representation of the logical.
  • on rvv platform allows for an efficient cast between logical and plain_simd_value.

Callable Signatures

namespace eve
{
template <eve::simd_value T, eve::simd_value Target>
requires /* see documentation*/
Target simd_cast(T x, eve::as<Target> tgt);
}
constexpr auto simd_cast
casting bits between simd values.
Definition simd_cast.hpp:111

Parameters

Return value

bits from x reinterpreted as a new type, according to the rules described earlier.

Example

#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide<int, eve::fixed<4>> in {-1, 1, 2, 3};
auto out = eve::simd_cast(in, eve::as<eve::wide<std::uint8_t, eve::fixed<8>>>{});
// Should print two first integers as bytes
std::cout << out << std::endl;
}
SIMD register cardinal type.
Definition cardinals.hpp:39