XenevaOS
Loading...
Searching...
No Matches
stdint.h
Go to the documentation of this file.
1
30#ifndef __STDINT_H__
31#define __STDINT_H__
32
33
34#define __need_wint_t
35#define __need_wchar_t
36
37typedef unsigned char BOOL;
38
39#ifdef ARCH_ARM64
40#if !defined(bool)
41#include <stdbool.h>
42#endif
43#endif
44
45
46/* 7.18.1.1 Exact-width integer types */
47typedef signed char int8_t;
48typedef unsigned char uint8_t;
49typedef short int16_t;
50typedef unsigned short uint16_t;
51typedef int int32_t;
52typedef unsigned uint32_t;
53typedef long long int64_t;
54typedef unsigned long long uint64_t;
55
56typedef uint8_t uint8;
60typedef int8_t int8;
61typedef int16_t int16;
62typedef int32_t int32;
63typedef int64_t int64;
64
65
66/* 7.18.1.2 Minimum-width integer types */
67typedef signed char int_least8_t;
68typedef unsigned char uint_least8_t;
69typedef short int_least16_t;
70typedef unsigned short uint_least16_t;
71typedef int int_least32_t;
72typedef unsigned uint_least32_t;
73typedef long long int_least64_t;
74typedef unsigned long long uint_least64_t;
75
76/* 7.18.1.3 Fastest minimum-width integer types
77* Not actually guaranteed to be fastest for all purposes
78* Here we use the exact-width types for 8 and 16-bit ints.
79*/
80typedef char int_fast8_t;
81typedef unsigned char uint_fast8_t;
82typedef short int_fast16_t;
83typedef unsigned short uint_fast16_t;
84typedef int int_fast32_t;
85typedef unsigned int uint_fast32_t;
86typedef long long int_fast64_t;
87typedef unsigned long long uint_fast64_t;
88
89#if defined(ARCH_ARM64) || defined(__aarch64__) || defined(ARCH_X64) || defined(__x86_64__)
90typedef long long intptr_t;
91typedef unsigned long long uintptr_t;
92#else
93typedef int intptr_t;
94typedef unsigned int uintptr_t;
95#endif
96
97/* 7.18.1.5 Greatest-width integer types */
98typedef long long intmax_t;
99typedef unsigned long long uintmax_t;
100
101#ifdef __SIZE_TYPE__
102typedef __SIZE_TYPE__ size_t;
103#else
105#endif
106/* 7.18.2 Limits of specified-width integer types */
107#if defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)
108
109/* 7.18.2.1 Limits of exact-width integer types */
110#define INT8_MIN (-128)
111#define INT16_MIN (-32768)
112#define INT32_MIN (-2147483647 - 1)
113#define INT64_MIN (-9223372036854775807LL - 1)
114
115#define INT8_MAX 127
116#define INT16_MAX 32767
117#define INT32_MAX 2147483647
118#define INT64_MAX 9223372036854775807LL
119
120#define UINT8_MAX 0xff /* 255U */
121#define UINT16_MAX 0xffff /* 65535U */
122#define UINT32_MAX 0xffffffff /* 4294967295U */
123#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
124
125/* 7.18.2.2 Limits of minimum-width integer types */
126#define INT_LEAST8_MIN INT8_MIN
127#define INT_LEAST16_MIN INT16_MIN
128#define INT_LEAST32_MIN INT32_MIN
129#define INT_LEAST64_MIN INT64_MIN
130
131#define INT_LEAST8_MAX INT8_MAX
132#define INT_LEAST16_MAX INT16_MAX
133#define INT_LEAST32_MAX INT32_MAX
134#define INT_LEAST64_MAX INT64_MAX
135
136#define UINT_LEAST8_MAX UINT8_MAX
137#define UINT_LEAST16_MAX UINT16_MAX
138#define UINT_LEAST32_MAX UINT32_MAX
139#define UINT_LEAST64_MAX UINT64_MAX
140
141/* 7.18.2.3 Limits of fastest minimum-width integer types */
142#define INT_FAST8_MIN INT8_MIN
143#define INT_FAST16_MIN INT16_MIN
144#define INT_FAST32_MIN INT32_MIN
145#define INT_FAST64_MIN INT64_MIN
146
147#define INT_FAST8_MAX INT8_MAX
148#define INT_FAST16_MAX INT16_MAX
149#define INT_FAST32_MAX INT32_MAX
150#define INT_FAST64_MAX INT64_MAX
151
152#define UINT_FAST8_MAX UINT8_MAX
153#define UINT_FAST16_MAX UINT16_MAX
154#define UINT_FAST32_MAX UINT32_MAX
155#define UINT_FAST64_MAX UINT64_MAX
156
157/* 7.18.2.4 Limits of integer types capable of holding
158object pointers */
159#define INTPTR_MIN INT32_MIN
160#define INTPTR_MAX INT32_MAX
161#define UINTPTR_MAX UINT32_MAX
162
163/* 7.18.2.5 Limits of greatest-width integer types */
164#define INTMAX_MIN INT64_MIN
165#define INTMAX_MAX INT64_MAX
166#define UINTMAX_MAX UINT64_MAX
167
168/* 7.18.3 Limits of other integer types */
169#define PTRDIFF_MIN INT32_MIN
170#define PTRDIFF_MAX INT32_MAX
171
172#define SIG_ATOMIC_MIN INT32_MIN
173#define SIG_ATOMIC_MAX INT32_MAX
174#ifndef SIZE_MAX
175#if defined(ARCH_ARM64) || defined(__aarch64__) || defined(ARCH_X64) || defined(__x86_64__)
176#define SIZE_MAX UINT64_MAX
177#else
178#define SIZE_MAX UINT32_MAX
179#endif
180#endif
181#ifndef WCHAR_MIN /* also in wchar.h */
182#define WCHAR_MIN 0
183#define WCHAR_MAX ((wchar_t)-1) /* UINT16_MAX */
184#endif
185
186/*
187* wint_t is unsigned short for compatibility with MS runtime
188*/
189#define WINT_MIN 0
190#define WINT_MAX ((wint_t)-1) /* UINT16_MAX */
191
192#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
193
194
195/* 7.18.4 Macros for integer constants */
196#if !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS
197
198/* 7.18.4.1 Macros for minimum-width integer constants */
199
200#define INT8_C(val) ((int8_t) + (val))
201#define UINT8_C(val) ((uint8_t) + (val##U))
202#define INT16_C(val) ((int16_t) + (val))
203#define UINT16_C(val) ((uint16_t) + (val##U))
204
205#define INT32_C(val) val##L
206#define UINT32_C(val) val##UL
207#define INT64_C(val) val##LL
208#define UINT64_C(val) val##ULL
209
210/* 7.18.4.2 Macros for greatest-width integer constants */
211#define INTMAX_C(val) INT64_C(val)
212#define UINTMAX_C(val) UINT64_C(val)
213
214#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
215
216#ifdef __cplusplus
217extern "C++" {
218 template <class T, class U> intptr_t raw_diff(T* p1, U* p2)
219 {
220 return (intptr_t)p1 - (intptr_t)p2;
221 };
222 template <class T, class U> T raw_offset(U p1, const intptr_t offset)
223 {
224 return (T)((size_t)p1 + offset);
225 };
226 template <class T, class U> T mem_after(U* p1)
227 {
228 return (T)(&p1[1]);
229 };
230};
231#endif
232
233#define RAW_OFFSET(type, x, offset) (type)((size_t)x + offset)
234#define RAW_DIFF(p1,p2) ((intptr_t)p1 - (intptr_t)p2)
235#define MEM_AFTER(type, p) ((type)(&(p)[1]))
236
237#define DIV_ROUND_UP(x, y) \
238 ((x + y - 1) / y)
239
240#define ALIGN_UP(x, y) (DIV_ROUND_UP(x,y)*y)
241
242#ifndef do_div
243#define do_div(n, base) { \
244 uint64_t __base = (base); \
245 uint64_t __rem = n % __base; \
246 n = n / __base; \
247 __rem; \
248 }
249#endif
250
251#define clamp_t(type, val, lo, hi) \
252 ((type)(val) < (type)(lo) ? (type)(lo) : ((type)(val) > (type)(hi)? (type)(hi) : (type)(val)))
253
254static inline int64_t div_round_closest_s64(int64_t x, int64_t divisor) {
255 if ((x > 0) == (divisor > 0))
256 return (x + divisor / 2) / divisor;
257 else
258 return (x - divisor / 2) / divisor;
259}
260
261static inline uint64_t div_round_closest_u64(uint64_t x, uint64_t divisor) {
262 return (x + divisor / 2) / divisor;
263}
264
265static inline int32_t div_round_closest_s32(int32_t x, int32_t divisor) {
266 if ((x > 0) == (divisor > 0))
267 return (x + divisor / 2) / divisor;
268 else
269 return (x - divisor / 2) / divisor;
270}
271
272
273static inline uint32_t div_round_closest_u32(uint32_t x, uint32_t divisor) {
274 return (x + divisor / 2) / divisor;
275}
276
277#define DIV_ROUND_CLOSEST(x, divisor) _Generic((x), \
278 int64_t: div_round_closest_s64, \
279 uint64_t: div_round_closest_u64, \
280 int32_t: div_round_closest_s32, \
281 uint32_t: div_round_closest_u32, \
282 default: div_round_closest_s32 \
283)(x,divisor)
284
285#define CLAMP(val, lo, hi) ((val) < (lo) ? (lo) : ((val) > (hi) ? (hi) : (val)))
286
287#define ABS(x) ((x) < 0 ? -(x) : (x))
288#endif
long long int_least64_t
Definition stdint.h:73
int intptr_t
Definition stdint.h:93
uint64_t size_t
Definition stdint.h:104
unsigned short uint16_t
Definition stdint.h:50
unsigned char uint_fast8_t
Definition stdint.h:81
unsigned uint32_t
Definition stdint.h:52
int int32_t
Definition stdint.h:51
uint8_t uint8
Definition stdint.h:56
unsigned int uint_fast32_t
Definition stdint.h:85
int int_least32_t
Definition stdint.h:71
unsigned char BOOL
Definition stdint.h:37
unsigned int uintptr_t
Definition stdint.h:94
unsigned long long uintmax_t
Definition stdint.h:99
int64_t int64
Definition stdint.h:63
short int_least16_t
Definition stdint.h:69
long long int_fast64_t
Definition stdint.h:86
long long int64_t
Definition stdint.h:53
int int_fast32_t
Definition stdint.h:84
unsigned long long uint_least64_t
Definition stdint.h:74
int16_t int16
Definition stdint.h:61
short int16_t
Definition stdint.h:49
int8_t int8
Definition stdint.h:60
unsigned long long uint64_t
Definition stdint.h:54
unsigned uint_least32_t
Definition stdint.h:72
unsigned short uint_fast16_t
Definition stdint.h:83
unsigned char uint_least8_t
Definition stdint.h:68
unsigned long long uint_fast64_t
Definition stdint.h:87
int32_t int32
Definition stdint.h:62
unsigned char uint8_t
Definition stdint.h:48
uint64_t uint64
Definition stdint.h:59
uint16_t uint16
Definition stdint.h:57
long long intmax_t
Definition stdint.h:98
uint32_t uint32
Definition stdint.h:58
unsigned short uint_least16_t
Definition stdint.h:70
signed char int_least8_t
Definition stdint.h:67
signed char int8_t
Definition stdint.h:47
char int_fast8_t
Definition stdint.h:80
short int_fast16_t
Definition stdint.h:82
std::ptrdiff_t raw_diff(T p1, T p2)
Definition Common.hpp:26
T raw_offset(U p1, std::ptrdiff_t offset)
Definition Common.hpp:41
T mem_after(T p1)
Definition Common.hpp:58
int int32_t
Definition acefiex.h:160
unsigned int uint32_t
Definition acefiex.h:163
COMPILER_DEPENDENT_INT64 int64_t
Definition acefiex.h:164
short int int16_t
Definition acefiex.h:159
unsigned char uint8_t
Definition acefiex.h:161
COMPILER_DEPENDENT_UINT64 uint64_t
Definition acefiex.h:165
unsigned short int uint16_t
Definition acefiex.h:162
signed char int8_t
Definition acefiex.h:158