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