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