avx::Char256¶
Documentation for avx::Char256 class.
Note
Functions marked as inline are part of char256.hpp file.
-
class Char256¶
Class representing vectorized version of
char
. It can hold 32 individualchar
variables. Provides support for arithmetic and bitwise operators.str()
method returns stored data as string. Supports printing directly to stream (cout). Class representing vectorized version ofchar
. It can hold 32 individualchar
variables. Provides support for arithmetic and bitwise operators.str()
method returns stored data as string. Supports printing directly to stream (cout).Public Types
-
using storedType = char¶
Type that is stored inside vector.
Public Functions
-
inline Char256() noexcept¶
Creates object and fills with 0.
-
inline Char256(const char init) noexcept¶
Initializes object with provided value.
- Parameters:
init – Value to be broadcasted to vector content.
-
inline Char256(const __m256i &init) noexcept¶
Initializes object with
__m256i
vector.- Parameters:
init – Vector from which values will be copied.
-
inline Char256(const Char256 &init) noexcept¶
Initializes object with another object.
- Parameters:
init – Object which content will be copied.
-
inline explicit Char256(const char *pSrc)¶
Initializes object with first 32 bytes of data stored under
addr
. Data does not need to be aligned to a 32 byte boundary.- Parameters:
pSrc – Memory holding data (minimum 32 bytes).
- Throws:
If – used in debug mode if
addr
isnullptr
thenstd::invalid_argument
will be thrown. Otherwise ifnullptr
is passed it will initialize vector with 0’s.
-
inline Char256(const char *pSrc, unsigned int count)¶
Initializes object using first
count
bytes frompSrc
or 32 bytes ifcount
> 32. Data does not need to be aligned to 32 byte boundary.- Parameters:
pSrc – Valid pointer from which data will be loaded.
count – Number of bytes held by
pSrc
. For less than 32 remaining bytes will be filled with 0’s. Otherwise first 32 bytes will be used.
- Throws:
std::invalid_argument – If in debug mode and
pSrc
is nullptr. If not in debug mode andnullptr
is passed, then vector will be loaded with 0’s.
-
inline Char256(const std::string &init) noexcept¶
Initializes with first 32 bytes read from string. If
init
is less than 32 bytes long missing values will be set to 0.- Parameters:
init – String containing initial data.
-
inline Char256(const std::array<char, 32> &init) noexcept¶
Initializes object with array of 32 bytes.
- Parameters:
init – Array containing initial data.
-
inline Char256(std::initializer_list<char> init)¶
Initializes object using initializer list. The number of elements in list is not limited but only a maximum of first 32 will be used. If size of list is less than 32 bytes missing values will be set to 0.
- Parameters:
init – Initializer list of values to assign.
- inline void load (const char *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<char, 32> &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 (char *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 (32x
char
).- 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 (char *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 (32x
char
).- 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 char operator[](const unsigned int &index) const¶
Indexing operator. Returns element under given
index
. 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 31.
- Throws:
If – index is not within the correct range and build type is debug
std::out_of_range
will be thrown. Otherwise bitwise AND will prevent index to be out of range. Side effect is that only 5 LSBs are used fromindex
.- Returns:
Value of underlying element.
-
inline bool operator==(const Char256 &bV) const noexcept¶
Compare with other vector for equality.
- Parameters:
bV – Second object to compare.
- Returns:
If ALL values are the same then it will return
true
, otherwisefalse
.
-
inline bool operator==(const char b) const noexcept¶
Compare if ALL values in vector are the same as provided in
b
.- Parameters:
b – Scalar value to compare with.
- Returns:
If ALL values in vector are equal to
b
then will returntrue
, otherwisefalse
will be returned.
-
inline bool operator!=(const Char256 &bV) const noexcept¶
Compares vectors for inequality.
- Parameters:
bV – Vector to compare with.
- Returns:
If ANY value doesn’t match then
true
will be returned. Otherwise will returnfalse
.
-
inline bool operator!=(const char b) const noexcept¶
Compares vector with scalar for inequality.
- Parameters:
b – Scalar to compare with.
- Returns:
If ANY value doesn’t match with
b
thentrue
will be returned. Otherwise will returnfalse
.
-
inline Char256 operator+(const Char256 &bV) const noexcept¶
Adds two vectors. Simple call to
_mm256_add_epi8
.- Parameters:
bV – Vector to add.
- Returns:
New object being a result of addition of vectors.
-
inline Char256 operator+(const char &b) const noexcept¶
Adds a scalar to vector. Similar to one using Char256 but creates intermediate vector filled with value of
b
.- Parameters:
b – Scalar to add.
- Returns:
New object being a result of adding value of
b
to vector.
-
inline Char256 &operator+=(const Char256 &bV) noexcept¶
Adds second vector and returns reference to existing vector.
- Parameters:
bV – Vector to add.
- Returns:
Reference to the same object after performing addition (
*this
).
-
inline Char256 &operator+=(const char &b) noexcept¶
Adds a scalar to vector and returns reference to existing vector.
- Parameters:
b – Scalar to add.
- Returns:
Reference to the same object after performing addition (
*this
).
-
inline std::string str() const noexcept¶
A string representation of internal vector contents. All 32 stored values will be printed out.
- Returns:
String in the following format (for default constructor): “Char256(0, 0, […], 0)”
-
inline std::string toString() const noexcept¶
Creates a string from internal vector. This function is safe even if data is not null-terminated.
- Returns:
String filled with contents of internal vector.
Public Static Attributes
-
static int size = 32¶
Number of individual values stored by object. This value can be used to iterate over elements.
-
using storedType = char¶