Derive-C
Loading...
Searching...
No Matches
helpers.h File Reference
#include <derive-c/core/panic.h>
#include <stdlib.h>
Include dependency graph for helpers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  gdb_marker

Macros

#define NS_EXPANDED(pre, post)
#define NS(pre, post)
#define PRIVATE(name)
#define DEBUG_UNUSED(ident)
#define UNUSED(ident)
#define LIKELY(x)
#define EXPAND(...)
#define FORCE_INLINE   inline __attribute__((always_inline))

Functions

static size_t next_power_of_2 (size_t x)
static bool is_power_of_2 (size_t x)
static size_t modulus_power_of_2_capacity (size_t index, size_t capacity)

Macro Definition Documentation

◆ DEBUG_UNUSED

#define DEBUG_UNUSED ( ident)
Value:
ident __attribute__((unused))

Definition at line 11 of file helpers.h.

◆ EXPAND

#define EXPAND ( ...)
Value:
__VA_ARGS__

Definition at line 20 of file helpers.h.

◆ FORCE_INLINE

#define FORCE_INLINE   inline __attribute__((always_inline))

Definition at line 54 of file helpers.h.

◆ LIKELY

#define LIKELY ( x)
Value:
__builtin_expect(!!(x), 1)

Definition at line 18 of file helpers.h.

◆ NS

#define NS ( pre,
post )
Value:
NS_EXPANDED(pre, post)
#define NS_EXPANDED(pre, post)
Definition helpers.h:5

Definition at line 6 of file helpers.h.

◆ NS_EXPANDED

#define NS_EXPANDED ( pre,
post )
Value:
pre##_##post

Definition at line 5 of file helpers.h.

◆ PRIVATE

#define PRIVATE ( name)
Value:
NS(__private, name)
#define NS(pre, post)
Definition helpers.h:6

Definition at line 8 of file helpers.h.

◆ UNUSED

#define UNUSED ( ident)
Value:
ident __attribute__((unused))

Definition at line 16 of file helpers.h.

Function Documentation

◆ is_power_of_2()

bool is_power_of_2 ( size_t x)
inlinestatic

Definition at line 46 of file helpers.h.

46{ return x != 0 && (x & (x - 1)) == 0; }
Here is the caller graph for this function:

◆ modulus_power_of_2_capacity()

size_t modulus_power_of_2_capacity ( size_t index,
size_t capacity )
inlinestatic

Definition at line 48 of file helpers.h.

48 {
50 // NOTE: If we know capacity is a power of 2, we can reduce the cost of 'index + 1 % capacity'
51 return index & (capacity - 1);
52}
static bool is_power_of_2(size_t x)
Definition helpers.h:46
#define DEBUG_ASSERT(expr)
Definition panic.h:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ next_power_of_2()

size_t next_power_of_2 ( size_t x)
inlinestatic

Definition at line 31 of file helpers.h.

31 {
32 if (x == 0)
33 return 1;
34 x--;
35 x |= x >> 1;
36 x |= x >> 2;
37 x |= x >> 4;
38 x |= x >> 8;
39 x |= x >> 16;
40#if SIZE_MAX > 0xFFFFFFFF
41 x |= x >> 32; // For 64-bit platforms
42#endif
43 return x + 1;
44}
Here is the caller graph for this function: