Derive-C
Loading...
Searching...
No Matches
core.h
Go to the documentation of this file.
1#pragma once
2#include <stdlib.h>
3
4#define NAME_EXPANDED(pre, post) pre##_##post
5#define NAME(pre, post) NAME_EXPANDED(pre, post)
6
7#ifndef NDEBUG
8#define DEBUG_UNUSED(ident) ident __attribute__((unused))
9#else
10#define DEBUG_UNUSED(ident)
11#endif
12
13#define UNUSED(ident) ident __attribute__((unused))
14
15#define LIKELY(x) __builtin_expect(!!(x), 1)
16
17#define EXPAND(...) __VA_ARGS__
18
19#ifdef __cplusplus
20struct gdb_marker {
21 char UNUSED(_dummy_cpp_object_size_compatibility);
22};
23#else
24typedef struct {
26#endif
27
28static inline size_t next_power_of_2(size_t x) {
29 if (x == 0)
30 return 1;
31 x--;
32 x |= x >> 1;
33 x |= x >> 2;
34 x |= x >> 4;
35 x |= x >> 8;
36 x |= x >> 16;
37#if SIZE_MAX > 0xFFFFFFFF
38 x |= x >> 32; // For 64-bit platforms
39#endif
40 return x + 1;
41}
42
43#define FORCE_INLINE inline __attribute__((always_inline))
#define UNUSED(ident)
Definition core.h:13
static size_t next_power_of_2(size_t x)
Definition core.h:28