1 | /* $NetBSD: cdefs.h,v 1.128 2015/11/19 17:04:01 christos Exp $ */ |
2 | |
3 | /* * Copyright (c) 1991, 1993 |
4 | * The Regents of the University of California. All rights reserved. |
5 | * |
6 | * This code is derived from software contributed to Berkeley by |
7 | * Berkeley Software Design, Inc. |
8 | * |
9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions |
11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in the |
16 | * documentation and/or other materials provided with the distribution. |
17 | * 3. Neither the name of the University nor the names of its contributors |
18 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. |
20 | * |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | * SUCH DAMAGE. |
32 | * |
33 | * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 |
34 | */ |
35 | |
36 | #ifndef _SYS_CDEFS_H_ |
37 | #define _SYS_CDEFS_H_ |
38 | |
39 | #ifdef _KERNEL_OPT |
40 | #include "opt_diagnostic.h" |
41 | #endif |
42 | |
43 | /* |
44 | * Macro to test if we're using a GNU C compiler of a specific vintage |
45 | * or later, for e.g. features that appeared in a particular version |
46 | * of GNU C. Usage: |
47 | * |
48 | * #if __GNUC_PREREQ__(major, minor) |
49 | * ...cool feature... |
50 | * #else |
51 | * ...delete feature... |
52 | * #endif |
53 | */ |
54 | #ifdef __GNUC__ |
55 | #define __GNUC_PREREQ__(x, y) \ |
56 | ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ |
57 | (__GNUC__ > (x))) |
58 | #else |
59 | #define __GNUC_PREREQ__(x, y) 0 |
60 | #endif |
61 | |
62 | #include <machine/cdefs.h> |
63 | #ifdef __ELF__ |
64 | #include <sys/cdefs_elf.h> |
65 | #else |
66 | #include <sys/cdefs_aout.h> |
67 | #endif |
68 | |
69 | #ifdef __GNUC__ |
70 | #define __strict_weak_alias(alias,sym) \ |
71 | __unused static __typeof__(alias) *__weak_alias_##alias = &sym; \ |
72 | __weak_alias(alias,sym) |
73 | #else |
74 | #define __strict_weak_alias(alias,sym) __weak_alias(alias,sym) |
75 | #endif |
76 | |
77 | /* |
78 | * Optional marker for size-optimised MD calling convention. |
79 | */ |
80 | #ifndef __compactcall |
81 | #define __compactcall |
82 | #endif |
83 | |
84 | /* |
85 | * The __CONCAT macro is used to concatenate parts of symbol names, e.g. |
86 | * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. |
87 | * The __CONCAT macro is a bit tricky -- make sure you don't put spaces |
88 | * in between its arguments. __CONCAT can also concatenate double-quoted |
89 | * strings produced by the __STRING macro, but this only works with ANSI C. |
90 | */ |
91 | |
92 | #define ___STRING(x) __STRING(x) |
93 | #define ___CONCAT(x,y) __CONCAT(x,y) |
94 | |
95 | #if __STDC__ || defined(__cplusplus) |
96 | #define __P(protos) protos /* full-blown ANSI C */ |
97 | #define __CONCAT(x,y) x ## y |
98 | #define __STRING(x) #x |
99 | |
100 | #define __const const /* define reserved names to standard */ |
101 | #define __signed signed |
102 | #define __volatile volatile |
103 | #if defined(__cplusplus) || defined(__PCC__) |
104 | #define __inline inline /* convert to C++/C99 keyword */ |
105 | #else |
106 | #if !defined(__GNUC__) && !defined(__lint__) |
107 | #define __inline /* delete GCC keyword */ |
108 | #endif /* !__GNUC__ && !__lint__ */ |
109 | #endif /* !__cplusplus */ |
110 | |
111 | #else /* !(__STDC__ || __cplusplus) */ |
112 | #define __P(protos) () /* traditional C preprocessor */ |
113 | #define __CONCAT(x,y) x/**/y |
114 | #define __STRING(x) "x" |
115 | |
116 | #ifndef __GNUC__ |
117 | #define __const /* delete pseudo-ANSI C keywords */ |
118 | #define __inline |
119 | #define __signed |
120 | #define __volatile |
121 | #endif /* !__GNUC__ */ |
122 | |
123 | /* |
124 | * In non-ANSI C environments, new programs will want ANSI-only C keywords |
125 | * deleted from the program and old programs will want them left alone. |
126 | * Programs using the ANSI C keywords const, inline etc. as normal |
127 | * identifiers should define -DNO_ANSI_KEYWORDS. |
128 | */ |
129 | #ifndef NO_ANSI_KEYWORDS |
130 | #define const __const /* convert ANSI C keywords */ |
131 | #define inline __inline |
132 | #define signed __signed |
133 | #define volatile __volatile |
134 | #endif /* !NO_ANSI_KEYWORDS */ |
135 | #endif /* !(__STDC__ || __cplusplus) */ |
136 | |
137 | /* |
138 | * Used for internal auditing of the NetBSD source tree. |
139 | */ |
140 | #ifdef __AUDIT__ |
141 | #define __aconst __const |
142 | #else |
143 | #define __aconst |
144 | #endif |
145 | |
146 | /* |
147 | * Compile Time Assertion. |
148 | */ |
149 | #ifdef __COUNTER__ |
150 | #define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__) |
151 | #else |
152 | #define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__) |
153 | #define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \ |
154 | __CONCAT(_,b)) |
155 | #endif |
156 | #define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z) |
157 | #define __CTASSERT1(x, y, z) typedef char y ## z[/*CONSTCOND*/(x) ? 1 : -1] __unused |
158 | |
159 | /* |
160 | * The following macro is used to remove const cast-away warnings |
161 | * from gcc -Wcast-qual; it should be used with caution because it |
162 | * can hide valid errors; in particular most valid uses are in |
163 | * situations where the API requires it, not to cast away string |
164 | * constants. We don't use *intptr_t on purpose here and we are |
165 | * explicit about unsigned long so that we don't have additional |
166 | * dependencies. |
167 | */ |
168 | #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) |
169 | |
170 | /* |
171 | * The following macro is used to remove the volatile cast-away warnings |
172 | * from gcc -Wcast-qual; as above it should be used with caution |
173 | * because it can hide valid errors or warnings. Valid uses include |
174 | * making it possible to pass a volatile pointer to memset(). |
175 | * For the same reasons as above, we use unsigned long and not intptr_t. |
176 | */ |
177 | #define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) |
178 | |
179 | /* |
180 | * GCC2 provides __extension__ to suppress warnings for various GNU C |
181 | * language extensions under "-ansi -pedantic". |
182 | */ |
183 | #if !__GNUC_PREREQ__(2, 0) |
184 | #define __extension__ /* delete __extension__ if non-gcc or gcc1 */ |
185 | #endif |
186 | |
187 | /* |
188 | * GCC1 and some versions of GCC2 declare dead (non-returning) and |
189 | * pure (no side effects) functions using "volatile" and "const"; |
190 | * unfortunately, these then cause warnings under "-ansi -pedantic". |
191 | * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of |
192 | * these work for GNU C++ (modulo a slight glitch in the C++ grammar |
193 | * in the distribution version of 2.5.5). |
194 | * |
195 | * GCC defines a pure function as depending only on its arguments and |
196 | * global variables. Typical examples are strlen and sqrt. |
197 | * |
198 | * GCC defines a const function as depending only on its arguments. |
199 | * Therefore calling a const function again with identical arguments |
200 | * will always produce the same result. |
201 | * |
202 | * Rounding modes for floating point operations are considered global |
203 | * variables and prevent sqrt from being a const function. |
204 | * |
205 | * Calls to const functions can be optimised away and moved around |
206 | * without limitations. |
207 | */ |
208 | #if !__GNUC_PREREQ__(2, 0) |
209 | #define __attribute__(x) |
210 | #endif |
211 | |
212 | #if __GNUC_PREREQ__(2, 5) |
213 | #define __dead __attribute__((__noreturn__)) |
214 | #elif defined(__GNUC__) |
215 | #define __dead __volatile |
216 | #else |
217 | #define __dead |
218 | #endif |
219 | |
220 | #if __GNUC_PREREQ__(2, 96) |
221 | #define __pure __attribute__((__pure__)) |
222 | #elif defined(__GNUC__) |
223 | #define __pure __const |
224 | #else |
225 | #define __pure |
226 | #endif |
227 | |
228 | #if __GNUC_PREREQ__(2, 5) |
229 | #define __constfunc __attribute__((__const__)) |
230 | #else |
231 | #define __constfunc |
232 | #endif |
233 | |
234 | #if __GNUC_PREREQ__(3, 0) |
235 | #define __noinline __attribute__((__noinline__)) |
236 | #else |
237 | #define __noinline /* nothing */ |
238 | #endif |
239 | |
240 | #if __GNUC_PREREQ__(3, 0) |
241 | #define __always_inline __attribute__((__always_inline__)) |
242 | #else |
243 | #define __always_inline /* nothing */ |
244 | #endif |
245 | |
246 | #if __GNUC_PREREQ__(4, 1) |
247 | #define __returns_twice __attribute__((__returns_twice__)) |
248 | #else |
249 | #define __returns_twice /* nothing */ |
250 | #endif |
251 | |
252 | #if __GNUC_PREREQ__(4, 5) |
253 | #define __noclone __attribute__((__noclone__)) |
254 | #else |
255 | #define __noclone /* nothing */ |
256 | #endif |
257 | |
258 | /* |
259 | * __unused: Note that item or function might be unused. |
260 | */ |
261 | #if __GNUC_PREREQ__(2, 7) |
262 | #define __unused __attribute__((__unused__)) |
263 | #else |
264 | #define __unused /* delete */ |
265 | #endif |
266 | |
267 | /* |
268 | * __used: Note that item is needed, even if it appears to be unused. |
269 | */ |
270 | #if __GNUC_PREREQ__(3, 1) |
271 | #define __used __attribute__((__used__)) |
272 | #else |
273 | #define __used __unused |
274 | #endif |
275 | |
276 | /* |
277 | * __diagused: Note that item is used in diagnostic code, but may be |
278 | * unused in non-diagnostic code. |
279 | */ |
280 | #if (defined(_KERNEL) && defined(DIAGNOSTIC)) \ |
281 | || (!defined(_KERNEL) && !defined(NDEBUG)) |
282 | #define __diagused /* empty */ |
283 | #else |
284 | #define __diagused __unused |
285 | #endif |
286 | |
287 | /* |
288 | * __debugused: Note that item is used in debug code, but may be |
289 | * unused in non-debug code. |
290 | */ |
291 | #if defined(DEBUG) |
292 | #define __debugused /* empty */ |
293 | #else |
294 | #define __debugused __unused |
295 | #endif |
296 | |
297 | #if __GNUC_PREREQ__(3, 1) |
298 | #define __noprofile __attribute__((__no_instrument_function__)) |
299 | #else |
300 | #define __noprofile /* nothing */ |
301 | #endif |
302 | |
303 | #if __GNUC_PREREQ__(4, 6) || defined(__clang__) |
304 | #define __unreachable() __builtin_unreachable() |
305 | #else |
306 | #define __unreachable() do {} while (/*CONSTCOND*/0) |
307 | #endif |
308 | |
309 | #if defined(__cplusplus) |
310 | #define __BEGIN_EXTERN_C extern "C" { |
311 | #define __END_EXTERN_C } |
312 | #define __static_cast(x,y) static_cast<x>(y) |
313 | #else |
314 | #define __BEGIN_EXTERN_C |
315 | #define __END_EXTERN_C |
316 | #define __static_cast(x,y) (x)y |
317 | #endif |
318 | |
319 | #if __GNUC_PREREQ__(4, 0) |
320 | # define __dso_public __attribute__((__visibility__("default"))) |
321 | # define __dso_hidden __attribute__((__visibility__("hidden"))) |
322 | # define __BEGIN_PUBLIC_DECLS \ |
323 | _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C |
324 | # define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") |
325 | # define __BEGIN_HIDDEN_DECLS \ |
326 | _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C |
327 | # define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") |
328 | #else |
329 | # define __dso_public |
330 | # define __dso_hidden |
331 | # define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C |
332 | # define __END_PUBLIC_DECLS __END_EXTERN_C |
333 | # define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C |
334 | # define __END_HIDDEN_DECLS __END_EXTERN_C |
335 | #endif |
336 | #if __GNUC_PREREQ__(4, 2) |
337 | # define __dso_protected __attribute__((__visibility__("protected"))) |
338 | #else |
339 | # define __dso_protected |
340 | #endif |
341 | |
342 | #define __BEGIN_DECLS __BEGIN_PUBLIC_DECLS |
343 | #define __END_DECLS __END_PUBLIC_DECLS |
344 | |
345 | /* |
346 | * Non-static C99 inline functions are optional bodies. They don't |
347 | * create global symbols if not used, but can be replaced if desirable. |
348 | * This differs from the behavior of GCC before version 4.3. The nearest |
349 | * equivalent for older GCC is `extern inline'. For newer GCC, use the |
350 | * gnu_inline attribute additionally to get the old behavior. |
351 | * |
352 | * For C99 compilers other than GCC, the C99 behavior is expected. |
353 | */ |
354 | #if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) |
355 | #define __c99inline extern __attribute__((__gnu_inline__)) __inline |
356 | #elif defined(__GNUC__) |
357 | #define __c99inline extern __inline |
358 | #elif defined(__STDC_VERSION__) |
359 | #define __c99inline __inline |
360 | #endif |
361 | |
362 | #if defined(__lint__) |
363 | #define __packed __packed |
364 | #define __aligned(x) /* delete */ |
365 | #define __section(x) /* delete */ |
366 | #elif __GNUC_PREREQ__(2, 7) || defined(__PCC__) |
367 | #define __packed __attribute__((__packed__)) |
368 | #define __aligned(x) __attribute__((__aligned__(x))) |
369 | #define __section(x) __attribute__((__section__(x))) |
370 | #elif defined(_MSC_VER) |
371 | #define __packed /* ignore */ |
372 | #else |
373 | #define __packed error: no __packed for this compiler |
374 | #define __aligned(x) error: no __aligned for this compiler |
375 | #define __section(x) error: no __section for this compiler |
376 | #endif |
377 | |
378 | /* |
379 | * C99 defines the restrict type qualifier keyword, which was made available |
380 | * in GCC 2.92. |
381 | */ |
382 | #if defined(__lint__) |
383 | #define __restrict /* delete __restrict when not supported */ |
384 | #elif __STDC_VERSION__ >= 199901L |
385 | #define __restrict restrict |
386 | #elif __GNUC_PREREQ__(2, 92) |
387 | #define __restrict __restrict__ |
388 | #else |
389 | #define __restrict /* delete __restrict when not supported */ |
390 | #endif |
391 | |
392 | /* |
393 | * C99 defines __func__ predefined identifier, which was made available |
394 | * in GCC 2.95. |
395 | */ |
396 | #if !(__STDC_VERSION__ >= 199901L) |
397 | #if __GNUC_PREREQ__(2, 6) |
398 | #define __func__ __PRETTY_FUNCTION__ |
399 | #elif __GNUC_PREREQ__(2, 4) |
400 | #define __func__ __FUNCTION__ |
401 | #else |
402 | #define __func__ "" |
403 | #endif |
404 | #endif /* !(__STDC_VERSION__ >= 199901L) */ |
405 | |
406 | #if defined(_KERNEL) |
407 | #if defined(NO_KERNEL_RCSIDS) |
408 | #undef __KERNEL_RCSID |
409 | #define __KERNEL_RCSID(_n, _s) /* nothing */ |
410 | #endif /* NO_KERNEL_RCSIDS */ |
411 | #endif /* _KERNEL */ |
412 | |
413 | #if !defined(_STANDALONE) && !defined(_KERNEL) |
414 | #if defined(__GNUC__) || defined(__PCC__) |
415 | #define __RENAME(x) ___RENAME(x) |
416 | #elif defined(__lint__) |
417 | #define __RENAME(x) __symbolrename(x) |
418 | #else |
419 | #error "No function renaming possible" |
420 | #endif /* __GNUC__ */ |
421 | #else /* _STANDALONE || _KERNEL */ |
422 | #define __RENAME(x) no renaming in kernel/standalone environment |
423 | #endif |
424 | |
425 | /* |
426 | * A barrier to stop the optimizer from moving code or assume live |
427 | * register values. This is gcc specific, the version is more or less |
428 | * arbitrary, might work with older compilers. |
429 | */ |
430 | #if __GNUC_PREREQ__(2, 95) |
431 | #define __insn_barrier() __asm __volatile("":::"memory") |
432 | #else |
433 | #define __insn_barrier() /* */ |
434 | #endif |
435 | |
436 | /* |
437 | * GNU C version 2.96 adds explicit branch prediction so that |
438 | * the CPU back-end can hint the processor and also so that |
439 | * code blocks can be reordered such that the predicted path |
440 | * sees a more linear flow, thus improving cache behavior, etc. |
441 | * |
442 | * The following two macros provide us with a way to use this |
443 | * compiler feature. Use __predict_true() if you expect the expression |
444 | * to evaluate to true, and __predict_false() if you expect the |
445 | * expression to evaluate to false. |
446 | * |
447 | * A few notes about usage: |
448 | * |
449 | * * Generally, __predict_false() error condition checks (unless |
450 | * you have some _strong_ reason to do otherwise, in which case |
451 | * document it), and/or __predict_true() `no-error' condition |
452 | * checks, assuming you want to optimize for the no-error case. |
453 | * |
454 | * * Other than that, if you don't know the likelihood of a test |
455 | * succeeding from empirical or other `hard' evidence, don't |
456 | * make predictions. |
457 | * |
458 | * * These are meant to be used in places that are run `a lot'. |
459 | * It is wasteful to make predictions in code that is run |
460 | * seldomly (e.g. at subsystem initialization time) as the |
461 | * basic block reordering that this affects can often generate |
462 | * larger code. |
463 | */ |
464 | #if __GNUC_PREREQ__(2, 96) |
465 | #define __predict_true(exp) __builtin_expect((exp) != 0, 1) |
466 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) |
467 | #else |
468 | #define __predict_true(exp) (exp) |
469 | #define __predict_false(exp) (exp) |
470 | #endif |
471 | |
472 | /* |
473 | * Compiler-dependent macros to declare that functions take printf-like |
474 | * or scanf-like arguments. They are null except for versions of gcc |
475 | * that are known to support the features properly (old versions of gcc-2 |
476 | * didn't permit keeping the keywords out of the application namespace). |
477 | */ |
478 | #if __GNUC_PREREQ__(2, 7) |
479 | #define __printflike(fmtarg, firstvararg) \ |
480 | __attribute__((__format__ (__printf__, fmtarg, firstvararg))) |
481 | #ifndef __syslog_attribute__ |
482 | #define __syslog__ __printf__ |
483 | #endif |
484 | #define __sysloglike(fmtarg, firstvararg) \ |
485 | __attribute__((__format__ (__syslog__, fmtarg, firstvararg))) |
486 | #define __scanflike(fmtarg, firstvararg) \ |
487 | __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) |
488 | #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) |
489 | #else |
490 | #define __printflike(fmtarg, firstvararg) /* nothing */ |
491 | #define __scanflike(fmtarg, firstvararg) /* nothing */ |
492 | #define __sysloglike(fmtarg, firstvararg) /* nothing */ |
493 | #define __format_arg(fmtarg) /* nothing */ |
494 | #endif |
495 | |
496 | /* |
497 | * Macros for manipulating "link sets". Link sets are arrays of pointers |
498 | * to objects, which are gathered up by the linker. |
499 | * |
500 | * Object format-specific code has provided us with the following macros: |
501 | * |
502 | * __link_set_add_text(set, sym) |
503 | * Add a reference to the .text symbol `sym' to `set'. |
504 | * |
505 | * __link_set_add_rodata(set, sym) |
506 | * Add a reference to the .rodata symbol `sym' to `set'. |
507 | * |
508 | * __link_set_add_data(set, sym) |
509 | * Add a reference to the .data symbol `sym' to `set'. |
510 | * |
511 | * __link_set_add_bss(set, sym) |
512 | * Add a reference to the .bss symbol `sym' to `set'. |
513 | * |
514 | * __link_set_decl(set, ptype) |
515 | * Provide an extern declaration of the set `set', which |
516 | * contains an array of pointers to type `ptype'. This |
517 | * macro must be used by any code which wishes to reference |
518 | * the elements of a link set. |
519 | * |
520 | * __link_set_start(set) |
521 | * This points to the first slot in the link set. |
522 | * |
523 | * __link_set_end(set) |
524 | * This points to the (non-existent) slot after the last |
525 | * entry in the link set. |
526 | * |
527 | * __link_set_count(set) |
528 | * Count the number of entries in link set `set'. |
529 | * |
530 | * In addition, we provide the following macros for accessing link sets: |
531 | * |
532 | * __link_set_foreach(pvar, set) |
533 | * Iterate over the link set `set'. Because a link set is |
534 | * an array of pointers, pvar must be declared as "type **pvar", |
535 | * and the actual entry accessed as "*pvar". |
536 | * |
537 | * __link_set_entry(set, idx) |
538 | * Access the link set entry at index `idx' from set `set'. |
539 | */ |
540 | #define __link_set_foreach(pvar, set) \ |
541 | for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) |
542 | |
543 | #define __link_set_entry(set, idx) (__link_set_start(set)[idx]) |
544 | |
545 | /* |
546 | * Return the natural alignment in bytes for the given type |
547 | */ |
548 | #if __GNUC_PREREQ__(4, 1) |
549 | #define __alignof(__t) __alignof__(__t) |
550 | #else |
551 | #define __alignof(__t) (sizeof(struct { char __x; __t __y; }) - sizeof(__t)) |
552 | #endif |
553 | |
554 | /* |
555 | * Return the number of elements in a statically-allocated array, |
556 | * __x. |
557 | */ |
558 | #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) |
559 | |
560 | #ifndef __ASSEMBLER__ |
561 | /* __BIT(n): nth bit, where __BIT(0) == 0x1. */ |
562 | #define __BIT(__n) \ |
563 | (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : \ |
564 | ((uintmax_t)1 << (uintmax_t)((__n) & (NBBY * sizeof(uintmax_t) - 1)))) |
565 | |
566 | /* __BITS(m, n): bits m through n, m < n. */ |
567 | #define __BITS(__m, __n) \ |
568 | ((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1)) |
569 | #endif /* !__ASSEMBLER__ */ |
570 | |
571 | /* find least significant bit that is set */ |
572 | #define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) |
573 | |
574 | #define __PRIuBIT PRIuMAX |
575 | #define __PRIuBITS __PRIuBIT |
576 | |
577 | #define __PRIxBIT PRIxMAX |
578 | #define __PRIxBITS __PRIxBIT |
579 | |
580 | #define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) |
581 | #define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) |
582 | #define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) |
583 | |
584 | /* |
585 | * Only to be used in other headers that are included from both c or c++ |
586 | * NOT to be used in code. |
587 | */ |
588 | #ifdef __cplusplus |
589 | #define __CAST(__dt, __st) static_cast<__dt>(__st) |
590 | #else |
591 | #define __CAST(__dt, __st) ((__dt)(__st)) |
592 | #endif |
593 | |
594 | #define __CASTV(__dt, __st) __CAST(__dt, __CAST(void *, __st)) |
595 | #define __CASTCV(__dt, __st) __CAST(__dt, __CAST(const void *, __st)) |
596 | |
597 | #define __USE(a) ((void)(a)) |
598 | |
599 | #define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \ |
600 | (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL) |
601 | |
602 | #ifndef __ASSEMBLER__ |
603 | static __inline long long __zeroll(void) { return 0; } |
604 | static __inline unsigned long long __zeroull(void) { return 0; } |
605 | #else |
606 | #define __zeroll() (0LL) |
607 | #define __zeroull() (0ULL) |
608 | #endif |
609 | |
610 | #define __negative_p(x) (!((x) > 0) && ((x) != 0)) |
611 | |
612 | #define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1)))) |
613 | #define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1)))) |
614 | #define __type_min_u(t) ((t)0ULL) |
615 | #define __type_max_u(t) ((t)~0ULL) |
616 | #define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1) |
617 | #define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t)) |
618 | #define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t)) |
619 | |
620 | |
621 | #define __type_fit_u(t, a) (/*LINTED*/!__negative_p(a) && \ |
622 | (uintmax_t)((a) + __zeroull()) <= (uintmax_t)__type_max_u(t)) |
623 | |
624 | #define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \ |
625 | ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \ |
626 | ((intmax_t)((a) + __zeroll()) >= (intmax_t)0 && \ |
627 | (intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t))) |
628 | |
629 | /* |
630 | * return true if value 'a' fits in type 't' |
631 | */ |
632 | #define __type_fit(t, a) (__type_is_signed(t) ? \ |
633 | __type_fit_s(t, a) : __type_fit_u(t, a)) |
634 | |
635 | #endif /* !_SYS_CDEFS_H_ */ |
636 | |