simd_batch

template<class X>
class xsimd::simd_batch : public xsimd::simd_base<X>

Base class for batch of integer or floating point values.

The simd_batch class is the base class for all classes representing a batch of integer or floating point values. Each type of batch (i.e. a class inheriting from simd_batch) has its dedicated type of boolean batch (i.e. a class inheriting from simd_batch_bool) for logical operations.

See

simd_batch_bool

tparam X

The derived type

Subclassed by xsimd::avx512_int_batch< uint8_t, 64 >, xsimd::avx512_int_batch< uint32_t, 16 >, xsimd::avx512_int_batch< uint16_t, 32 >, xsimd::avx512_int_batch< int64_t, 8 >, xsimd::avx512_int_batch< uint64_t, 8 >, xsimd::avx512_int_batch< int8_t, 64 >, xsimd::avx512_int_batch< int32_t, 16 >, xsimd::avx512_int_batch< int16_t, 32 >, xsimd::avx_int_batch< int64_t, 4 >, xsimd::avx_int_batch< uint32_t, 8 >, xsimd::avx_int_batch< int32_t, 8 >, xsimd::avx_int_batch< int16_t, 16 >, xsimd::avx_int_batch< int8_t, 32 >, xsimd::avx_int_batch< uint64_t, 4 >, xsimd::avx_int_batch< uint8_t, 32 >, xsimd::avx_int_batch< uint16_t, 16 >, xsimd::sse_int_batch< uint32_t, 4 >, xsimd::sse_int_batch< int8_t, 16 >, xsimd::sse_int_batch< int64_t, 2 >, xsimd::sse_int_batch< int16_t, 8 >, xsimd::sse_int_batch< uint16_t, 8 >, xsimd::sse_int_batch< uint8_t, 16 >, xsimd::sse_int_batch< int32_t, 4 >, xsimd::sse_int_batch< uint64_t, 2 >

Static builders

static inline X broadcast(value_type v)

Creates a batch from the single value v.

Parameters

v – the value used to initialize the batch

Returns

a new batch instance

template<class T>
static inline X from_unaligned(T *src)

Creates a batch from the buffer src.

The memory does not need to be aligned.

Parameters

src – the memory buffer to read

Returns

a new batch instance

template<class T>
static inline X from_aligned(T *src)

Creates a batch from the buffer src.

The memory needs to be aligned.

Parameters

src – the memory buffer to read

Returns

a new batch instance

Arithmetic computed assignment

inline X &operator+=(const X &rhs)

Adds the batch rhs to this.

Parameters

rhs – the batch to add.

Returns

a reference to this.

inline X &operator+=(const value_type &rhs)

Adds the scalar rhs to each value contained in this.

Parameters

rhs – the scalar to add.

Returns

a reference to this.

inline X &operator-=(const X &rhs)

Substracts the batch rhs to this.

Parameters

rhs – the batch to substract.

Returns

a reference to this.

inline X &operator-=(const value_type &rhs)

Substracts the scalar rhs to each value contained in this.

Parameters

rhs – the scalar to substract.

Returns

a reference to this.

inline X &operator*=(const X &rhs)

Multiplies this with the batch rhs.

Parameters

rhs – the batch involved in the multiplication.

Returns

a reference to this.

inline X &operator*=(const value_type &rhs)

Multiplies each scalar contained in this with the scalar rhs.

Parameters

rhs – the scalar involved in the multiplication.

Returns

a reference to this.

inline X &operator/=(const X &rhs)

Divides this by the batch rhs.

Parameters

rhs – the batch involved in the division.

Returns

a reference to this.

inline X &operator/=(const value_type &rhs)

Divides each scalar contained in this by the scalar rhs.

Parameters

rhs – the scalar involved in the division.

Returns

a reference to this.

Bitwise computed assignment

inline X &operator&=(const X &rhs)

Assigns the bitwise and of rhs and this.

Parameters

rhs – the batch involved in the operation.

Returns

a reference to this.

inline X &operator|=(const X &rhs)

Assigns the bitwise or of rhs and this.

Parameters

rhs – the batch involved in the operation.

Returns

a reference to this.

inline X &operator^=(const X &rhs)

Assigns the bitwise xor of rhs and this.

Parameters

rhs – the batch involved in the operation.

Returns

a reference to this.

Increment and decrement operators

inline X &operator++()

Pre-increment operator.

Returns

