npv:pts debug tracing, ffmpeg dev tantrum
[nyanmp.git] / npv / c_fixing.h
blob9516575029c049854dceab67bc842e8b5b9614fd
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 #include <stdatomic.h>
11 #define u8 uint8_t
12 #define U8_MAX 0xff
13 #define s8 int8_t
14 #define u16 uint16_t
15 #define U16_MAX 0xffff
16 #define s16 int16_t
17 #define u32 uint32_t
18 #define u64 uint64_t
19 #define U64_MAX 0xffffffffffffffff
20 #define s64 int64_t
21 #define S64_MIN 0x8000000000000000
22 #define S64_MAX 0x7fffffffffffffff
23 #define s64_abs labs
24 #define s32 int32_t
25 #define f32 float
26 #define f64 double
28 #if UCHAR_WIDTH == 8
29 #define atomic_u8 atomic_uchar
30 #else
31 #error "unable to find the right atomic for a 8 bits byte, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
32 #endif
33 #if SHRT_WIDTH == 16
34 #define atomic_u16 atomic_ushort
35 #else
36 #error "unable to find the right atomic for an unsigned 16 bits word, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
37 #endif
38 #if UINT_WIDTH == 32
39 #define atomic_u32 atomic_uint
40 #elif ULONG_WIDTH == 32
41 #define atomic_u32 atomic_ulong
42 #else
43 #error "unable to select the right atomic for an unsigned 32 bits word, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
44 #endif
45 #if LONG_WIDTH == 64
46 #define atomic_s64 atomic_long
47 #else
48 #error "unable to select the right atomic for a 64 bits signed word, be sure to have __STDC_WANT_IEC_60559_BFP_EXT__ defined"
49 #endif
51 #define loop for(;;)
53 * we don't know how to handle enum from the C "standard" perspective. this
54 * is based on empirical conclusions based on gcc.
55 * this is for compiler constant, not compiler constant _variables_
57 #define constant_u32 enum
59 #define ARRAY_N(x) (sizeof(x) / sizeof((x)[0]))
60 #endif