#ifndef vjxaugYoBtZu5XZVahcafy1l5XU #define vjxaugYoBtZu5XZVahcafy1l5XU #include #include #include "template_helpers.hpp" inline uint8_t bit_extract(void *base, uint8_t width, uint64_t id) { assert(width < 8); uint8_t off, mask, block, result, *addr; addr = ((uint8_t*) base) + (id * width / 8); off = (id % (8 / width)) * width; mask = (~((~0) << width)) << off; block = * addr; result = (block & mask) >> off; return result; } template inline void bit_insert(void *base, uint8_t width, uint64_t id, T rawValue) { assert(width < 8); uint8_t off, mask, block, result, *addr; uint8_t value(FORCE_CONV(uint8_t, rawValue)); addr = ((uint8_t*) base) + (id * width / 8); off = (id % (8 / width)) * width; mask = (~((~0) << width)) << off; block = * addr; result = (block & (~mask)) | ((value << off) & mask); // mask also value, in case it is larger than allowed *addr = result; } #endif // vjxaugYoBtZu5XZVahcafy1l5XU