npv:osd:ascii only mode for the timer
[nyanmp.git] / npv / c_fixing.h
blob70e719ce796037a2d773ec1e578003ea3008ad01
1 #ifndef NPV_C_FIXING_H
2 #define NPV_C_FIXING_H
3 /*
4 * code protected with a GNU affero GPLv3 license
5 * copyright (C) 2020 Sylvain BERTRAND
6 */
7 #include <stdint.h>
8 #include <limits.h>
9 #if __GNUC__ > 4
10 #include <stdatomic.h>
11 #endif
12 #define u8 uint8_t
13 #define U8_MAX 0xff
14 #define s8 int8_t
15 #define u16 uint16_t
16 #define U16_MAX 0xffff
17 #define s16 int16_t
18 #define u32 uint32_t
19 #define u64 uint64_t
20 #define U64_MAX 0xffffffffffffffff
21 #define s64 int64_t
22 #define S64_MIN 0x8000000000000000
23 #define S64_MAX 0x7fffffffffffffff
24 #define s64_abs labs
25 #define s32 int32_t
26 #define f32 float
27 #define f64 double
29 #if UCHAR_WIDTH == 8
30 #if __GNUC__ > 4
31 #define atomic_u8 atomic_uchar
32 #else
33 #define atomic_u8 u8
34 #endif
35 #else
36 #error "unable to find the right atomic for a 8 bits byte, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
37 #endif
38 #if SHRT_WIDTH == 16
39 #if __GNUC__ > 4
40 #define atomic_u16 atomic_ushort
41 #else
42 #define atomic_u16 u16
43 #endif
44 #else
45 #error "unable to find the right atomic for an unsigned 16 bits word, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
46 #endif
47 #if UINT_WIDTH == 32
48 #if __GNUC__ > 4
49 #define atomic_u32 atomic_uint
50 #else
51 #define atomic_u32 u32
52 #endif
53 #elif ULONG_WIDTH == 32
54 #if __GNUC__ > 4
55 #define atomic_u32 atomic_ulong
56 #else
57 #define atomic_u32 u32
58 #endif
59 #else
60 #error "unable to select the right atomic for an unsigned 32 bits word, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
61 #endif
62 #if LONG_WIDTH == 64
63 #if __GNUC__ > 4
64 #define atomic_s64 atomic_long
65 #else
66 #define atomic_s64 s64
67 #endif
68 #else
69 #error "unable to select the right atomic for a 64 bits signed word, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
70 #endif
71 #if __GNUC__ <= 4
72 #define atomic_load(x) __atomic_load_n(x,__ATOMIC_SEQ_CST)
73 #define atomic_store(x,y) __atomic_store_n(x,y,__ATOMIC_SEQ_CST)
74 #endif
76 #define loop for(;;)
78 * we don't know how to handle enum from the C "standard" perspective. this
79 * is based on empirical conclusions based on gcc.
80 * this is for compiler constant, not compiler constant _variables_
82 #define constant_u32 enum
84 #define ARRAY_N(x) (sizeof(x) / sizeof((x)[0]))
85 #endif