Status & Roadmap
Authors & License
Funding U++
Search on this site

SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

Low Level Data Functions


Some of these functions extend or supplement classical C mem* functions to wider datatypes or eventually specific condition, using heavy inlining and SIMD code to optimize performance. Other provide endianness support and/or raw access to memory (SwapEndian/Poke/Peek).


Function List


void memset8(void *p, byte data, size_t count)

void memset16(void *p, word data, size_t count)

void memset32(void *p, dword data, size_t count)

void memset64(void *p, qword data, size_t count)

void memset128(void *t, m128 data, size_t count)

Similar functionality to memset for 8, 16, 32, 64, 128 bit: sets the value of count elements starting at p. memset8 might be faster for small datablocks, other functions should be faster than the manual implementation.



void memcpy8(void *p, const void *q, size_t count)

void memcpy16(void *p, const void *q, size_t count)

void memcpy32(void *p, const void *q, size_t count)

void memcpy64(void *p, const void *q, size_t count)

void memcpy128(void *p, const void *q, size_t count)

Similar functionality to memcpy for 8, 16, 32, 64, 128 bit: copies the memory block of count elements from q to p. memset8 might be faster for small datablocks, other functions should be faster than the manual implementation.



template <class Tvoid memcpy_t(void *t, const T *s, size_t count)

This function selects appropriate memcpy* function based on sizeof(T) to copy count of T elements. Useful for template algorithms.



bool inline_memeq8_aligned(const void *p, const void *q, size_t count)

bool inline_memeq16_aligned(const void *p, const void *q, size_t count)

bool inline_memeq32_aligned(const void *p, const void *q, size_t count)

bool inline_memeq64_aligned(const void *p, const void *q, size_t count)

bool inline_memeq128_aligned(const void *t, const void *s, size_t count)

These functions compare the memory blocks at p and q of count 8, 16, 32, 64, 128 bit elements and return true if they are equal. Memory must be correctly aligned for the element size. These functions should be faster than memcmp for small blocks.



bool memeq8(const void *p, const void *q, size_t count)

bool memeq16(const void *p, const void *q, size_t count)

bool memeq32(const void *p, const void *q, size_t count)

bool memeq64(const void *p, const void *q, size_t count)

bool memeq128(const void *p, const void *q, size_t count)

Similar to memcmp(p, q, count * size) == 0 and probably about the same speed. Provided mostly for completeness.



hash_t memhash(const void *ptr, size_t size)

Computes a non-cryptographic hash of memory block.



dword FoldHash(qword h)

This functions "hashes all bits together". One purpose is to bring the entropy of higher bits down so that the hash can be limited by masking, other purpose is to provide hash for integral numbers.



int SignificantBits(dword x)

int SignificantBits64(uint64 x)

Returns the number of bits required to store the value. E.g. for binary value 1010, this value is 4. For 0, the value is 0.



bool FitsInInt64(double x)

Returns true if x can be converted to int64 without loosing the precision.



int Peek16le(const void *ptr)

int Peek32le(const void *ptr)

int64 Peek64le(const void *ptr)

Reads little endian value from unaligned ptr.



void Poke16le(const void *ptr, int val)

void Poke32le(const void *ptr, int val)

void Poke64le(const void *ptr, int64 val)

Writes val to unaligned ptr as little endian.



int Peek16be(const void *ptr)

int Peek32be(const void *ptr)

int64 Peek64be(const void *ptr)

Reads big endian value from unaligned ptr.



void Poke16be(const void *ptr, int val)

void Poke32be(const void *ptr, int val)

void Poke64be(const void *ptr, int64 val)

Writes val to unaligned ptr as big endian.



word SwapEndian16(word v)

int16 SwapEndian16(int16 v)

dword SwapEndian32(dword v)

int SwapEndian32(int v)

uint64 SwapEndian64(uint64 v)

int64 SwapEndian64(int64 v)

Returns the v with swapped order of bytes.



void EndianSwap(word& v)

void EndianSwap(int16& v)

void EndianSwap(dword& v)

void EndianSwap(int& v)

void EndianSwap(int64& v)

void EndianSwap(uint64& v)

Swaps the order of bytes of v.


Do you want to contribute?