gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
defs.h
Go to the documentation of this file.
1
4#pragma once
5
6#ifdef USE_GETTEXT
7#include <libintl.h>
8#include <locale.h>
9#include <stdio.h>
10#define _(String) dgettext(GWION_PACKAGE, String)
11#else
12#define _(String) (String)
13#endif
14
15#define container_of(ptr, type, member) \
16 ((type *)((char *)(ptr)-offsetof(type, member)))
17
18#define ANN __attribute__((nonnull))
19#define ANN2(...) __attribute__((nonnull(__VA_ARGS__)))
20//#define ANEW __attribute__((returns_nonnull,malloc))
21#define ANEW __attribute__((malloc))
22#define NUSED __attribute__((unused))
23
24#ifdef __GNUC__
25#ifdef __clang__
26#define LOOP_OPTIM
27#define CC_OPTIM(a)
28#else
29#define LOOP_OPTIM _Pragma("GCC ivdep")
30#define CC_OPTIM(a) __attribute__((optimize(#a)))
31#endif
32#else
33#define LOOP_OPTIM
34#endif
35
36// maybe later enclose in ifdef
37#define likely(x) __builtin_expect(!!(x), 1)
38#define unlikely(x) __builtin_expect(!!(x), 0)
39
40#define CHECK_B(f) \
41 do { \
42 if (!f) return false; \
43 } while (0)
44#define CHECK_O(f) \
45 do { \
46 if (!f) return NULL; \
47 } while (0)
48
49#define DECL_B(decl, f, exp) \
50 decl f exp; \
51 if (!f) return false
52#define DECL_O(decl, f, exp) \
53 decl f exp; \
54 if (!f) return NULL
55
56#include <stdio.h>
57#include <math.h>
58#include <assert.h>
59#include <string.h>
60#include "gwcommon.h"
61
62typedef unsigned int uint;
63
64static inline m_uint num_digit(const m_uint i) {
65 return i ? (m_uint)floor(log10((float)i) + 1) : 1;
66}
67
68static inline m_uint round2szint(const m_uint i) {
69 return ((i + (SZ_INT - 1)) & ~(SZ_INT - 1));
70}
static m_uint round2szint(const m_uint i)
Definition defs.h:68
static m_uint num_digit(const m_uint i)
Definition defs.h:64
unsigned int uint
Definition defs.h:62
uintptr_t m_uint
Definition gwcommon.h:12
#define SZ_INT
Definition gwcommon.h:19