a reference to this.

inline X &operator++(int)

Post-increment operator.

Returns

a reference to this.

inline X &operator--()

Pre-decrement operator.

Returns

a reference to this.

inline X &operator--(int)

Post-decrement operator.

Returns

a reference to this.

Arithmetic operators

template<class X>
inline batch_type_t<X> operator-(const simd_base<X> &rhs)

Computes the opposite of the batch rhs.

Template Parameters

X – the actual type of batch.

Parameters

rhs – batch involved in the operation.

Returns

the opposite of rhs.

template<class X>
inline X operator+(const simd_batch<X> &rhs)

No-op on rhs.

Template Parameters

X – the actual type of batch.

Parameters

rhs – batch involved in the operation.

Returns

rhs.

template<class X, class Y>
batch_type_t<X> operator+(const simd_base<X> &lhs, const simd_base<Y> &rhs)

Computes the sum of the batches lhs and rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the addition.

  • rhs – batch involved in the addition.

Returns

the result of the addition.

template<class X>
batch_type_t<X> operator+(const simd_base<X> &lhs, const typename simd_batch_traits<X>::value_type &rhs)

Computes the sum of the batch lhs and the scalar rhs.

Equivalent to the sum of two batches where all the values of the second one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the addition.

  • rhs – scalar involved in the addition.

Returns

the result of the addition.

template<class X>
batch_type_t<X> operator+(const typename simd_batch_traits<X>::value_type &lhs, const simd_base<X> &rhs)

Computes the sum of the scalar lhs and the batch rhs.

Equivalent to the sum of two batches where all the values of the first one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – scalar involved in the addition.

  • rhs – batch involved in the addition.

Returns

the result of the addition.

template<class X>
inline batch_type_t<X> sadd(const simd_base<X> &lhs, const simd_base<X> &rhs)

Computes the saturate sum of the batch lhs and the batch rhs.

lhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the saturated addition.

  • rhs – batch involved in the saturated addition.

Returns

the result of the saturated addition.

template<class X>
inline batch_type_t<X> sadd(const typename simd_batch_traits<X>::value_type &lhs, const simd_base<X> &rhs)

Computes the saturate sum of the scalar lhs and the batch rhs.

Equivalent to the saturated sum of two batches where all the values of the first one are initialized to lhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – scalar involved in the saturated addition.

  • rhs – batch involved in the saturated addition.

Returns

the result of the saturated addition.

template<class X>
inline batch_type_t<X> sadd(const simd_base<X> &lhs, const typename simd_batch_traits<X>::value_type &rhs)

Computes the saturate sum of the batch lhs and the scalar rhs.

Equivalent to the saturated sum of two batches where all the values of the second one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the saturated addition.

  • rhs – scalar involved in the saturated addition.

Returns

the result of the saturated addition.

template<class X, class Y>
batch_type_t<X> operator-(const simd_base<X> &lhs, const simd_base<Y> &rhs)

Computes the difference of the batches lhs and rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the difference.

  • rhs – batch involved in the difference.

Returns

the result of the difference.

template<class X>
batch_type_t<X> operator-(const simd_base<X> &lhs, const typename simd_batch_traits<X>::value_type &rhs)

Computes the difference of the batch lhs and the scalar rhs.

Equivalent to the difference of two batches where all the values of the second one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the difference.

  • rhs – scalar involved in the difference.

Returns

the result of the difference.

template<class X>
batch_type_t<X> operator-(const typename simd_batch_traits<X>::value_type &lhs, const simd_base<X> &rhs)

Computes the difference of the scalar lhs and the batch rhs.

Equivalent to the difference of two batches where all the values of the first one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – scalar involved in the difference.

  • rhs – batch involved in the difference.

Returns

the result of the difference.

template<class X>
inline batch_type_t<X> ssub(const simd_base<X> &lhs, const simd_base<X> &rhs)

Computes the saturate difference of the batch lhs and the batch rhs.

lhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the saturated difference.

  • rhs – batch involved in the saturated difference.

Returns

the result of the saturated difference.

template<class X>
inline batch_type_t<X> ssub(const typename simd_batch_traits<X>::value_type &lhs, const simd_base<X> &rhs)

Computes the saturate difference of the scalar lhs and the batch rhs.

Equivalent to the saturated sum of two batches where all the values of the first one are initialized to lhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – scalar involved in the saturated difference.

  • rhs – batch involved in the saturated difference.

