#ifndef INCLUDED_UTILS_H #define INCLUDED_UTILS_H #include #include #include #include #define UNUSED(X) ((void) (X)) #define UNREACHABLE() ASSERT (!"reached the unreachable...") // #define TODO(STR) fprintf (stderr, "%s:%d: warning: TODO "STR"\n", __FILE__, __LINE__) #define TODO(...) #define ASSERT assert #define REALLOC realloc #define FREE free #define ARRAY_LEN(array) (sizeof (array)/sizeof (*array)) #define ARRAY_GET(array, index) \ (ASSERT(index >= 0), ASSERT(index < ARRAY_LEN(array)), array[index]) // inline void // setbit (uint8_t *bytes, size_t index, bool value) // { // uint8_t *byte = &bytes[index >> 3]; // uint8_t offset = index & ((1 << 3) - 1); // uint8_t mask = ~(1 << offset); // *byte = *byte & mask | value << offset; // } static inline void setbit (uint8_t *bytes, size_t index) { uint8_t *byte = &bytes[index/8]; uint8_t offset = index & 7; *byte |= 1 << offset; } static inline bool getbit (uint8_t *bytes, size_t index) { uint8_t byte = bytes[index/8]; uint8_t offset = index & 7; uint8_t mask = 1 << offset; return (byte & mask) >> offset; } #endif