1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2014, STMicroelectronics International N.V. 4 */ 5 6 #include <limits.h> 7 8 /* 9 * This file provides what C99 standard requires in 10 * 7.18 interger types <stdint.h> 11 */ 12 13 #ifndef __STDINT_H 14 #define __STDINT_H 15 16 /* 17 * If compiler supplies neither __ILP32__ or __LP64__, try to figure it out 18 * here. 19 */ 20 #if !defined(__ILP32__) && !defined(__LP64__) 21 #if defined(__SIZEOF_INT__) && defined(__SIZEOF_POINTER__) && \ 22 defined(__SIZEOF_LONG__) 23 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 4 && __SIZEOF_LONG__ == 4 24 #define __ILP32__ 1 25 #endif 26 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 8 27 #define __LP64__ 1 28 #endif 29 #endif 30 #endif /* !defined(__ILP32__) && !defined(__LP64__) */ 31 32 #if !defined(__ILP32__) && !defined(__LP64__) 33 #error Neither __ILP32__ nor __LP64__ is defined 34 #endif 35 36 #ifndef __ASSEMBLER__ 37 38 /* 7.18.1.1 Exact-width interger types */ 39 #ifndef __int8_t_defined 40 # define __int8_t_defined 41 typedef signed char int8_t; 42 typedef short int int16_t; 43 typedef int int32_t; 44 #ifdef __ILP32__ 45 __extension__ 46 typedef long long int int64_t; 47 #endif /*__ILP32__*/ 48 #ifdef __LP64__ 49 typedef long int int64_t; 50 #endif /*__LP64__*/ 51 #endif 52 53 /* Unsigned. */ 54 typedef unsigned char uint8_t; 55 typedef unsigned short int uint16_t; 56 #ifndef __uint32_t_defined 57 typedef unsigned int uint32_t; 58 # define __uint32_t_defined 59 #endif 60 #ifdef __ILP32__ 61 __extension__ 62 typedef unsigned long long int uint64_t; 63 #endif /*__ILP32__*/ 64 #ifdef __LP64__ 65 typedef unsigned long int uint64_t; 66 #endif /*__LP64__*/ 67 68 /* 7.18.1.2 Minimum-width integer types */ 69 typedef int8_t int_least8_t; 70 typedef int16_t int_least16_t; 71 typedef int32_t int_least32_t; 72 typedef int64_t int_least64_t; 73 typedef uint8_t uint_least8_t; 74 typedef uint16_t uint_least16_t; 75 typedef uint32_t uint_least32_t; 76 typedef uint64_t uint_least64_t; 77 78 /* 7.18.1.3 Fastest minimum-width integer types */ 79 typedef int8_t int_fast8_t; 80 typedef int16_t int_fast16_t; 81 typedef int32_t int_fast32_t; 82 typedef int64_t int_fast64_t; 83 typedef uint8_t uint_fast8_t; 84 typedef uint16_t uint_fast16_t; 85 typedef uint32_t uint_fast32_t; 86 typedef uint64_t uint_fast64_t; 87 88 /* 7.18.1.4 Integer types capable of holding object pointers */ 89 typedef long intptr_t; 90 typedef unsigned long uintptr_t; 91 92 typedef int64_t intmax_t; 93 typedef uint64_t uintmax_t; 94 95 #endif /*__ASSEMBLER__*/ 96 97 /* 98 * 7.18.2 Limits of specified-width integer types 99 */ 100 101 /* 7.18.2.1 Limits of exact-width interger types */ 102 103 #define INT8_MIN (-0x7f-1) 104 #define INT16_MIN (-0x7fff-1) 105 #define INT32_MIN (-0x7fffffff-1) 106 #define INT64_MIN (-0x7fffffffffffffffL-1) 107 108 #define INT8_MAX 0x7f 109 #define INT16_MAX 0x7fff 110 #define INT32_MAX 0x7fffffff 111 #define INT64_MAX 0x7fffffffffffffffL 112 113 #define UINT8_MAX 0xff 114 #define UINT16_MAX 0xffff 115 #define UINT32_MAX 0xffffffffU 116 #define UINT64_MAX 0xffffffffffffffffUL 117 118 /* 7.18.2.2 Limits of minimum-width integer types */ 119 120 #define INT_LEAST8_MIN INT8_MIN 121 #define INT_LEAST16_MIN INT16_MIN 122 #define INT_LEAST32_MIN INT32_MIN 123 #define INT_LEAST64_MIN INT64_MIN 124 125 #define INT_LEAST8_MAX INT8_MAX 126 #define INT_LEAST16_MAX INT16_MAX 127 #define INT_LEAST32_MAX INT32_MAX 128 #define INT_LEAST64_MAX INT64_MAX 129 130 #define UINT_LEAST8_MAX UINT8_MAX 131 #define UINT_LEAST16_MAX UINT16_MAX 132 #define UINT_LEAST32_MAX UINT32_MAX 133 #define UINT_LEAST64_MAX UINT64_MAX 134 135 /* 7.18.2.3 Limits of fastest minimum-width integer types */ 136 137 #define INT_FAST8_MIN INT8_MIN 138 #define INT_FAST16_MIN INT16_MIN 139 #define INT_FAST32_MIN INT32_MIN 140 #define INT_FAST64_MIN INT64_MIN 141 142 #define INT_FAST8_MAX INT8_MAX 143 #define INT_FAST16_MAX INT16_MAX 144 #define INT_FAST32_MAX INT32_MAX 145 #define INT_FAST64_MAX INT64_MAX 146 147 #define UINT_FAST8_MAX UINT8_MAX 148 #define UINT_FAST16_MAX UINT16_MAX 149 #define UINT_FAST32_MAX UINT32_MAX 150 #define UINT_FAST64_MAX UINT64_MAX 151 152 /* 7.18.2.4 Limits of integer types capable of holding object pointers */ 153 154 #define INTPTR_MIN LONG_MIN 155 #define INTPTR_MAX LONG_MAX 156 #define UINTPTR_MAX ULONG_MAX 157 158 /* 7.18.2.5 Limits of greatest-width integer types */ 159 #define INTMAX_MAX INT64_MAX 160 #define INTMAX_MIN INT64_MIN 161 #define UINTMAX_MAX UINT64_MAX 162 163 /* 7.18.3 Limits of other integer types */ 164 #define SIZE_MAX ULONG_MAX 165 166 /* 167 * 7.18.4 Macros for integer constants 168 */ 169 170 #ifdef __ASSEMBLER__ 171 #define U(v) v 172 #define UL(v) v 173 #define ULL(v) v 174 #define L(v) v 175 #define LL(v) v 176 #else 177 #define U(v) v ## U 178 #define UL(v) v ## UL 179 #define ULL(v) v ## ULL 180 #define L(v) v ## L 181 #define LL(v) v ## LL 182 #endif 183 184 /* 7.18.4.1 Macros for minimum-width integer constants */ 185 186 #define INT8_C(v) v 187 #define UINT8_C(v) v 188 #define INT16_C(v) v 189 #define UINT16_C(v) v 190 #define INT32_C(v) v 191 #define UINT32_C(v) U(v) 192 #ifdef __ILP32__ 193 #define INT64_C(v) LL(v) 194 #define UINT64_C(v) ULL(v) 195 #endif 196 #ifdef __LP64__ 197 #define INT64_C(v) L(v) 198 #define UINT64_C(v) UL(v) 199 #endif 200 201 #define UINTPTR_C(v) UL(v) 202 203 /* 7.18.4.2 Macros for greatest-width integer constants */ 204 205 #define INTMAX_C(v) INT64_C(v) 206 #define UINTMAX_C(v) UINT64_C(v) 207 208 #endif /* __STDINT_H */ 209