blob: 4b773cf66a9cc04a2606d6c3e15f1c5ec8230aa9 (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#ifndef TRAY_UTIL_H_
#define TRAY_UTIL_H_
#include <stdint.h>
#define __stringify(x) #x
#define stringify(x) __stringify(x)
#define min(a, b) ({ \
__typeof__(a) __a = (a); \
__typeof__(b) __b = (b); \
__a < __b ? __a : __b; \
})
#define max(a, b) ({ \
__typeof__(a) __a = (a); \
__typeof__(b) __b = (b); \
__a > __b ? __a : __b; \
})
#define clamp(v, mi, ma) max(min(v, ma), mi)
#define round_up(n, s) ((((n) + (s) - 1) / (s)) * (s))
#define div_round_up(x, d) ({ \
__typeof__(x) __x = (x); \
__typeof__(d) __d = (d); \
(__x + __d - 1) / __d; \
})
#define div_round(x, d) ({ \
__typeof__(x) __x = (x); \
__typeof__(d) __d = (d); \
(__x + (__d / 2)) / __d; \
})
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define compiler_barrier() __asm__ __volatile__("" : : : "memory")
#define ALIGN(x) __attribute__((__aligned__(x)))
#define ALIGN_MAX ALIGN(__BIGGEST_ALIGNMENT__)
void msleep(unsigned int msecs);
#endif /* TRAY_UTIL_H_ */
|