Tue Dec 18 16:23:20 2018 UTC ()
Appease gcc error: comparison of unsigned expression < 0 is always false
when using __BITS(u_int, 0)


(skrll)
diff -r1.138 -r1.139 src/sys/sys/cdefs.h

cvs diff -r1.138 -r1.139 src/sys/sys/cdefs.h (switch to unified diff)

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