batch

template<class T, class A = default_arch>
class xsimd::batch : public types::simd_register<T, default_arch>

batch of integer or floating point values.

Abstract representation of an SIMD register for floating point or integral value.

tparam T

the type of the underlying values.

tparam A

the architecture this batch is tied too.

Public Functions

template<class U>
void store_aligned(U *mem) const

Copy content of this batch to the buffer mem.

The memory needs to be aligned.

Parameters

mem – the memory buffer to read

template<class U>
void store_unaligned(U *mem) const

Copy content of this batch to the buffer mem.

The memory does not need to be aligned.

Parameters

mem – the memory buffer to write to

template<class U>
batch<T, A> load_aligned(U const *mem)

Loading from aligned memory.

May involve a conversion if U is different from T.

Parameters

mem – the memory buffer to read from.

Returns

a new batch instance.

template<class U>
batch<T, A> load_unaligned(U const *mem)

Loading from unaligned memory.

May involve a conversion if U is different from T.

Parameters

mem – the memory buffer to read from.

Returns

a new batch instance.

Arithmetic operators

template<class T, class Tp>
auto add(T const &x, Tp const &y) -> decltype(x + y)

Computes the sum of the batches x and y.

Parameters
  • x – batch or scalar involved in the addition.

  • y – batch or scalar involved in the addition.

Returns

the sum of x and y

template<class T, class Tp>
auto div(T const &x, Tp const &y) -> decltype(x / y)

Computes the division of the batch x by the batch y.

Parameters
  • x – scalar or batch of scalars

  • y – scalar or batch of scalars

Returns

the result of the division.

template<class T, class A>
batch<T, A> fma(batch<T, A> const &x, batch<T, A> const &y, batch<T, A> const &z)

Computes (x*y) + z in a single instruction when possible.

Parameters
  • x – a batch of integer or floating point values.

  • y – a batch of integer or floating point values.

  • z – a batch of integer or floating point values.

Returns

the result of the fused multiply-add operation.

template<class T, class A>
batch<T, A> fms(batch<T, A> const &x, batch<T, A> const &y, batch<T, A> const &z)

Computes (x*y) - z in a single instruction when possible.

Parameters
  • x – a batch of integer or floating point values.

  • y – a batch of integer or floating point values.

  • z – a batch of integer or floating point values.

Returns

the result of the fused multiply-sub operation.

template<class T, class A>
batch<T, A> fnma(batch<T, A> const &x, batch<T, A> const &y, batch<T, A> const &z)

Computes -(x*y) + z in a single instruction when possible.

Parameters
  • x – a batch of integer or floating point values.

  • y – a batch of integer or floating point values.

  • z – a batch of integer or floating point values.

Returns

the result of the fused negated multiply-add operation.

template<class T, class A>
batch<T, A> fnms(batch<T, A> const &x, batch<T, A> const &y, batch<T, A> const &z)

Computes -(x*y) - z in a single instruction when possible.

Parameters
  • x – a batch of integer or floating point values.

  • y – a batch of integer or floating point values.

  • z – a batch of integer or floating point values.

Returns

the result of the fused negated multiply-sub operation.

template<class T, class Tp>
auto mod(T const &x, Tp const &y) -> decltype(x % y)

Computes the integer modulo of the batch x by the batch y.

Parameters
  • x – batch involved in the modulo.

  • y – batch involved in the modulo.

Returns

the result of the modulo.

template<class T, class Tp>
auto mul(T const &x, Tp const &y) -> decltype(x * y)

Computes the product of the batches x and y.

Template Parameters

X – the actual type of batch.

Parameters
  • x – batch involved in the product.

  • y – batch involved in the product.

Returns

the result of the product.

template<class T, class A>
batch<T, A> neg(batch<T, A> const &x)

Computes the opposite of the batch x.

Parameters

x – batch involved in the operation.

Returns

the opposite of x.

template<class T, class A>
batch<T, A> pos(batch<T, A> const &x)

No-op on x.

Parameters

x – batch involved in the operation.

Returns

x.

template<class T, class Tp>
auto sadd(T const &x, Tp const &y) -> decltype(x + y)

Computes the saturate sum of the batch x and the batch y.

x.

Template Parameters

X – the actual type of batch.

Parameters
  • x – batch involved in the saturated addition.

  • y – batch involved in the saturated addition.

