1 /*
2  * Copyright (c) 2004, 2005 by
3  * Ralf Corsepius, Ulm/Germany. All rights reserved.
4  *
5  * Permission to use, copy, modify, and distribute this software
6  * is freely granted, provided that this notice is preserved.
7  */
8 
9 #ifndef _SYS__INTSUP_H
10 #define _SYS__INTSUP_H
11 
12 #include <sys/features.h>
13 
14 #if __GNUC_PREREQ (3, 2)
15 /* gcc > 3.2 implicitly defines the values we are interested */
16 #define __STDINT_EXP(x) __##x##__
17 #else
18 #define __STDINT_EXP(x) x
19 #include <limits.h>
20 #endif
21 
22 /* Determine how intptr_t and intN_t fastN_t and leastN_t are defined by gcc
23    for this target.  This is used to determine the correct printf() constant in
24    inttypes.h and other  constants in stdint.h.
25    So we end up with
26    ?(signed|unsigned) char == 0
27    ?(signed|unsigned) short == 1
28    ?(signed|unsigned) int == 2
29    ?(signed|unsigned) short int == 3
30    ?(signed|unsigned) long == 4
31    ?(signed|unsigned) long int == 6
32    ?(signed|unsigned) long long == 8
33    ?(signed|unsigned) long long int == 10
34  */
35 #pragma push_macro("signed")
36 #pragma push_macro("unsigned")
37 #pragma push_macro("char")
38 #pragma push_macro("short")
39 #pragma push_macro("__int20")
40 #pragma push_macro("__int20__")
41 #pragma push_macro("int")
42 #pragma push_macro("long")
43 #undef signed
44 #undef unsigned
45 #undef char
46 #undef short
47 #undef int
48 #undef __int20
49 #undef __int20__
50 #undef long
51 #define signed +0
52 #define unsigned +0
53 #define char +0
54 #define short +1
55 #define __int20 +2
56 #define __int20__ +2
57 #define int +2
58 #define long +4
59 #if (__INTPTR_TYPE__ == 8 || __INTPTR_TYPE__ == 10)
60 #define _INTPTR_EQ_LONGLONG
61 #elif (__INTPTR_TYPE__ == 4 || __INTPTR_TYPE__ == 6)
62 #define _INTPTR_EQ_LONG
63 /* Note - the tests for _INTPTR_EQ_INT and _INTPTR_EQ_SHORT are currently
64    redundant as the values are not used.  But one day they may be needed
65    and so the tests remain.  */
66 #elif __INTPTR_TYPE__ == 2
67 #define _INTPTR_EQ_INT
68 #elif (__INTPTR_TYPE__ == 1 || __INTPTR_TYPE__ == 3)
69 #define _INTPTR_EQ_SHORT
70 #else
71 #error "Unable to determine type definition of intptr_t"
72 #endif
73 #if (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6)
74 #define _INT32_EQ_LONG
75 #elif __INT32_TYPE__ == 2
76 /* Nothing to define because int32_t is safe to print as an int. */
77 #else
78 #error "Unable to determine type definition of int32_t"
79 #endif
80 
81 #if (__INT8_TYPE__ == 0)
82 #define __INT8 "hh"
83 #elif (__INT8_TYPE__ == 1 || __INT8_TYPE__ == 3)
84 #define __INT8 "h"
85 #elif (__INT8_TYPE__ == 2)
86 #define __INT8
87 #elif (__INT8_TYPE__ == 4 || __INT8_TYPE__ == 6)
88 #define __INT8 "l"
89 #elif (__INT8_TYPE__ == 8 || __INT8_TYPE__ == 10)
90 #define __INT8 "ll"
91 #endif
92 #if (__INT16_TYPE__ == 1 || __INT16_TYPE__ == 3)
93 #define __INT16 "h"
94 #elif (__INT16_TYPE__ == 2)
95 #define __INT16
96 #elif (__INT16_TYPE__ == 4 || __INT16_TYPE__ == 6)
97 #define __INT16 "l"
98 #elif (__INT16_TYPE__ == 8 || __INT16_TYPE__ == 10)
99 #define __INT16 "ll"
100 #endif
101 #if (__INT32_TYPE__ == 2)
102 #define __INT32
103 #elif (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6)
104 #define __INT32 "l"
105 #elif (__INT32_TYPE__ == 8 || __INT32_TYPE__ == 10)
106 #define __INT32 "ll"
107 #endif
108 #if (__INT64_TYPE__ == 2)
109 #define __INT64
110 #elif (__INT64_TYPE__ == 4 || __INT64_TYPE__ == 6)
111 #define __INT64 "l"
112 #elif (__INT64_TYPE__ == 8 || __INT64_TYPE__ == 10)
113 #define __INT64 "ll"
114 #endif
115 #if (__INT_FAST8_TYPE__ == 0)
116 #define __FAST8 "hh"
117 #elif (__INT_FAST8_TYPE__ == 1 || __INT_FAST8_TYPE__ == 3)
118 #define __FAST8 "h"
119 #elif (__INT_FAST8_TYPE__ == 2)
120 #define __FAST8
121 #elif (__INT_FAST8_TYPE__ == 4 || __INT_FAST8_TYPE__ == 6)
122 #define __FAST8 "l"
123 #elif (__INT_FAST8_TYPE__ == 8 || __INT_FAST8_TYPE__ == 10)
124 #define __FAST8 "ll"
125 #endif
126 #if (__INT_FAST16_TYPE__ == 1 || __INT_FAST16_TYPE__ == 3)
127 #define __FAST16 "h"
128 #elif (__INT_FAST16_TYPE__ == 2)
129 #define __FAST16
130 #elif (__INT_FAST16_TYPE__ == 4 || __INT_FAST16_TYPE__ == 6)
131 #define __FAST16 "l"
132 #elif (__INT_FAST16_TYPE__ == 8 || __INT_FAST16_TYPE__ == 10)
133 #define __FAST16 "ll"
134 #endif
135 #if (__INT_FAST32_TYPE__ == 2)
136 #define __FAST32
137 #elif (__INT_FAST32_TYPE__ == 4 || __INT_FAST32_TYPE__ == 6)
138 #define __FAST32 "l"
139 #elif (__INT_FAST32_TYPE__ == 8 || __INT_FAST32_TYPE__ == 10)
140 #define __FAST32 "ll"
141 #endif
142 #if (__INT_FAST64_TYPE__ == 2)
143 #define __FAST64
144 #elif (__INT_FAST64_TYPE__ == 4 || __INT_FAST64_TYPE__ == 6)
145 #define __FAST64 "l"
146 #elif (__INT_FAST64_TYPE__ == 8 || __INT_FAST64_TYPE__ == 10)
147 #define __FAST64 "ll"
148 #endif
149 
150 #if (__INT_LEAST8_TYPE__ == 0)
151 #define __LEAST8 "hh"
152 #elif (__INT_LEAST8_TYPE__ == 1 || __INT_LEAST8_TYPE__ == 3)
153 #define __LEAST8 "h"
154 #elif (__INT_LEAST8_TYPE__ == 2)
155 #define __LEAST8
156 #elif (__INT_LEAST8_TYPE__ == 4 || __INT_LEAST8_TYPE__ == 6)
157 #define __LEAST8 "l"
158 #elif (__INT_LEAST8_TYPE__ == 8 || __INT_LEAST8_TYPE__ == 10)
159 #define __LEAST8 "ll"
160 #endif
161 #if (__INT_LEAST16_TYPE__ == 1 || __INT_LEAST16_TYPE__ == 3)
162 #define __LEAST16 "h"
163 #elif (__INT_LEAST16_TYPE__ == 2)
164 #define __LEAST16
165 #elif (__INT_LEAST16_TYPE__ == 4 || __INT_LEAST16_TYPE__ == 6)
166 #define __LEAST16 "l"
167 #elif (__INT_LEAST16_TYPE__ == 8 || __INT_LEAST16_TYPE__ == 10)
168 #define __LEAST16 "ll"
169 #endif
170 #if (__INT_LEAST32_TYPE__ == 2)
171 #define __LEAST32
172 #elif (__INT_LEAST32_TYPE__ == 4 || __INT_LEAST32_TYPE__ == 6)
173 #define __LEAST32 "l"
174 #elif (__INT_LEAST32_TYPE__ == 8 || __INT_LEAST32_TYPE__ == 10)
175 #define __LEAST32 "ll"
176 #endif
177 #if (__INT_LEAST64_TYPE__ == 2)
178 #define __LEAST64
179 #elif (__INT_LEAST64_TYPE__ == 4 || __INT_LEAST64_TYPE__ == 6)
180 #define __LEAST64 "l"
181 #elif (__INT_LEAST64_TYPE__ == 8 || __INT_LEAST64_TYPE__ == 10)
182 #define __LEAST64 "ll"
183 #endif
184 #undef signed
185 #undef unsigned
186 #undef char
187 #undef short
188 #undef int
189 #undef long
190 #pragma pop_macro("signed")
191 #pragma pop_macro("unsigned")
192 #pragma pop_macro("char")
193 #pragma pop_macro("short")
194 #pragma pop_macro("__int20")
195 #pragma pop_macro("__int20__")
196 #pragma pop_macro("int")
197 #pragma pop_macro("long")
198 
199 #endif /* _SYS__INTSUP_H */
200