[Utils] Identity map module-level debug info on first use in CloneFunction* (#118627)
[llvm-project.git] / libc / include / llvm-libc-macros / stdbit-macros.h
blobc5b2f097783440d5c711986721240a2a28205e7d
1 //===-- Definition of macros to be used with stdbit functions ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef __LLVM_LIBC_MACROS_STDBIT_MACROS_H
10 #define __LLVM_LIBC_MACROS_STDBIT_MACROS_H
12 #define __STDC_VERSION_STDBIT_H__ 202311L
13 #define __STDC_ENDIAN_LITTLE__ __ORDER_LITTLE_ENDIAN__
14 #define __STDC_ENDIAN_BIG__ __ORDER_BIG_ENDIAN__
15 #define __STDC_ENDIAN_NATIVE__ __BYTE_ORDER__
17 // TODO(https://github.com/llvm/llvm-project/issues/80509): support _BitInt().
18 #ifdef __cplusplus
19 inline unsigned stdc_leading_zeros(unsigned char x) {
20 return stdc_leading_zeros_uc(x);
22 inline unsigned stdc_leading_zeros(unsigned short x) {
23 return stdc_leading_zeros_us(x);
25 inline unsigned stdc_leading_zeros(unsigned x) {
26 return stdc_leading_zeros_ui(x);
28 inline unsigned stdc_leading_zeros(unsigned long x) {
29 return stdc_leading_zeros_ul(x);
31 inline unsigned stdc_leading_zeros(unsigned long long x) {
32 return stdc_leading_zeros_ull(x);
34 inline unsigned stdc_leading_ones(unsigned char x) {
35 return stdc_leading_ones_uc(x);
37 inline unsigned stdc_leading_ones(unsigned short x) {
38 return stdc_leading_ones_us(x);
40 inline unsigned stdc_leading_ones(unsigned x) {
41 return stdc_leading_ones_ui(x);
43 inline unsigned stdc_leading_ones(unsigned long x) {
44 return stdc_leading_ones_ul(x);
46 inline unsigned stdc_leading_ones(unsigned long long x) {
47 return stdc_leading_ones_ull(x);
49 inline unsigned stdc_trailing_zeros(unsigned char x) {
50 return stdc_trailing_zeros_uc(x);
52 inline unsigned stdc_trailing_zeros(unsigned short x) {
53 return stdc_trailing_zeros_us(x);
55 inline unsigned stdc_trailing_zeros(unsigned x) {
56 return stdc_trailing_zeros_ui(x);
58 inline unsigned stdc_trailing_zeros(unsigned long x) {
59 return stdc_trailing_zeros_ul(x);
61 inline unsigned stdc_trailing_zeros(unsigned long long x) {
62 return stdc_trailing_zeros_ull(x);
64 inline unsigned stdc_trailing_ones(unsigned char x) {
65 return stdc_trailing_ones_uc(x);
67 inline unsigned stdc_trailing_ones(unsigned short x) {
68 return stdc_trailing_ones_us(x);
70 inline unsigned stdc_trailing_ones(unsigned x) {
71 return stdc_trailing_ones_ui(x);
73 inline unsigned stdc_trailing_ones(unsigned long x) {
74 return stdc_trailing_ones_ul(x);
76 inline unsigned stdc_trailing_ones(unsigned long long x) {
77 return stdc_trailing_ones_ull(x);
79 inline unsigned stdc_first_leading_zero(unsigned char x) {
80 return stdc_first_leading_zero_uc(x);
82 inline unsigned stdc_first_leading_zero(unsigned short x) {
83 return stdc_first_leading_zero_us(x);
85 inline unsigned stdc_first_leading_zero(unsigned x) {
86 return stdc_first_leading_zero_ui(x);
88 inline unsigned stdc_first_leading_zero(unsigned long x) {
89 return stdc_first_leading_zero_ul(x);
91 inline unsigned stdc_first_leading_zero(unsigned long long x) {
92 return stdc_first_leading_zero_ull(x);
94 inline unsigned stdc_first_leading_one(unsigned char x) {
95 return stdc_first_leading_one_uc(x);
97 inline unsigned stdc_first_leading_one(unsigned short x) {
98 return stdc_first_leading_one_us(x);
100 inline unsigned stdc_first_leading_one(unsigned x) {
101 return stdc_first_leading_one_ui(x);
103 inline unsigned stdc_first_leading_one(unsigned long x) {
104 return stdc_first_leading_one_ul(x);
106 inline unsigned stdc_first_leading_one(unsigned long long x) {
107 return stdc_first_leading_one_ull(x);
109 inline unsigned stdc_first_trailing_zero(unsigned char x) {
110 return stdc_first_trailing_zero_uc(x);
112 inline unsigned stdc_first_trailing_zero(unsigned short x) {
113 return stdc_first_trailing_zero_us(x);
115 inline unsigned stdc_first_trailing_zero(unsigned x) {
116 return stdc_first_trailing_zero_ui(x);
118 inline unsigned stdc_first_trailing_zero(unsigned long x) {
119 return stdc_first_trailing_zero_ul(x);
121 inline unsigned stdc_first_trailing_zero(unsigned long long x) {
122 return stdc_first_trailing_zero_ull(x);
124 inline unsigned stdc_first_trailing_one(unsigned char x) {
125 return stdc_first_trailing_one_uc(x);
127 inline unsigned stdc_first_trailing_one(unsigned short x) {
128 return stdc_first_trailing_one_us(x);
130 inline unsigned stdc_first_trailing_one(unsigned x) {
131 return stdc_first_trailing_one_ui(x);
133 inline unsigned stdc_first_trailing_one(unsigned long x) {
134 return stdc_first_trailing_one_ul(x);
136 inline unsigned stdc_first_trailing_one(unsigned long long x) {
137 return stdc_first_trailing_one_ull(x);
139 inline unsigned stdc_count_zeros(unsigned char x) {
140 return stdc_count_zeros_uc(x);
142 inline unsigned stdc_count_zeros(unsigned short x) {
143 return stdc_count_zeros_us(x);
145 inline unsigned stdc_count_zeros(unsigned x) { return stdc_count_zeros_ui(x); }
146 inline unsigned stdc_count_zeros(unsigned long x) {
147 return stdc_count_zeros_ul(x);
149 inline unsigned stdc_count_zeros(unsigned long long x) {
150 return stdc_count_zeros_ull(x);
152 inline unsigned stdc_count_ones(unsigned char x) {
153 return stdc_count_ones_uc(x);
155 inline unsigned stdc_count_ones(unsigned short x) {
156 return stdc_count_ones_us(x);
158 inline unsigned stdc_count_ones(unsigned x) { return stdc_count_ones_ui(x); }
159 inline unsigned stdc_count_ones(unsigned long x) {
160 return stdc_count_ones_ul(x);
162 inline unsigned stdc_count_ones(unsigned long long x) {
163 return stdc_count_ones_ull(x);
165 inline bool stdc_has_single_bit(unsigned char x) {
166 return stdc_has_single_bit_uc(x);
168 inline bool stdc_has_single_bit(unsigned short x) {
169 return stdc_has_single_bit_us(x);
171 inline bool stdc_has_single_bit(unsigned x) {
172 return stdc_has_single_bit_ui(x);
174 inline bool stdc_has_single_bit(unsigned long x) {
175 return stdc_has_single_bit_ul(x);
177 inline bool stdc_has_single_bit(unsigned long long x) {
178 return stdc_has_single_bit_ull(x);
180 inline unsigned stdc_bit_width(unsigned char x) { return stdc_bit_width_uc(x); }
181 inline unsigned stdc_bit_width(unsigned short x) {
182 return stdc_bit_width_us(x);
184 inline unsigned stdc_bit_width(unsigned x) { return stdc_bit_width_ui(x); }
185 inline unsigned stdc_bit_width(unsigned long x) { return stdc_bit_width_ul(x); }
186 inline unsigned stdc_bit_width(unsigned long long x) {
187 return stdc_bit_width_ull(x);
189 inline unsigned char stdc_bit_floor(unsigned char x) {
190 return stdc_bit_floor_uc(x);
192 inline unsigned short stdc_bit_floor(unsigned short x) {
193 return stdc_bit_floor_us(x);
195 inline unsigned stdc_bit_floor(unsigned x) { return stdc_bit_floor_ui(x); }
196 inline unsigned long stdc_bit_floor(unsigned long x) {
197 return stdc_bit_floor_ul(x);
199 inline unsigned long long stdc_bit_floor(unsigned long long x) {
200 return stdc_bit_floor_ull(x);
202 inline unsigned char stdc_bit_ceil(unsigned char x) {
203 return stdc_bit_ceil_uc(x);
205 inline unsigned short stdc_bit_ceil(unsigned short x) {
206 return stdc_bit_ceil_us(x);
208 inline unsigned stdc_bit_ceil(unsigned x) { return stdc_bit_ceil_ui(x); }
209 inline unsigned long stdc_bit_ceil(unsigned long x) {
210 return stdc_bit_ceil_ul(x);
212 inline unsigned long long stdc_bit_ceil(unsigned long long x) {
213 return stdc_bit_ceil_ull(x);
215 #else
216 #define stdc_leading_zeros(x) \
217 _Generic((x), \
218 unsigned char: stdc_leading_zeros_uc, \
219 unsigned short: stdc_leading_zeros_us, \
220 unsigned: stdc_leading_zeros_ui, \
221 unsigned long: stdc_leading_zeros_ul, \
222 unsigned long long: stdc_leading_zeros_ull)(x)
223 #define stdc_leading_ones(x) \
224 _Generic((x), \
225 unsigned char: stdc_leading_ones_uc, \
226 unsigned short: stdc_leading_ones_us, \
227 unsigned: stdc_leading_ones_ui, \
228 unsigned long: stdc_leading_ones_ul, \
229 unsigned long long: stdc_leading_ones_ull)(x)
230 #define stdc_trailing_zeros(x) \
231 _Generic((x), \
232 unsigned char: stdc_trailing_zeros_uc, \
233 unsigned short: stdc_trailing_zeros_us, \
234 unsigned: stdc_trailing_zeros_ui, \
235 unsigned long: stdc_trailing_zeros_ul, \
236 unsigned long long: stdc_trailing_zeros_ull)(x)
237 #define stdc_trailing_ones(x) \
238 _Generic((x), \
239 unsigned char: stdc_trailing_ones_uc, \
240 unsigned short: stdc_trailing_ones_us, \
241 unsigned: stdc_trailing_ones_ui, \
242 unsigned long: stdc_trailing_ones_ul, \
243 unsigned long long: stdc_trailing_ones_ull)(x)
244 #define stdc_first_leading_zero(x) \
245 _Generic((x), \
246 unsigned char: stdc_first_leading_zero_uc, \
247 unsigned short: stdc_first_leading_zero_us, \
248 unsigned: stdc_first_leading_zero_ui, \
249 unsigned long: stdc_first_leading_zero_ul, \
250 unsigned long long: stdc_first_leading_zero_ull)(x)
251 #define stdc_first_leading_one(x) \
252 _Generic((x), \
253 unsigned char: stdc_first_leading_one_uc, \
254 unsigned short: stdc_first_leading_one_us, \
255 unsigned: stdc_first_leading_one_ui, \
256 unsigned long: stdc_first_leading_one_ul, \
257 unsigned long long: stdc_first_leading_one_ull)(x)
258 #define stdc_first_trailing_zero(x) \
259 _Generic((x), \
260 unsigned char: stdc_first_trailing_zero_uc, \
261 unsigned short: stdc_first_trailing_zero_us, \
262 unsigned: stdc_first_trailing_zero_ui, \
263 unsigned long: stdc_first_trailing_zero_ul, \
264 unsigned long long: stdc_first_trailing_zero_ull)(x)
265 #define stdc_first_trailing_one(x) \
266 _Generic((x), \
267 unsigned char: stdc_first_trailing_one_uc, \
268 unsigned short: stdc_first_trailing_one_us, \
269 unsigned: stdc_first_trailing_one_ui, \
270 unsigned long: stdc_first_trailing_one_ul, \
271 unsigned long long: stdc_first_trailing_one_ull)(x)
272 #define stdc_count_zeros(x) \
273 _Generic((x), \
274 unsigned char: stdc_count_zeros_uc, \
275 unsigned short: stdc_count_zeros_us, \
276 unsigned: stdc_count_zeros_ui, \
277 unsigned long: stdc_count_zeros_ul, \
278 unsigned long long: stdc_count_zeros_ull)(x)
279 #define stdc_count_ones(x) \
280 _Generic((x), \
281 unsigned char: stdc_count_ones_uc, \
282 unsigned short: stdc_count_ones_us, \
283 unsigned: stdc_count_ones_ui, \
284 unsigned long: stdc_count_ones_ul, \
285 unsigned long long: stdc_count_ones_ull)(x)
286 #define stdc_has_single_bit(x) \
287 _Generic((x), \
288 unsigned char: stdc_has_single_bit_uc, \
289 unsigned short: stdc_has_single_bit_us, \
290 unsigned: stdc_has_single_bit_ui, \
291 unsigned long: stdc_has_single_bit_ul, \
292 unsigned long long: stdc_has_single_bit_ull)(x)
293 #define stdc_bit_width(x) \
294 _Generic((x), \
295 unsigned char: stdc_bit_width_uc, \
296 unsigned short: stdc_bit_width_us, \
297 unsigned: stdc_bit_width_ui, \
298 unsigned long: stdc_bit_width_ul, \
299 unsigned long long: stdc_bit_width_ull)(x)
300 #define stdc_bit_floor(x) \
301 _Generic((x), \
302 unsigned char: stdc_bit_floor_uc, \
303 unsigned short: stdc_bit_floor_us, \
304 unsigned: stdc_bit_floor_ui, \
305 unsigned long: stdc_bit_floor_ul, \
306 unsigned long long: stdc_bit_floor_ull)(x)
307 #define stdc_bit_ceil(x) \
308 _Generic((x), \
309 unsigned char: stdc_bit_ceil_uc, \
310 unsigned short: stdc_bit_ceil_us, \
311 unsigned: stdc_bit_ceil_ui, \
312 unsigned long: stdc_bit_ceil_ul, \
313 unsigned long long: stdc_bit_ceil_ull)(x)
314 #endif // __cplusplus
316 #endif // __LLVM_LIBC_MACROS_STDBIT_MACROS_H