Returns

the result of the saturated difference.

template<class X>
inline batch_type_t<X> ssub(const simd_base<X> &lhs, const typename simd_batch_traits<X>::value_type &rhs)

Computes the saturate difference of the batch lhs and the scalar rhs.

Equivalent to the saturated difference of two batches where all the values of the second one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the saturated difference.

  • rhs – scalar involved in the saturated difference.

Returns

the result of the saturated difference.

template<class X, class Y>
batch_type_t<X> operator*(const simd_base<X> &lhs, const simd_base<Y> &rhs)

Computes the product of the batches lhs and rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the product.

  • rhs – batch involved in the product.

Returns

the result of the product.

template<class X>
batch_type_t<X> operator*(const simd_base<X> &lhs, const typename simd_batch_traits<X>::value_type &rhs)

Computes the product of the batch lhs and the scalar rhs.

Equivalent to the product of two batches where all the values of the second one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the product.

  • rhs – scalar involved in the product.

Returns

the result of the product.

template<class X>
batch_type_t<X> operator*(const typename simd_batch_traits<X>::value_type &lhs, const simd_base<X> &rhs)

Computes the product of the scalar lhs and the batch rhs.

Equivalent to the difference of two batches where all the values of the first one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – scalar involved in the product.

  • rhs – batch involved in the product.

Returns

the result of the product.

template<class X, class Y>
batch_type_t<X> operator/(const simd_base<X> &lhs, const simd_base<Y> &rhs)

Computes the division of the batch lhs by the batch rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the division.

  • rhs – batch involved in the division.

Returns

the result of the division.

template<class X>
batch_type_t<X> operator/(const simd_base<X> &lhs, const typename simd_batch_traits<X>::value_type &rhs)

Computes the division of the batch lhs by the scalar rhs.

Equivalent to the division of two batches where all the values of the second one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the division.

  • rhs – scalar involved in the division.

Returns

the result of the division.

template<class X>
batch_type_t<X> operator/(const typename simd_batch_traits<X>::value_type &lhs, const simd_base<X> &rhs)

Computes the division of the scalar lhs and the batch rhs.

Equivalent to the difference of two batches where all the values of the first one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – scalar involved in the division.

  • rhs – batch involved in the division.

Returns

the result of the division.

template<class X, class Y>
batch_type_t<X> operator%(const simd_base<X> &lhs, const simd_base<Y> &rhs)

Computes the integer modulo of the batch lhs by the batch rhs.

Parameters
  • lhs – batch involved in the modulo.

  • rhs – batch involved in the modulo.

Returns

the result of the modulo.

template<class X>
batch_type_t<X> operator%(const simd_base<X> &lhs, const typename simd_batch_traits<X>::value_type &rhs)

Computes the integer modulo of the batch lhs by the scalar rhs.

Equivalent to the modulo of two batches where all the values of the second one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the modulo.

  • rhs – scalar involved in the modulo.

Returns

the result of the modulo.

template<class X>
batch_type_t<X> operator%(const typename simd_batch_traits<X>::value_type &lhs, const simd_base<X> &rhs)

Computes the integer modulo of the scalar lhs and the batch rhs.

Equivalent to the difference of two batches where all the values of the first one are initialized to rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – scalar involved in the modulo.

  • rhs – batch involved in the modulo.

Returns

the result of the modulo.

Comparison operators

template<class X>
simd_batch_traits<X>::batch_bool_type operator==(const simd_base<X> &lhs, const simd_base<X> &rhs)

Element-wise equality comparison of batches lhs and rhs.

Parameters
  • lhs – batch involved in the comparison.

  • rhs – batch involved in the comparison.

Returns

a boolean batch.

template<class X>
simd_batch_traits<X>::batch_bool_type operator!=(const simd_base<X> &lhs, const simd_base<X> &rhs)

Element-wise inequality comparison of batches lhs and rhs.

Parameters
  • lhs – batch involved in the comparison.

  • rhs – batch involved in the comparison.

Returns

a boolean batch.

template<class X>
simd_batch_traits<X>::batch_bool_type operator<(const simd_base<X> &lhs, const simd_base<X> &rhs)

Element-wise lesser than comparison of batches lhs and rhs.

Parameters
  • lhs – batch involved in the comparison.

  • rhs – batch involved in the comparison.

Returns

a boolean batch.

