summaryrefslogtreecommitdiff
path: root/src/util.h
blob: 569054b52aa9be0eff2152165a43be4064e76faa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef IMB3_UTIL_H
#define IMB3_UTIL_H

#include <stdbool.h>
#include <stdnoreturn.h>

static inline bool likely(bool cond) { return __builtin_expect(cond, true); }
static inline bool unlikely(bool cond) { return __builtin_expect(cond, false); }

#ifndef NDEBUG
noreturn void assume__failed(const char *file, int line, const char *expr);
#endif // NDEBUG

static inline void assume__impl(bool cond, const char *file, int line,
                                const char *expr) {
#ifndef NDEBUG
  if (unlikely(!cond))
    assume__failed(file, line, expr);
#endif // NDEBUG
  if (unlikely(!cond))
    __builtin_unreachable();
}

#define assume(COND) assume__impl(COND, __FILE__, __LINE__, #COND)

__attribute__((format(printf, 3, 4))) noreturn void
todo__impl(const char *file, int line, const char *fmt, ...);

#define todo(...) todo__impl(__FILE__, __LINE__, __VA_ARGS__)

#endif // IMB3_UTIL_H