insns.dat: use the officially documented UD0 and UD1 forms
[nasm.git] / include / nasmint.h
blob6be623bf5a563e51110146a53a1271d833006cc1
1 /*
2 * nasmint.h
4 * Small ersatz subset of <inttypes.h>, deriving the types from
5 * <limits.h>.
7 * Important: the preprocessor may truncate numbers too large for it.
8 * Therefore, test the signed types only ... truncation won't generate
9 * a 01111111... bit pattern.
12 #ifndef NASM_NASMINT_H
13 #define NASM_NASMINT_H
15 #include <limits.h>
17 /*** 64-bit type: __int64, long or long long ***/
19 /* Some old versions of gcc <limits.h> omit LLONG_MAX */
20 #ifndef LLONG_MAX
21 # ifdef __LONG_LONG_MAX__
22 # define LLONG_MAX __LONG_LONG_MAX__
23 # else
24 # define LLONG_MAX 0 /* Assume long long is unusable */
25 # endif
26 #endif
28 #ifndef _I64_MAX
29 # ifdef _MSC_VER
30 # define _I64_MAX 9223372036854775807
31 # else
32 # define _I64_MAX 0
33 # endif
34 #endif
36 #if _I64_MAX == 9223372036854775807
38 /* Windows-based compiler: use __int64 */
39 typedef signed __int64 int64_t;
40 typedef unsigned __int64 uint64_t;
41 #define _scn64 "I64"
42 #define _pri64 "I64"
43 #define INT64_C(x) x ## i64
44 #define UINT64_C(x) x ## ui64
46 #elif LONG_MAX == 9223372036854775807L
48 /* long is 64 bits */
49 typedef signed long int64_t;
50 typedef unsigned long uint64_t;
51 #define _scn64 "l"
52 #define _pri64 "l"
53 #define INT64_C(x) x ## L
54 #define UINT64_C(x) x ## UL
56 #elif LLONG_MAX == 9223372036854775807LL
58 /* long long is 64 bits */
59 typedef signed long long int64_t;
60 typedef unsigned long long uint64_t;
61 #define _scn64 "ll"
62 #define _pri64 "ll"
63 #define INT64_C(x) x ## LL
64 #define UINT64_C(x) x ## ULL
66 #else
68 #error "Neither long nor long long is 64 bits in size"
70 #endif
72 /*** 32-bit type: int or long ***/
74 #if INT_MAX == 2147483647
76 /* int is 32 bits */
77 typedef signed int int32_t;
78 typedef unsigned int uint32_t;
79 #define _scn32 ""
80 #define _pri32 ""
81 #define INT32_C(x) x
82 #define UINT32_C(x) x ## U
84 #elif LONG_MAX == 2147483647L
86 /* long is 32 bits */
87 typedef signed long int32_t;
88 typedef unsigned long uint32_t;
89 #define _scn32 "l"
90 #define _pri32 "l"
91 #define INT32_C(x) x ## L
92 #define UINT32_C(x) x ## UL
94 #else
96 #error "Neither int nor long is 32 bits in size"
98 #endif
100 /*** 16-bit size: int or short ***/
102 #if INT_MAX == 32767
104 /* int is 16 bits */
105 typedef signed int int16_t;
106 typedef unsigned int uint16_t;
107 #define _scn16 ""
108 #define _pri16 ""
109 #define INT16_C(x) x
110 #define UINT16_C(x) x ## U
112 #elif SHRT_MAX == 32767
114 /* short is 16 bits */
115 typedef signed short int16_t;
116 typedef unsigned short uint16_t;
117 #define _scn16 "h"
118 #define _pri16 ""
119 #define INT16_C(x) x
120 #define UINT16_C(x) x ## U
122 #else
124 #error "Neither short nor int is 16 bits in size"
126 #endif
128 /*** 8-bit size: char ***/
130 #if SCHAR_MAX == 127
132 /* char is 8 bits */
133 typedef signed char int8_t;
134 typedef unsigned char uint8_t;
135 #define _scn8 "hh"
136 #define _pri8 ""
137 #define INT8_C(x) x
138 #define UINT8_C(x) x ## U
140 #else
142 #error "char is not 8 bits in size"
144 #endif
146 /* The rest of this is common to all models */
148 #define PRId8 _pri8 "d"
149 #define PRId16 _pri16 "d"
150 #define PRId32 _pri32 "d"
151 #define PRId64 _pri64 "d"
153 #define PRIi8 _pri8 "i"
154 #define PRIi16 _pri16 "i"
155 #define PRIi32 _pri32 "i"
156 #define PRIi64 _pri64 "i"
158 #define PRIo8 _pri8 "o"
159 #define PRIo16 _pri16 "o"
160 #define PRIo32 _pri32 "o"
161 #define PRIo64 _pri64 "o"
163 #define PRIu8 _pri8 "u"
164 #define PRIu16 _pri16 "u"
165 #define PRIu32 _pri32 "u"
166 #define PRIu64 _pri64 "u"
168 #define PRIx8 _pri8 "x"
169 #define PRIx16 _pri16 "x"
170 #define PRIx32 _pri32 "x"
171 #define PRIx64 _pri64 "x"
173 #define PRIX8 _pri8 "X"
174 #define PRIX16 _pri16 "X"
175 #define PRIX32 _pri32 "X"
176 #define PRIX64 _pri64 "X"
178 #define SCNd8 _scn8 "d"
179 #define SCNd16 _scn16 "d"
180 #define SCNd32 _scn32 "d"
181 #define SCNd64 _scn64 "d"
183 #define SCNi8 _scn8 "i"
184 #define SCNi16 _scn16 "i"
185 #define SCNi32 _scn32 "i"
186 #define SCNi64 _scn64 "i"
188 #define SCNo8 _scn8 "o"
189 #define SCNo16 _scn16 "o"
190 #define SCNo32 _scn32 "o"
191 #define SCNo64 _scn64 "o"
193 #define SCNu8 _scn8 "u"
194 #define SCNu16 _scn16 "u"
195 #define SCNu32 _scn32 "u"
196 #define SCNu64 _scn64 "u"
198 #define SCNx8 _scn8 "x"
199 #define SCNx16 _scn16 "x"
200 #define SCNx32 _scn32 "x"
201 #define SCNx64 _scn64 "x"
203 #define INT8_MIN INT8_C(-128)
204 #define INT8_MAX INT8_C(127)
205 #define UINT8_MAX UINT8_C(255)
207 #define INT16_MIN INT16_C(-32768)
208 #define INT16_MAX INT16_C(32767)
209 #define UINT16_MAX UINT16_C(65535)
211 #define INT32_MIN INT32_C(-2147483648)
212 #define INT32_MAX INT32_C(2147483647)
213 #define UINT32_MAX UINT32_C(4294967295)
215 #define INT64_MIN INT64_C(-9223372036854775808)
216 #define INT64_MAX INT64_C(9223372036854775807)
217 #define UINT64_MAX UINT64_C(18446744073709551615)
219 #endif /* NASM_NASMINT_H */