blob: 6be623bf5a563e51110146a53a1271d833006cc1 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/*
* nasmint.h
*
* Small ersatz subset of <inttypes.h>, deriving the types from
* <limits.h>.
*
* Important: the preprocessor may truncate numbers too large for it.
* Therefore, test the signed types only ... truncation won't generate
* a 01111111... bit pattern.
*/
#ifndef NASM_NASMINT_H
#define NASM_NASMINT_H
#include <limits.h>
/*** 64-bit type: __int64, long or long long ***/
/* Some old versions of gcc <limits.h> omit LLONG_MAX */
#ifndef LLONG_MAX
# ifdef __LONG_LONG_MAX__
# define LLONG_MAX __LONG_LONG_MAX__
# else
# define LLONG_MAX 0 /* Assume long long is unusable */
# endif
#endif
#ifndef _I64_MAX
# ifdef _MSC_VER
# define _I64_MAX 9223372036854775807
# else
# define _I64_MAX 0
# endif
#endif
#if _I64_MAX == 9223372036854775807
/* Windows-based compiler: use __int64 */
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
#define _scn64 "I64"
#define _pri64 "I64"
#define INT64_C(x) x ## i64
#define UINT64_C(x) x ## ui64
#elif LONG_MAX == 9223372036854775807L
/* long is 64 bits */
typedef signed long int64_t;
typedef unsigned long uint64_t;
#define _scn64 "l"
#define _pri64 "l"
#define INT64_C(x) x ## L
#define UINT64_C(x) x ## UL
#elif LLONG_MAX == 9223372036854775807LL
/* long long is 64 bits */
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
#define _scn64 "ll"
#define _pri64 "ll"
#define INT64_C(x) x ## LL
#define UINT64_C(x) x ## ULL
#else
#error "Neither long nor long long is 64 bits in size"
#endif
/*** 32-bit type: int or long ***/
#if INT_MAX == 2147483647
/* int is 32 bits */
typedef signed int int32_t;
typedef unsigned int uint32_t;
#define _scn32 ""
#define _pri32 ""
#define INT32_C(x) x
#define UINT32_C(x) x ## U
#elif LONG_MAX == 2147483647L
/* long is 32 bits */
typedef signed long int32_t;
typedef unsigned long uint32_t;
#define _scn32 "l"
#define _pri32 "l"
#define INT32_C(x) x ## L
#define UINT32_C(x) x ## UL
#else
#error "Neither int nor long is 32 bits in size"
#endif
/*** 16-bit size: int or short ***/
#if INT_MAX == 32767
/* int is 16 bits */
typedef signed int int16_t;
typedef unsigned int uint16_t;
#define _scn16 ""
#define _pri16 ""
#define INT16_C(x) x
#define UINT16_C(x) x ## U
#elif SHRT_MAX == 32767
/* short is 16 bits */
typedef signed short int16_t;
typedef unsigned short uint16_t;
#define _scn16 "h"
#define _pri16 ""
#define INT16_C(x) x
#define UINT16_C(x) x ## U
#else
#error "Neither short nor int is 16 bits in size"
#endif
/*** 8-bit size: char ***/
#if SCHAR_MAX == 127
/* char is 8 bits */
typedef signed char int8_t;
typedef unsigned char uint8_t;
#define _scn8 "hh"
#define _pri8 ""
#define INT8_C(x) x
#define UINT8_C(x) x ## U
#else
#error "char is not 8 bits in size"
#endif
/* The rest of this is common to all models */
#define PRId8 _pri8 "d"
#define PRId16 _pri16 "d"
#define PRId32 _pri32 "d"
#define PRId64 _pri64 "d"
#define PRIi8 _pri8 "i"
#define PRIi16 _pri16 "i"
#define PRIi32 _pri32 "i"
#define PRIi64 _pri64 "i"
#define PRIo8 _pri8 "o"
#define PRIo16 _pri16 "o"
#define PRIo32 _pri32 "o"
#define PRIo64 _pri64 "o"
#define PRIu8 _pri8 "u"
#define PRIu16 _pri16 "u"
#define PRIu32 _pri32 "u"
#define PRIu64 _pri64 "u"
#define PRIx8 _pri8 "x"
#define PRIx16 _pri16 "x"
#define PRIx32 _pri32 "x"
#define PRIx64 _pri64 "x"
#define PRIX8 _pri8 "X"
#define PRIX16 _pri16 "X"
#define PRIX32 _pri32 "X"
#define PRIX64 _pri64 "X"
#define SCNd8 _scn8 "d"
#define SCNd16 _scn16 "d"
#define SCNd32 _scn32 "d"
#define SCNd64 _scn64 "d"
#define SCNi8 _scn8 "i"
#define SCNi16 _scn16 "i"
#define SCNi32 _scn32 "i"
#define SCNi64 _scn64 "i"
#define SCNo8 _scn8 "o"
#define SCNo16 _scn16 "o"
#define SCNo32 _scn32 "o"
#define SCNo64 _scn64 "o"
#define SCNu8 _scn8 "u"
#define SCNu16 _scn16 "u"
#define SCNu32 _scn32 "u"
#define SCNu64 _scn64 "u"
#define SCNx8 _scn8 "x"
#define SCNx16 _scn16 "x"
#define SCNx32 _scn32 "x"
#define SCNx64 _scn64 "x"
#define INT8_MIN INT8_C(-128)
#define INT8_MAX INT8_C(127)
#define UINT8_MAX UINT8_C(255)
#define INT16_MIN INT16_C(-32768)
#define INT16_MAX INT16_C(32767)
#define UINT16_MAX UINT16_C(65535)
#define INT32_MIN INT32_C(-2147483648)
#define INT32_MAX INT32_C(2147483647)
#define UINT32_MAX UINT32_C(4294967295)
#define INT64_MIN INT64_C(-9223372036854775808)
#define INT64_MAX INT64_C(9223372036854775807)
#define UINT64_MAX UINT64_C(18446744073709551615)
#endif /* NASM_NASMINT_H */
|