xref: /optee_os/lib/libutils/isoc/include/stdint.h (revision 216816c80b0213ff6b222a6e6ee733ac7faf7e7a)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30  * This file provides what C99 standard requires in
31  * 7.18 interger types <stdint.h>
32  */
33 
34 #ifndef STDINT_H
35 #define STDINT_H
36 #define _STDINT_H
37 
38 /*
39  * If compiler supplies neither __ILP32__ or __LP64__, try to figure it out
40  * here.
41  */
42 #if !defined(__ILP32__) && !defined(__LP64__)
43 #if defined(__SIZEOF_INT__) && defined(__SIZEOF_POINTER__) && \
44 	defined(__SIZEOF_LONG__)
45 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 4 && __SIZEOF_LONG__ == 4
46 #define __ILP32__ 1
47 #endif
48 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 8
49 #define __LP64__ 1
50 #endif
51 #endif
52 #endif /* !defined(__ILP32__) && !defined(__LP64__) */
53 
54 #if !defined(__ILP32__) && !defined(__LP64__)
55 #error Neither __ILP32__ nor __LP64__ is defined
56 #endif
57 
58 #ifndef ASM
59 
60 /* 7.18.1.1 Exact-width interger types */
61 #ifndef __int8_t_defined
62 # define __int8_t_defined
63 typedef signed char             int8_t;
64 typedef short int               int16_t;
65 typedef int                     int32_t;
66 #ifdef __ILP32__
67 __extension__
68 typedef long long int           int64_t;
69 #endif /*__ILP32__*/
70 #ifdef __LP64__
71 typedef long int		int64_t;
72 #endif /*__LP64__*/
73 #endif
74 
75 /* Unsigned.  */
76 typedef unsigned char           uint8_t;
77 typedef unsigned short int      uint16_t;
78 #ifndef __uint32_t_defined
79 typedef unsigned int            uint32_t;
80 # define __uint32_t_defined
81 #endif
82 #ifdef __ILP32__
83 __extension__
84 typedef unsigned long long int  uint64_t;
85 #endif /*__ILP32__*/
86 #ifdef __LP64__
87 typedef unsigned long int	uint64_t;
88 #endif /*__LP64__*/
89 
90 /* 7.18.1.2 Minimum-width integer types */
91 typedef int8_t int_least8_t;
92 typedef int16_t int_least16_t;
93 typedef int32_t int_least32_t;
94 typedef int64_t int_least64_t;
95 typedef uint8_t uint_least8_t;
96 typedef uint16_t uint_least16_t;
97 typedef uint32_t uint_least32_t;
98 typedef uint64_t uint_least64_t;
99 
100 /* 7.18.1.3 Fastest minimum-width integer types */
101 typedef int8_t int_fast8_t;
102 typedef int16_t int_fast16_t;
103 typedef int32_t int_fast32_t;
104 typedef int64_t int_fast64_t;
105 typedef uint8_t uint_fast8_t;
106 typedef uint16_t uint_fast16_t;
107 typedef uint32_t uint_fast32_t;
108 typedef uint64_t uint_fast64_t;
109 
110 /* 7.18.1.4 Integer types capable of holding object pointers */
111 typedef long intptr_t;
112 typedef unsigned long uintptr_t;
113 
114 typedef int64_t intmax_t;
115 typedef uint64_t uintmax_t;
116 
117 #endif /*ASM*/
118 
119 /*
120  * 7.18.2 Limits of specified-width integer types
121  */
122 
123 /* 7.18.2.1 Limits of exact-width interger types */
124 
125 #define INT8_MIN    (-0x7f-1)
126 #define INT16_MIN   (-0x7fff-1)
127 #define INT32_MIN   (-0x7fffffff-1)
128 #define INT64_MIN   (-0x7fffffffffffffffL-1)
129 
130 #define INT8_MAX    0x7f
131 #define INT16_MAX   0x7fff
132 #define INT32_MAX   0x7fffffff
133 #define INT64_MAX   0x7fffffffffffffffL
134 
135 #define UINT8_MAX    0xff
136 #define UINT16_MAX   0xffff
137 #define UINT32_MAX   0xffffffffU
138 #define UINT64_MAX   0xffffffffffffffffUL
139 
140 /* 7.18.2.2 Limits of minimum-width integer types */
141 
142 #define INT_LEAST8_MIN		INT8_MIN
143 #define INT_LEAST16_MIN		INT16_MIN
144 #define INT_LEAST32_MIN		INT32_MIN
145 #define INT_LEAST64_MIN		INT64_MIN
146 
147 #define INT_LEAST8_MAX		INT8_MAX
148 #define INT_LEAST16_MAX		INT16_MAX
149 #define INT_LEAST32_MAX		INT32_MAX
150 #define INT_LEAST64_MAX		INT64_MAX
151 
152 #define UINT_LEAST8_MAX		UINT8_MAX
153 #define UINT_LEAST16_MAX	UINT16_MAX
154 #define UINT_LEAST32_MAX	UINT32_MAX
155 #define UINT_LEAST64_MAX	UINT64_MAX
156 
157 /* 7.18.2.3 Limits of fastest minimum-width integer types */
158 
159 #define INT_FAST8_MIN		INT8_MIN
160 #define INT_FAST16_MIN		INT16_MIN
161 #define INT_FAST32_MIN		INT32_MIN
162 #define INT_FAST64_MIN		INT64_MIN
163 
164 #define INT_FAST8_MAX		INT8_MAX
165 #define INT_FAST16_MAX		INT16_MAX
166 #define INT_FAST32_MAX		INT32_MAX
167 #define INT_FAST64_MAX		INT64_MAX
168 
169 #define UINT_FAST8_MAX		UINT8_MAX
170 #define UINT_FAST16_MAX		UINT16_MAX
171 #define UINT_FAST32_MAX		UINT32_MAX
172 #define UINT_FAST64_MAX		UINT64_MAX
173 
174 /* 7.18.2.4 Limits of integer types capable of holding object pointers */
175 
176 #define INTPTR_MIN  LONG_MIN
177 #define INTPTR_MAX  LONG_MAX
178 #define UINTPTR_MAX ULONG_MAX
179 
180 /* 7.18.2.5  Limits of greatest-width integer types */
181 #define INTMAX_MAX  INT64_MAX
182 #define INTMAX_MIN  INT64_MIN
183 #define UINTMAX_MAX UINT64_MAX
184 
185 /* 7.18.3  Limits of other integer types */
186 #define SIZE_MAX	ULONG_MAX
187 
188 /*
189  * 7.18.4 Macros for integer constants
190  */
191 
192 /* 7.18.4.1 Macros for minimum-width integer constants */
193 
194 #define INT8_C(v)	v
195 #define UINT8_C(v)	v
196 #define INT16_C(v)	v
197 #define UINT16_C(v)	v
198 #define INT32_C(v)	v
199 #define UINT32_C(v)	v ## U
200 #ifdef __ILP32__
201 #define INT64_C(v)	v ## LL
202 #define UINT64_C(v)	v ## ULL
203 #endif
204 #ifdef __LP64__
205 #define INT64_C(v)	v ## L
206 #define UINT64_C(v)	v ## UL
207 #endif
208 
209 #ifdef ASM
210 #define UINTPTR_C(v) v
211 #else
212 #define UINTPTR_C(v) v ## LU
213 #endif
214 
215 /* 7.18.4.2 Macros for greatest-width integer constants */
216 
217 #define INTMAX_C(v)	INT64_C(v)
218 #define UINTMAX_C(v)	UINT64_C(v)
219 
220 
221 #endif /* STDINT_H */
222