template<class X>
simd_batch_traits<X>::batch_bool_type operator<=(const simd_base<X> &lhs, const simd_base<X> &rhs)

Element-wise lesser or equal to comparison of batches lhs and rhs.

Parameters
  • lhs – batch involved in the comparison.

  • rhs – batch involved in the comparison.

Returns

a boolean batch.

template<class X>
simd_batch_traits<X>::batch_bool_type operator>(const simd_base<X> &lhs, const simd_base<X> &rhs)

Element-wise greater than comparison of batches lhs and rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the comparison.

  • rhs – batch involved in the comparison.

Returns

a boolean batch.

template<class X>
simd_batch_traits<X>::batch_bool_type operator>=(const simd_base<X> &lhs, const simd_base<X> &rhs)

Element-wise greater or equal comparison of batches lhs and rhs.

Template Parameters

X – the actual type of batch.

Parameters
  • lhs – batch involved in the comparison.

  • rhs – batch involved in the comparison.

Returns

a boolean batch.

Bitwise operators

template<class X, class Y>
inline batch_type_t<X> operator&(const simd_base<X> &lhs, const simd_base<Y> &rhs)

Computes the bitwise and of the batches lhs and rhs.

Parameters
  • lhs – batch involved in the operation.

  • rhs – batch involved in the operation.

Returns

the result of the bitwise and.

template<class X, class Y>
inline batch_type_t<X> operator|(const simd_base<X> &lhs, const simd_base<Y> &rhs)

Computes the bitwise or of the batches lhs and rhs.

Parameters
  • lhs – batch involved in the operation.

  • rhs – batch involved in the operation.

Returns

the result of the bitwise or.

template<class X, class Y>
inline batch_type_t<X> operator^(const simd_base<X> &lhs, const simd_base<Y> &rhs)

Computes the bitwise xor of the batches lhs and rhs.

Parameters
  • lhs – batch involved in the operation.

  • rhs – batch involved in the operation.

Returns

the result of the bitwise xor.

template<class X>
batch_type_t<X> operator~(const simd_base<X> &rhs)

Computes the bitwise not of the batches lhs and rhs.

Parameters

rhs – batch involved in the operation.

Returns

the result of the bitwise not.

template<class X>
inline batch_type_t<X> bitwise_andnot(const simd_batch<X> &lhs, const simd_batch<X> &rhs)

Computes the bitwise andnot of the batches lhs and rhs.

Parameters
  • lhs – batch involved in the operation.

  • rhs – batch involved in the operation.

Returns

the result of the bitwise andnot.

Reducers

template<class X>
inline simd_batch_traits<X>::value_type hadd(const simd_base<X> &rhs)

Adds all the scalars of the batch rhs.

Parameters

rhs – batch involved in the reduction

Returns

the result of the reduction.

template<class X>
enable_if_simd_t<X> haddp(const X *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 X>
inline batch_type_t<X> select(const typename simd_batch_traits<X>::batch_bool_type &cond, const simd_base<X> &a, const simd_base<X> &b)

Ternary operator for batches: selects values from the batches a or b depending on the boolean values in cond.

Equivalent to

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

Parameters
  • cond – batch condition.

  • a – batch values for truthy condition.

  • b – batch value for falsy condition.

Returns

the result of the selection.

template<class X, bool... Masks>
inline batch_type_t<X> select(const batch_bool_constant<typename simd_batch_traits<X>::value_type, Masks...> &cond, const simd_base<X> &a, const simd_base<X> &b)

Ternary operator for batches: selects values from the batches a or b 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] ? a[i] : b[i];

Parameters
  • cond – constant batch condition.

  • a – batch values for truthy condition.

  • b – batch value for falsy condition.

Returns

the result of the selection.

Other operators

Warning

doxygenfunction: Unable to resolve function “xsimd::operator!” with arguments (const simd_batch<X>&) in doxygen xml output for project “xsimd” from directory: ../xml. Potential matches:

- template<class X> X operator!(const simd_batch_bool<X> &rhs)
- template<class X> simd_batch_traits<X>::batch_bool_type operator!(const simd_base<X> &rhs)
template<class X>
inline std::ostream &xsimd::operator<<(std::ostream &out, const simd_batch<X> &rhs)

Insert the batch rhs into the stream out.

Template Parameters

X – the actual type of batch.

Parameters
  • out – the output stream.

  • rhs – the batch to output.

Returns

the output stream.