Returns

the result of the saturated addition.

template<class T, class Tp>
auto ssub(T const &x, Tp const &y) -> decltype(x - y)

Computes the saturate difference of the batch x and the batch y.

x.

Template Parameters

X – the actual type of batch.

Parameters
  • x – batch involved in the saturated difference.

  • y – batch involved in the saturated difference.

Returns

the result of the saturated difference.

template<class T, class Tp>
auto sub(T const &x, Tp const &y) -> decltype(x - y)

Computes the difference between x and y.

Template Parameters

X – the actual type of batch.

Parameters
  • x – scalar or batch of scalars

  • y – scalar or batch of scalars

Returns

the difference between x and y

Comparison operators

template<class T, class A>
batch_bool<T, A> eq(batch<T, A> const &x, batch<T, A> const &y)

Element-wise equality comparison of batches x and y.

Parameters
  • x – batch of scalars

  • y – batch of scalars

Returns

a boolean batch.

template<class T, class A>
batch_bool<T, A> ge(batch<T, A> const &x, batch<T, A> const &y)

Element-wise greater or equal comparison of batches x and y.

Template Parameters

X – the actual type of batch.

Parameters
  • x – batch involved in the comparison.

  • y – batch involved in the comparison.

Returns

a boolean batch.

template<class T, class A>
batch_bool<T, A> gt(batch<T, A> const &x, batch<T, A> const &y)

Element-wise greater than comparison of batches x and y.

Template Parameters

X – the actual type of batch.

Parameters
  • x – batch involved in the comparison.

  • y – batch involved in the comparison.

Returns

a boolean batch.

template<class T, class A>
batch_bool<T, A> is_even(batch<T, A> const &x)

Determines if the scalars in the given batch x represent an even integer value.

Parameters

x – batch of floating point values.

Returns

a batch of booleans.

template<class T, class A>
batch_bool<T, A> is_flint(batch<T, A> const &x)

Determines if the floating-point scalars in the given batch x represent integer value.

Parameters

x – batch of floating point values.

Returns

a batch of booleans.

template<class T, class A>
batch_bool<T, A> is_odd(batch<T, A> const &x)

Determines if the scalars in the given batch x represent an odd integer value.

Parameters

x – batch of floating point values.

Returns

a batch of booleans.

template<class T, class A>
batch_bool<T, A> isinf(batch<T, A> const &x)

Determines if the scalars in the given batch x are inf values.

Parameters

x – batch of floating point values.

Returns

a batch of booleans.

template<class T, class A>
batch_bool<T, A> isfinite(batch<T, A> const &x)

Determines if the scalars in the given batch x are finite values.

Parameters

x – batch of floating point values.

Returns

a batch of booleans.

template<class T, class A>
batch<T, A>::batch_bool_type isnan(batch<T, A> const &x)

Determines if the scalars in the given batch x are NaN values.

Parameters

x – batch of floating point values.

Returns

a batch of booleans.

template<class T, class A>
batch_bool<T, A> le(batch<T, A> const &x, batch<T, A> const &y)

Element-wise lesser or equal to comparison of batches x and y.

Parameters
  • x – batch involved in the comparison.

  • y – batch involved in the comparison.

Returns

a boolean batch.

template<class T, class A>
batch_bool<T, A> lt(batch<T, A> const &x, batch<T, A> const &y)

Element-wise lesser than comparison of batches x and y.

Parameters
  • x – batch involved in the comparison.

  • y – batch involved in the comparison.

Returns

a boolean batch.

template<class T, class A>
batch_bool<T, A> neq(batch<T, A> const &x, batch<T, A> const &y)

Element-wise inequality comparison of batches x and y.

Parameters
  • x – batch involved in the comparison.

  • y – batch involved in the comparison.

Returns

a boolean batch.

Bitwise operators

template<class T, class Tp>
auto bitwise_and(T const &x, Tp const &y) -> decltype(x & y)

Computes the bitwise and of the batches x and y.

Parameters
  • x – batch involved in the operation.

  • y – batch involved in the operation.

Returns

the result of the bitwise and.

template<class T, class A>
batch<T, A> bitwise_andnot(batch<T, A> const &x, batch<T, A> const &y)

Computes the bitwise and not of batches x and y.

