From 3f36aca66e1ac6c872300059e8db691a473614d4 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sun, 8 Nov 2026 08:23:31 +0300 Subject: publish --- src/utils.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/utils.h (limited to 'src/utils.h') diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..aec95d2 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,48 @@ +#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 -- cgit v1.3.1