一呼百應, "one call, a hundred responses"
Loading...
Searching...
No Matches
Numerics

Concepts

concept  ein::one_of
 N is one of the candidates
 
concept  ein::not_one_of
 N is not one of the candidates
 

Classes

struct  ein::imm_t< N >
 A compile time constant passed as an empty struct. More...
 

Typedefs

template<typename T >
using ein::int_t
 returns a signed integer type of the same size as T suitable for std::bitcast
 
template<typename T >
using ein::uint_t
 returns an unsigned integer type of the same size as T suitable for std::bitcast
 

Enumerations

enum class  ein::CMPINT : size_t {
  ein::CMPINT::EQ = 0x0uz ,
  ein::CMPINT::LT = 0x1uz ,
  ein::CMPINT::LE = 0x2uz ,
  ein::CMPINT::FALSE = 0x3uz ,
  ein::CMPINT::NE = 0x4uz ,
  ein::CMPINT::NLT = 0x5uz ,
  ein::CMPINT::NLE = 0x6uz ,
  ein::CMPINT::TRUE = 0x7uz
}
 
enum class  ein::CMP : size_t {
  ein::CMP::EQ_OQ = 0x00uz ,
  ein::CMP::LT_OS = 0x01uz ,
  ein::CMP::LE_OS = 0x02uz ,
  ein::CMP::UNORD_Q = 0x03uz ,
  ein::CMP::NEQ_UQ = 0x04uz ,
  ein::CMP::NLT_US = 0x05uz ,
  ein::CMP::NLE_US = 0x06uz ,
  ein::CMP::ORD_Q = 0x07uz ,
  ein::CMP::EQ_UQ = 0x08uz ,
  ein::CMP::NGE_US = 0x09uz ,
  ein::CMP::NGT_US = 0x0Auz ,
  ein::CMP::FALSE_OQ = 0x0Buz ,
  ein::CMP::NEQ_OQ = 0x0Cuz ,
  ein::CMP::GE_OS = 0x0Duz ,
  ein::CMP::GT_OS = 0x0Euz ,
  ein::CMP::TRUE_UQ = 0x0Fuz ,
  ein::CMP::EQ_OS = 0x10uz ,
  ein::CMP::LT_OQ = 0x11uz ,
  ein::CMP::LE_OQ = 0x12uz ,
  ein::CMP::UNORD_S = 0x13uz ,
  ein::CMP::NEQ_US = 0x14uz ,
  ein::CMP::NLT_UQ = 0x15uz ,
  ein::CMP::NLE_UQ = 0x16uz ,
  ein::CMP::ORD_S = 0x17uz ,
  ein::CMP::EQ_US = 0x18uz ,
  ein::CMP::NGE_UQ = 0x19uz ,
  ein::CMP::NGT_UQ = 0x1Auz ,
  ein::CMP::FALSE_OS = 0x1Buz ,
  ein::CMP::NEQ_OS = 0x1Cuz ,
  ein::CMP::GE_OQ = 0x1Duz ,
  ein::CMP::GT_OQ = 0x1Euz ,
  ein::CMP::TRUE_US = 0x1Fuz
}
 

Functions

template<typename T >
constexpr bool ein::cmp_unord (T a, T b) noexcept
 Return true if either argument is NaN.
 
template<typename T >
constexpr bool ein::cmp_ord (T a, T b) noexcept
 Return true if neither argument is NaN.
 
template<one_of_t< float, double > T>
constexpr T ein::scalef (T x, T y) noexcept
 
template<CMPINT imm8, typename T >
requires (one_of_t<T,uint8_t,int8_t,uint16_t,int16_t,uint32_t,int32_t,uint64_t,int64_t> && (size_t(imm8) < 8uz))
constexpr bool ein::cmpint (T a, T b) noexcept
 
template<CMP imm8, typename T >
requires (one_of_t<T,float,double> && (size_t(imm8) < 32uz))
constexpr bool ein::cmp (T a, T b) noexcept
 perform an avx512 style floating point comparison for scalar values.
 

Variables

template<size_t N>
constinit imm_t< N > ein::imm {}
 A compile time constant passed as an empty struct.
 
constexpr size_t ein::max_fp_comparison_predicate
 AVX512 added many more floating point comparison types. Do we have them?
 

Detailed Description


Class Documentation

◆ ein::imm_t

struct ein::imm_t
template<size_t N>
struct ein::imm_t< N >

A compile time constant passed as an empty struct.

Definition at line 61 of file numerics.hpp.