Parameters
  • x – batch involved in the operation.

  • y – batch involved in the operation.

Returns

the result of the bitwise and not.

template<class T, class A>
batch<T, A> bitwise_not(batch<T, A> const &x)

Computes the bitwise not of batch x.

Parameters

x – batch involved in the operation.

Returns

the result of the bitwise not.

template<class T, class Tp>
auto bitwise_or(T const &x, Tp const &y) -> decltype(x | y)

Computes the bitwise or of the batches x and y.

Parameters
  • x – scalar or batch of scalars

  • y – scalar or batch of scalars

Returns

the result of the bitwise or.

template<class T, class Tp>
auto bitwise_xor(T const &x, Tp const &y) -> decltype(x ^ y)

Computes the bitwise xor of the batches x and y.

Parameters
  • x – scalar or batch of scalars

  • y – scalar or batch of scalars

Returns

the result of the bitwise xor.

Reducers

template<class T, class A>
T hadd(batch<T, A> const &x)

Adds all the scalars of the batch x.

Parameters

x – batch involved in the reduction

Returns

the result of the reduction.

template<class T, class A>
batch<T, A> haddp(batch<T, A> const *row)

Parallel horizontal addition: adds the scalars of each batch in the array pointed by row and store them in a returned batch.

Parameters

row – an array of N batches

Returns

the result of the reduction.

Miscellaneous

template<class T, class A>
batch<T, A> bitofsign(batch<T, A> const &x)

Computes the bit of sign of x.

Parameters

x – batch of scalar

Returns

bit of sign of x

template<class A, class T>
batch<T, A> copysign(batch<T, A> const &x, batch<T, A> const &y)

Computes a value whose absolute value matches that of x, but whose sign bit matches that of y.

Parameters
  • x – batch of scalars

  • y – batch of scalars

Returns

batch whose absolute value matches that of x, but whose sign bit matches that of y.

template<class T, class A>
batch<T, A> select(batch_bool<T, A> const &cond, batch<T, A> const &true_br, batch<T, A> const &false_br)

Ternary operator for batches: selects values from the batches true_br or false_br depending on the boolean values in the constant batch cond.

Equivalent to

for(std::size_t i = 0; i < N; ++i)
    res[i] = cond[i] ? true_br[i] : false_br[i];

Parameters
  • cond – constant batch condition.

  • true_br – batch values for truthy condition.

  • false_br – batch value for falsy condition.

Returns

the result of the selection.

template<class T, class A>
batch<std::complex<T>, A> select(batch_bool<T, A> const &cond, batch<std::complex<T>, A> const &true_br, batch<std::complex<T>, A> const &false_br)

Ternary operator for batches: selects values from the batches true_br or false_br depending on the boolean values in the constant batch cond.

Equivalent to

for(std::size_t i = 0; i < N; ++i)
    res[i] = cond[i] ? true_br[i] : false_br[i];

Parameters
  • cond – constant batch condition.

  • true_br – batch values for truthy condition.

  • false_br – batch value for falsy condition.

Returns

the result of the selection.

template<class T, class A, bool... Values>
batch<T, A> select(batch_bool_constant<batch<T, A>, Values...> const &cond, batch<T, A> const &true_br, batch<T, A> const &false_br)

Ternary operator for batches: selects values from the batches true_br or false_br depending on the boolean values in the constant batch cond.

Equivalent to

for(std::size_t i = 0; i < N; ++i)
    res[i] = cond[i] ? true_br[i] : false_br[i];

Parameters
  • cond – constant batch condition.

  • true_br – batch values for truthy condition.

  • false_br – batch value for falsy condition.

Returns

the result of the selection.

template<class T, class A>
batch<T, A> sign(batch<T, A> const &x)

Computes the sign of x.

Parameters

x – batch

Returns

-1 for each negative element, -1 or +1 for each null element and +1 for each element

template<class T, class A>
batch<T, A> signnz(batch<T, A> const &x)

Computes the sign of x, assuming x doesn’t have any zero.

Parameters

x – batch

Returns

-1 for each negative element, -1 or +1 for each null element and +1 for each element

template<class T, class A>
std::ostream &operator<<(std::ostream &o, batch<T, A> const &x)

Dump the content of batch x to stream o.

Parameters
  • o – the stream where the batch is dumped

  • x – batch to dump.

Returns

a reference to o