avx::Float256

class Float256

Class providing vectorized version of float. Can hold 8 individual float values. Provides arithmetic operators.

  • Provides comparison operators == != (optimization on the way).

Public Types

using storedType = float

Type that is stored inside vector.

Public Functions

inline Float256() noexcept

Default constructor. Initializes vector with zeros.

inline Float256(const Float256 &init) noexcept

Copy constructor. Initializes vector from another Float256 vector.

Parameters:

init – Another Float256 vector to copy from.

inline Float256(const float value) noexcept

Initializes vector with const value. Each cell will be set with value of value.

Parameters:

value – Value to be set.

inline Float256(const __m256 init) noexcept

Initializes vector from __m256 value.

Parameters:

init – Value of type __m256 to initialize the vector.

inline Float256(const std::array<float, 8> &init) noexcept

Initializes vector from std::array of 8 float values.

Parameters:

init – Array of 8 float values to initialize the vector.

inline Float256(std::initializer_list<float> init) noexcept

Initializes vector from initializer_list of float values. If the list contains fewer than 8 elements, remaining elements are set to zero. If the list contains more than 8 elements, only the first 8 are used.

Parameters:

init – Initializer list of float values.

inline Float256(const float *pSrc)

Initializes vector by loading data from memory (via _mm256_loadu_ps).

Parameters:

pSrc – Pointer to memory of at least 32 bytes (8 floats).

inline const __m256 get() const noexcept

Returns the internal __m256 value stored by the object.

Returns:

The __m256 value.

inline void set(__m256 val) noexcept

Sets the internal __m256 value stored by the object.

Parameters:

val – New value of type __m256.

inline void load (const float *pSrc) N_THROW_REL

Loads data from memory into vector (memory should be of size of at least 32 bytes). Memory doesn’t need to be aligned to any specific boundary. If sP is nullptr this method has no effect.

Parameters:

pSrc – Pointer to memory from which to load data.

Throws:

std::invalid_argument – If in Debug mode and pSrc is nullptr. In Release builds this method never throws (for nullptr method will have no effect).

inline void save(std::array<float, 8> &dest) const noexcept

Saves data to destination in memory.

Parameters:

dest – Reference to the list to which vector will be saved. Array doesn’t need to be aligned to any specific boundary.

inline void save (float *pDest) const N_THROW_REL

Saves data to destination in memory. The memory doesn’t have to be aligned to any specific boundary.

See https://en.cppreference.com/w/cpp/memory/c/aligned_alloc for more details.

Parameters:

pDest – A valid pointer to a memory of at least 32 bytes (8x float).

Throws:

std::invalid_argument – If in Debug mode and pDest is nullptr. In Release builds this method never throws (for nullptr method will have no effect).

inline void saveAligned (float *pDest) const N_THROW_REL

Saves data to destination in memory. The memory must be aligned at 32-byte boundary.

See https://en.cppreference.com/w/cpp/memory/c/aligned_alloc for more details.

Parameters:

pDest – A valid pointer to a memory of at least 32 bytes (8x float).

Throws:

std::invalid_argument – If in Debug mode and pDest is nullptr. In Release builds this method never throws (for nullptr method will have no effect).

inline bool operator==(const Float256 &bV)

Compares with second vector for equality. This method is secured to return true when comparing 0.0f with -0.0f.

Parameters:

bV – Second vector to compare.

Returns:

true if all fields in both vectors have the same value, false otherwise.

inline bool operator==(const float b)

Compares with value for equality. This method is secured to return true when comparing 0.0f with -0.0f.

Parameters:

b – Value to compare with.

Returns:

true if all fields in vectors have the same value as b, false otherwise.

inline bool operator!=(const Float256 &bV)

Compares with second vector for equality. This method is secured to return true when comparing 0.0f with -0.0f.

Parameters:

bV – Second vector to compare.

Returns:

true if ANY field in one vector has different value than one in scond vector, false if vector are equal.

inline bool operator!=(const float b)

Compares with second vector for equality. This method is secured to return true when comparing 0.0f with -0.0f.

Parameters:

b – Value to compare with.

Returns:

true if ANY field in vector has different value than passed value, false if vector are equal.

inline Float256 operator+(const Float256 &bV) const noexcept
inline Float256 operator+(const float b) const
inline Float256 &operator+=(const Float256 &bV)
inline Float256 &operator+=(const float b)
inline Float256 operator-(const Float256 &bV) const
inline Float256 operator-(const float b) const
inline Float256 &operator-=(const Float256 &bV)
inline Float256 &operator-=(const float b)
inline Float256 operator*(const Float256 &bV) const
inline Float256 operator*(const float b) const
inline Float256 &operator*=(const Float256 &bV)
inline Float256 &operator*=(const float b)
inline Float256 operator/(const Float256 &bV) const
inline Float256 operator/(const float b) const
inline Float256 &operator/=(const Float256 &bV)
inline Float256 &operator/=(const float b)
inline float operator[](const unsigned int index) const

Indexing operator. Does not support value assignment through this method (e.g. aV[0] = 1 won’t work).

Parameters:

index – Position of desired element between 0 and 7.

Throws:

std::out_of_range – If index is not within the correct range and build type is debug will be thrown. Otherwise bitwise AND will prevent index to be out of range. Side effect is that only 3 LSBs are used from index.

Returns:

Value of underlying element.

inline std::string str() const noexcept

Returns string representation of vector. Printing will result in Float256(<vector_values>) eg. Float256(1.000000, 2.000000, 3.000000, 4.000000, 5.000000, 6.000000, 7.000000, 8.000000)

Returns:

String representation of underlying vector.

Public Static Attributes

static int size = 8

Number of individual values stored by object. This value can be used to iterate over elements.