Public Member Functions

consteval operator size_t () const noexcept
 

Static Public Attributes

static constexpr size_t value = N
 

Member Function Documentation

◆ operator size_t()

template<size_t N>
ein::imm_t< N >::operator size_t ( ) const
inlineconstevalnoexcept[[nodiscard]][[always_inline]][[const]][[artificial]]

Definition at line 64 of file numerics.hpp.

64{ return N; }

Member Data Documentation

◆ value

template<size_t N>
size_t ein::imm_t< N >::value = N
staticconstexpr

Definition at line 62 of file numerics.hpp.

Typedef Documentation

◆ int_t

template<typename T >
using ein::int_t

returns a signed integer type of the same size as T suitable for std::bitcast

Definition at line 51 of file numerics.hpp.

◆ uint_t

template<typename T >
using ein::uint_t

returns an unsigned integer type of the same size as T suitable for std::bitcast

Definition at line 57 of file numerics.hpp.

Enumeration Type Documentation

◆ CMP

enum class ein::CMP : size_t
strong
Enumerator
EQ_OQ 

Equal (ordered, nonsignaling)

LT_OS 

Less-than (ordered, signaling)

LE_OS 

Less-than-or-equal (ordered, signaling)

UNORD_Q 

Unordered (nonsignaling)

NEQ_UQ 

Not-equal (unordered, nonsignaling)

NLT_US 

Not-less-than (unordered, signaling)

NLE_US 

Not-less-than-or-equal (unordered, signaling)

ORD_Q 

Ordered (nonsignaling)

EQ_UQ 

Equal (unordered, nonsignaling) (AVX-512)

NGE_US 

Not-greater-than-or-equal (unordered, signaling) (AVX-512)

NGT_US 

Not-greater-than (unordered, signaling) (AVX-512)

FALSE_OQ 

False (ordered, nonsignaling) (AVX-512)

NEQ_OQ 

Not-equal (ordered, nonsignaling) (AVX-512)

GE_OS 

Greater-than-or-equal (ordered, signaling) (AVX-512)

GT_OS 

Greater-than (ordered, signaling) (AVX-512)

TRUE_UQ 

True (unordered, nonsignaling) (AVX-512)

EQ_OS 

Equal (ordered, signaling) (AVX-512)

LT_OQ 

Less-than (ordered, nonsignaling) (AVX-512)

LE_OQ 

Less-than-or-equal (ordered, nonsignaling) (AVX-512)

UNORD_S 

Unordered (signaling) (AVX-512)

NEQ_US 

Not-equal (unordered, signaling) (AVX-512)

NLT_UQ 

Not-less-than (unordered, nonsignaling) (AVX-512)

NLE_UQ 

Not-less-than-or-equal (unordered, nonsignaling) (AVX-512)

ORD_S 

Ordered (signaling) (AVX-512)

EQ_US 

Equal (unordered, signaling) (AVX-512)

NGE_UQ 

Not-greater-than-or-equal (unordered, nonsignaling) (AVX-512)

NGT_UQ 

Not-greater-than (unordered, nonsignaling) (AVX-512)

FALSE_OS 

False (ordered, signaling) (AVX-512)

NEQ_OS 

Not-equal (ordered, signaling) (AVX-512)

GE_OQ 

Greater-than-or-equal (ordered, nonsignaling) (AVX-512)

GT_OQ 

Greater-than (ordered, nonsignaling) (AVX-512)

TRUE_US 

True (unordered, signaling) (AVX-512)

Definition at line 193 of file numerics.hpp.

◆ CMPINT

enum class ein::CMPINT : size_t
strong
Enumerator
EQ 

==

LT 

<

LE 

<=

FALSE 

always false

NE 

!=

NLT 

>=

NLE 

>

TRUE 

always true

Definition at line 161 of file numerics.hpp.

Function Documentation

◆ cmp()

template<CMP imm8, typename T >
requires (one_of_t<T,float,double> && (size_t(imm8) < 32uz))
bool ein::cmp ( T a,
T b )
constexprnoexcept

perform an avx512 style floating point comparison for scalar values.

Definition at line 232 of file numerics.hpp.

