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