avx::UShort256¶
-
class UShort256¶
Class providing vectorized version of
unsigned short
. Can hold 16 individualunsigned short
values. Provides arithmetic and bitwise operators. Provides comparison operators == !=.Public Types
-
using storedType = unsigned short¶
Type that is stored inside vector.
Public Functions
-
inline UShort256() noexcept¶
Default constructor. Sets zero to whole vector.
-
inline UShort256(const UShort256 &init) noexcept¶
Initializes vector with value from other vector.
- Parameters:
init – Object which value will be copied.
-
inline UShort256(const __m256i &init) noexcept¶
Initializes vector but using
__m256i
type.- Parameters:
init – Raw value to be set.
-
inline UShort256(const std::array<unsigned short, 16> &init) noexcept¶
Initialize vector with values read from an array.
- Parameters:
init – Array from which values will be copied.
-
inline UShort256(std::initializer_list<unsigned short> init)¶
-
inline explicit UShort256(const unsigned short *addr)¶
Initialize vector with values using pointer.
- Parameters:
addr – A valid address containing at least 16
unsigned short
numbers.- Throws:
std::invalid_argument – If in debug mode and
addr
isnullptr
. Otherwise ifaddr
is nullptr vector will be filled with 0’s.
-
inline explicit UShort256(const unsigned short b) noexcept¶
Initializes all vector fields with single value.
- Parameters:
b – A literal value to be set.
- inline void load (const unsigned short *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
isnullptr
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
isnullptr
. In Release builds this method never throws (fornullptr
method will have no effect).
-
inline void save(std::array<unsigned short, 16> &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 (unsigned short *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 (16x
unsigned short
).- Throws:
std::invalid_argument – If in Debug mode and
pDest
isnullptr
. In Release builds this method never throws (fornullptr
method will have no effect).
- inline void saveAligned (unsigned short *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 (16x
unsigned short
).- Throws:
std::invalid_argument – If in Debug mode and
pDest
isnullptr
. In Release builds this method never throws (fornullptr
method will have no effect).
-
inline __m256i get() const noexcept¶
Get the internal vector value.
- Returns:
The value of
__m256i
vector.
-
inline void set(const __m256i value) noexcept¶
Set the internal vector value.
- Parameters:
value – New value to be set.
-
inline unsigned short operator[](const unsigned int &index) const¶
Indexing operator.
- Parameters:
index – Position of desired element between 0 and 15.
- Throws:
std::out_of_range – If index is not within the correct range.
- Returns:
Value of underlying element.
-
inline bool operator==(const UShort256 &bV) const noexcept¶
Compares with second vector for equality.
- Parameters:
bV – Object to compare.
- Returns:
true
if all elements are equal orfalse
if not.
-
inline bool operator==(const unsigned short &b) const noexcept¶
Compares with value for equality.
- Parameters:
b – Value to compare.
- Returns:
true
if all elements are equal to passed valuefalse
if not.
-
inline bool operator!=(const UShort256 &bV) const noexcept¶
Compares with second vector for inequality.
- Parameters:
bV – Object to compare.
- Returns:
true
if any alement is not equal to corresponding element inbV
otherwisefalse
.
-
inline bool operator!=(const unsigned short &b) const noexcept¶
Compares with value for inequality.
- Parameters:
b – Value
- Returns:
true
if any alement is not equal to corresponding element inbV
otherwisefalse
.
-
inline UShort256 operator/(const UShort256 &bV) const noexcept¶
Performs an integer division.
NOTE: Value is first casted to
int
and then tofloat
and inverse to return integer result which has not been yet tested for performance.- Parameters:
bV – Divisors vector.
- Returns:
Result of integer division with truncation.
-
inline UShort256 operator/(const unsigned short &b) const noexcept¶
Performs an integer division.
NOTE: Value is first casted to
int
and then tofloat
and inverse to return integer result which has not been yet tested for performance.- Parameters:
bV – Divisor value.
- Returns:
Result of integer division with truncation.
-
inline UShort256 operator%(const UShort256 &bV) const noexcept¶
Performs a modulo operation. The implemented algorithm works as shown below:
mod(a, b) -> a - b * (a / b) where
/
is an integer division. Due to SIMD (AVX2) limitations values are casted to two float vectors and then divided.NOTE: Analogously as in
/
and/=
operators values are casted before performing a division.- Parameters:
bV – Divisor.
- Returns:
Modulo result.
-
inline UShort256 operator%(const unsigned short &b) noexcept¶
Performs a modulo operation. The implemented algorithm works as shown below:
mod(a, b) -> a - b * (a / b) where
/
is an integer division. Due to SIMD (AVX2) limitations values are casted to two float vectors and then divided.NOTE: Analogously as in
/
and/=
operators values are casted before performing a division.- Parameters:
bV – Divisor.
- Returns:
Modulo result.
-
inline UShort256 &operator%=(const UShort256 &bV) noexcept¶
Performs a modulo operation. The implemented algorithm works as shown below:
mod(a, b) -> a - b * (a / b) where
/
is an integer division. Due to SIMD (AVX2) limitations values are casted to two float vectors and then divided.NOTE: Analogously as in
/
and/=
operators values are casted before performing a division.- Parameters:
bV – Divisor.
- Returns:
Reference to modified object.
-
inline UShort256 &operator%=(const unsigned short &b) noexcept¶
Performs a modulo operation. The implemented algorithm works as shown below:
mod(a, b) -> a - b * (a / b) where
/
is an integer division. Due to SIMD (AVX2) limitations values are casted to two float vectors and then divided.NOTE: Analogously as in
/
and/=
operators values are casted before performing a division.- Parameters:
bV – Divisor.
- Returns:
Reference to modified object.
-
inline UShort256 operator<<(const UShort256 &bV) const noexcept¶
Performs left bitwise shift of corresponding values.
- Parameters:
bV – Second vector that specifies number of bits to shift (for each 16-bit value).
- Returns:
New value of
v
shifted by number of bits specfied inbV
.
-
inline std::string str() const noexcept¶
Public Static Attributes
-
static const int size = 16¶
Number of individual values stored by object. This value can be used to iterate over elements.
-
using storedType = unsigned short¶