232 {
233 using enum CMP;
234 if constexpr (imm8 == EQ_OQ) return cmp_ord(a, b) && (a == b);
235 else if constexpr (imm8 == LT_OS) return cmp_ord(a, b) && (a < b);
236 else if constexpr (imm8 == LE_OS) return cmp_ord(a, b) && (a <= b);
237 else if constexpr (imm8 == UNORD_Q) return cmp_unord(a, b);
238 else if constexpr (imm8 == NEQ_UQ) return cmp_unord(a, b) || (a != b);
239 else if constexpr (imm8 == NLT_US) return cmp_unord(a, b) || !(a < b);
240 else if constexpr (imm8 == NLE_US) return cmp_unord(a, b) || !(a <= b);
241 else if constexpr (imm8 == ORD_Q) return cmp_ord(a, b);
242 else if constexpr (imm8 == EQ_UQ) return cmp_unord(a, b) || (a == b);
243 else if constexpr (imm8 == NGE_US) return cmp_unord(a, b) || !(a >= b);
244 else if constexpr (imm8 == NGT_US) return cmp_unord(a, b) || !(a > b);
245 else if constexpr (imm8 == FALSE_OQ) return 0;
246 else if constexpr (imm8 == NEQ_OQ) return cmp_ord(a, b) && (a != b);
247 else if constexpr (imm8 == GE_OS) return cmp_ord(a, b) && (a >= b);
248 else if constexpr (imm8 == GT_OS) return cmp_ord(a, b) && (a > b);
249 else if constexpr (imm8 == TRUE_UQ) return -1;
250 else if constexpr (imm8 == EQ_OS) return cmp_ord(a, b) && (a == b);
251 else if constexpr (imm8 == LT_OQ) return cmp_ord(a, b) && (a < b);
252 else if constexpr (imm8 == LE_OQ) return cmp_ord(a, b) && (a <= b);
253 else if constexpr (imm8 == UNORD_S) return cmp_unord(a, b);
254 else if constexpr (imm8 == NEQ_US) return cmp_unord(a, b) || (a != b);
255 else if constexpr (imm8 == NLT_UQ) return cmp_unord(a, b) || !(a < b);
256 else if constexpr (imm8 == NLE_UQ) return cmp_unord(a, b) || !(a <= b);
257 else if constexpr (imm8 == ORD_S) return cmp_ord(a, b);
258 else if constexpr (imm8 == EQ_US) return cmp_unord(a, b) || (a == b);
259 else if constexpr (imm8 == NGE_UQ) return cmp_unord(a, b) || !(a >= b);
260 else if constexpr (imm8 == NGT_UQ) return cmp_unord(a, b) || !(a > b);
261 else if constexpr (imm8 == FALSE_OS) return 0;
262 else if constexpr (imm8 == NEQ_OS) return cmp_ord(a, b) && (a != b);
263 else if constexpr (imm8 == GE_OQ) return cmp_ord(a, b) && (a >= b);
264 else if constexpr (imm8 == GT_OQ) return cmp_ord(a, b) && (a > b);
265 else if constexpr (imm8 == TRUE_US) return -1;
266 else static_assert(false);
267}
@ LE_OQ
Less-than-or-equal (ordered, nonsignaling) (AVX-512)
@ FALSE_OQ
False (ordered, nonsignaling) (AVX-512)
@ NEQ_OS
Not-equal (ordered, signaling) (AVX-512)
@ NLE_US
Not-less-than-or-equal (unordered, signaling)
@ TRUE_US
True (unordered, signaling) (AVX-512)
@ NGE_UQ
Not-greater-than-or-equal (unordered, nonsignaling) (AVX-512)
@ GE_OS
Greater-than-or-equal (ordered, signaling) (AVX-512)
@ NEQ_OQ
Not-equal (ordered, nonsignaling) (AVX-512)
@ ORD_Q
Ordered (nonsignaling)
@ LT_OS
Less-than (ordered, signaling)
@ GE_OQ
Greater-than-or-equal (ordered, nonsignaling) (AVX-512)
@ EQ_US
Equal (unordered, signaling) (AVX-512)
@ TRUE_UQ
True (unordered, nonsignaling) (AVX-512)
@ EQ_OS
Equal (ordered, signaling) (AVX-512)
@ FALSE_OS
False (ordered, signaling) (AVX-512)
@ GT_OS
Greater-than (ordered, signaling) (AVX-512)
@ ORD_S
Ordered (signaling) (AVX-512)
@ NLE_UQ
Not-less-than-or-equal (unordered, nonsignaling) (AVX-512)
@ GT_OQ
Greater-than (ordered, nonsignaling) (AVX-512)
@ UNORD_S
Unordered (signaling) (AVX-512)
@ LE_OS
Less-than-or-equal (ordered, signaling)
@ EQ_OQ
Equal (ordered, nonsignaling)
@ NEQ_UQ
Not-equal (unordered, nonsignaling)
@ EQ_UQ
Equal (unordered, nonsignaling) (AVX-512)
@ NLT_US
Not-less-than (unordered, signaling)
@ UNORD_Q
Unordered (nonsignaling)
@ LT_OQ
Less-than (ordered, nonsignaling) (AVX-512)
@ NLT_UQ
Not-less-than (unordered, nonsignaling) (AVX-512)
@ NGT_US
Not-greater-than (unordered, signaling) (AVX-512)
@ NGE_US
Not-greater-than-or-equal (unordered, signaling) (AVX-512)
@ NGT_UQ
Not-greater-than (unordered, nonsignaling) (AVX-512)
@ NEQ_US
Not-equal (unordered, signaling) (AVX-512)
template bool cmp_unord(float, float) noexcept
template bool cmp_ord(float, float) noexcept

