Contains common functions related to bitwise operations.
More...
#include "exceptions.hpp"
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
|
| __JAFFAR_COMMON_INLINE__ void | jaffarCommon::bitwise::bitcopy (void *dstBufferPtr, const size_t dstBufferSize, const size_t dstBufferOffset, const void *srcBufferPtr, const size_t srcBufferSize, const size_t srcBufferOffset, const size_t count, const size_t elementBitSize) |
| |
| __JAFFAR_COMMON_INLINE__ size_t | jaffarCommon::bitwise::getEncodingBitsForElementCount (const size_t elementCount) |
| |
| __JAFFAR_COMMON_INLINE__ size_t | jaffarCommon::bitwise::getByteStorageForBitCount (const size_t bitCount) |
| |
| __JAFFAR_COMMON_INLINE__ void | jaffarCommon::bitwise::setBitValue (void *dst, const size_t idx, const bool value) |
| |
| __JAFFAR_COMMON_INLINE__ bool | jaffarCommon::bitwise::getBitValue (const void *src, const size_t idx) |
| |
| __JAFFAR_COMMON_INLINE__ bool | jaffarCommon::bitwise::getBitFlag (const uint8_t value, const uint8_t idx) |
| |
|
| constexpr uint8_t | jaffarCommon::bitwise::bitMaskTable [8] = {0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000} |
| |
| constexpr uint8_t | jaffarCommon::bitwise::bitNotMaskTable [8] = {0b11111110, 0b11111101, 0b11111011, 0b11110111, 0b11101111, 0b11011111, 0b10111111, 0b01111111} |
| |
Contains common functions related to bitwise operations.
◆ bitcopy()
| __JAFFAR_COMMON_INLINE__ void jaffarCommon::bitwise::bitcopy |
( |
void * |
dstBufferPtr, |
|
|
const size_t |
dstBufferSize, |
|
|
const size_t |
dstBufferOffset, |
|
|
const void * |
srcBufferPtr, |
|
|
const size_t |
srcBufferSize, |
|
|
const size_t |
srcBufferOffset, |
|
|
const size_t |
count, |
|
|
const size_t |
elementBitSize |
|
) |
| |
This function copies a contiguous set of k elements of size n bits from a source buffer plus an offset s_off * n to a destination buffer plus an offset of d_off * n
- Parameters
-
| [out] | dstBufferPtr | The destination buffer |
| [in] | dstBufferSize | The size of the destination buffer (expressed in bytes). This is necessary to guard possible overflows before they happen |
| [in] | dstBufferOffset | The size of the destination buffer (expressed in elements) |
| [in] | srcBufferPtr | The source buffer |
| [in] | srcBufferSize | The size of the source buffer (expressed in bytes). This is necessary to guard possible overflows before they happen |
| [in] | srcBufferOffset | The size of the source buffer (expressed in elements) |
| [in] | count | The number of elements to copy |
| [in] | elementBitSize | The size of each element (expressed in bits) |
◆ getBitFlag()
| __JAFFAR_COMMON_INLINE__ bool jaffarCommon::bitwise::getBitFlag |
( |
const uint8_t |
value, |
|
|
const uint8_t |
idx |
|
) |
| |
Gets the value of a given bit inside an 8-bit word
- Parameters
-
| [in] | value | The 8-bit word |
| [in] | idx | Index (position) of the bit to get inside the value (only accepted values: 0-7) |
- Returns
- Whether the specified bit was true or false
◆ getBitValue()
| __JAFFAR_COMMON_INLINE__ bool jaffarCommon::bitwise::getBitValue |
( |
const void * |
src, |
|
|
const size_t |
idx |
|
) |
| |
Gets the value of a given bit inside a buffer of any size
- Parameters
-
| [in] | src | The buffer containing the bit to set |
| [in] | idx | Index (position) of the bit to get inside value |
- Returns
- Whether the specified bit was true or false
◆ getByteStorageForBitCount()
| __JAFFAR_COMMON_INLINE__ size_t jaffarCommon::bitwise::getByteStorageForBitCount |
( |
const size_t |
bitCount | ) |
|
Calculates how many bytes if needed to store a certain amount of bits
- Parameters
-
| [in] | bitCount | The number of bits to store |
- Returns
- The bytes required to store them
◆ getEncodingBitsForElementCount()
| __JAFFAR_COMMON_INLINE__ size_t jaffarCommon::bitwise::getEncodingBitsForElementCount |
( |
const size_t |
elementCount | ) |
|
Calculates the number of bits necessary encode a number of distinct elements.
- Parameters
-
| [in] | elementCount | The number of elements to encode |
- Returns
- The number of bits required. Examples: (Element Count, Bits Required) => (0,0), (1,1), (2,1), (3,2), (4,2), (5,3), (6,3), (7,3), (8,3), (9,4)
- Note
- A single element is given 1 bit (not 0): downstream storage (e.g. bit-packed buffers and bitcopy) requires a positive element bit size.
◆ setBitValue()
| __JAFFAR_COMMON_INLINE__ void jaffarCommon::bitwise::setBitValue |
( |
void * |
dst, |
|
|
const size_t |
idx, |
|
|
const bool |
value |
|
) |
| |
Sets to value for a given bit inside a buffer of any size
- Parameters
-
| [out] | dst | The buffer containing the bit to set |
| [in] | idx | Index (position) of the bit to set inside the buffer |
| [in] | value | Value to set (true or false) |
◆ bitMaskTable
| constexpr uint8_t jaffarCommon::bitwise::bitMaskTable[8] = {0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000} |
|
inlineconstexpr |
A reference table that maps a given bit index to its corresponding bit map (one in the indicates position, zeros in all other bits)
◆ bitNotMaskTable
| constexpr uint8_t jaffarCommon::bitwise::bitNotMaskTable[8] = {0b11111110, 0b11111101, 0b11111011, 0b11110111, 0b11101111, 0b11011111, 0b10111111, 0b01111111} |
|
inlineconstexpr |
A reference table that maps a given bit index to its corresponding negated bit map (zero in the indicates position, ones in all other bits)