References ein::cmp_ord(), ein::cmp_unord(), ein::EQ_OQ, ein::EQ_OS, ein::EQ_UQ, ein::EQ_US, ein::FALSE_OQ, ein::FALSE_OS, ein::GE_OQ, ein::GE_OS, ein::GT_OQ, ein::GT_OS, ein::LE_OQ, ein::LE_OS, ein::LT_OQ, ein::LT_OS, ein::NEQ_OQ, ein::NEQ_OS, ein::NEQ_UQ, ein::NEQ_US, ein::NGE_UQ, ein::NGE_US, ein::NGT_UQ, ein::NGT_US, ein::NLE_UQ, ein::NLE_US, ein::NLT_UQ, ein::NLT_US, ein::ORD_Q, ein::ORD_S, ein::TRUE_UQ, ein::TRUE_US, ein::UNORD_Q, and ein::UNORD_S.

◆ cmp_ord()

template<typename T >
bool ein::cmp_ord ( T a,
T b )
constexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Return true if neither argument is NaN.

This corresponds to checking if the two arguments are "ordered" with respect to the IEEE floating point comparison predicates

Definition at line 102 of file numerics.hpp.

102 {
103 return !isnan(a) && !isnan(b);
104}
constexpr bool isnan(ein::bf16 x) noexcept
Definition bf16.hpp:131

References std::isnan().

◆ cmp_unord()

template<typename T >
bool ein::cmp_unord ( T a,
T b )
constexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Return true if either argument is NaN.

This corresponds to checking if the two arguments are "unordered" with respect to the IEEE floating point comparison predicates

Definition at line 85 of file numerics.hpp.

85 {
86 return isnan(a) || isnan(b);
87}

References std::isnan().

◆ cmpint()

template<CMPINT imm8, typename T >
requires (one_of_t<T,uint8_t,int8_t,uint16_t,int16_t,uint32_t,int32_t,uint64_t,int64_t> && (size_t(imm8) < 8uz))
bool ein::cmpint ( T a,
T b )
constexprnoexcept

Definition at line 175 of file numerics.hpp.

175 {
176 using enum CMPINT;
177 if constexpr (imm8 == TRUE) return -1;
178 else if constexpr (imm8 == FALSE) return 0;
179 else if constexpr (imm8 == LT) return a < b;
180 else if constexpr (imm8 == NLT) return a >= b;
181 else if constexpr (imm8 == LE) return a <= b;
182 else if constexpr (imm8 == NLE) return a > b;
183 else if constexpr (imm8 == EQ) return a == b;
184 else if constexpr (imm8 == NE) return a != b;
185 else static_assert(false);
186}
@ FALSE
always false
@ TRUE
always true

References ein::EQ, ein::FALSE, ein::LE, ein::LT, ein::NE, ein::NLE, ein::NLT, and ein::TRUE.

◆ scalef()

template<one_of_t< float, double > T>
T ein::scalef ( T x,
T y )
constexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 114 of file numerics.hpp.

References std::isnan().

Variable Documentation

◆ imm

template<size_t N>
imm_t<N> ein::imm {}
constinit

A compile time constant passed as an empty struct.

Allow passing immediate values to operators without having to give up x << y as a syntactic form. xs << imm<n> isn't much of an imposition and ensures the compiler knows that N is a fixed constant known at compile time

Definition at line 75 of file numerics.hpp.

75{};

◆ max_fp_comparison_predicate

size_t ein::max_fp_comparison_predicate
constexpr

AVX512 added many more floating point comparison types. Do we have them?

Definition at line 190 of file numerics.hpp.