1 /* $NetBSD: cdefs.h,v 1.42 2001/11/23 10:19:47 enami Exp $ */ 2 3 /* 4 * Copyright (c) 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Berkeley Software Design, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 39 */ 40 41 #ifndef _SYS_CDEFS_H_ 42 #define _SYS_CDEFS_H_ 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 #if defined(__cplusplus) 71 #define __BEGIN_DECLS extern "C" { 72 #define __END_DECLS }; 73 #define __static_cast(x,y) static_cast<x>(y) 74 #else 75 #define __BEGIN_DECLS 76 #define __END_DECLS 77 #define __static_cast(x,y) (x)y 78 #endif 79 80 /* 81 * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 82 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 83 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 84 * in between its arguments. __CONCAT can also concatenate double-quoted 85 * strings produced by the __STRING macro, but this only works with ANSI C. 86 */ 87 88 #define ___STRING(x) __STRING(x) 89 #define ___CONCAT(x,y) __CONCAT(x,y) 90 91 #if __STDC__ || defined(__cplusplus) 92 #define __P(protos) protos /* full-blown ANSI C */ 93 #define __CONCAT(x,y) x ## y 94 #define __STRING(x) #x 95 96 #define __const const /* define reserved names to standard */ 97 #define __signed signed 98 #define __volatile volatile 99 #if defined(__cplusplus) 100 #define __inline inline /* convert to C++ keyword */ 101 #else 102 #if !defined(__GNUC__) && !defined(__lint__) 103 #define __inline /* delete GCC keyword */ 104 #endif /* !__GNUC__ && !__lint__ */ 105 #endif /* !__cplusplus */ 106 107 #else /* !(__STDC__ || __cplusplus) */ 108 #define __P(protos) () /* traditional C preprocessor */ 109 #define __CONCAT(x,y) x/**/y 110 #define __STRING(x) "x" 111 112 #ifndef __GNUC__ 113 #define __const /* delete pseudo-ANSI C keywords */ 114 #define __inline 115 #define __signed 116 #define __volatile 117 #endif /* !__GNUC__ */ 118 119 /* 120 * In non-ANSI C environments, new programs will want ANSI-only C keywords 121 * deleted from the program and old programs will want them left alone. 122 * Programs using the ANSI C keywords const, inline etc. as normal 123 * identifiers should define -DNO_ANSI_KEYWORDS. 124 */ 125 #ifndef NO_ANSI_KEYWORDS 126 #define const __const /* convert ANSI C keywords */ 127 #define inline __inline 128 #define signed __signed 129 #define volatile __volatile 130 #endif /* !NO_ANSI_KEYWORDS */ 131 #endif /* !(__STDC__ || __cplusplus) */ 132 133 /* 134 * Used for internal auditing of the NetBSD source tree. 135 */ 136 #ifdef __AUDIT__ 137 #define __aconst __const 138 #else 139 #define __aconst 140 #endif 141 142 /* 143 * GCC2 provides __extension__ to suppress warnings for various GNU C 144 * language extensions under "-ansi -pedantic". 145 */ 146 #if !__GNUC_PREREQ__(2, 0) 147 #define __extension__ /* delete __extension__ if non-gcc or gcc1 */ 148 #endif 149 150 /* 151 * GCC1 and some versions of GCC2 declare dead (non-returning) and 152 * pure (no side effects) functions using "volatile" and "const"; 153 * unfortunately, these then cause warnings under "-ansi -pedantic". 154 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of 155 * these work for GNU C++ (modulo a slight glitch in the C++ grammar 156 * in the distribution version of 2.5.5). 157 */ 158 #if !__GNUC_PREREQ__(2, 5) 159 #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ 160 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 161 #define __dead __volatile 162 #define __pure __const 163 #endif 164 #endif 165 166 /* Delete pseudo-keywords wherever they are not available or needed. */ 167 #ifndef __dead 168 #define __dead 169 #define __pure 170 #endif 171 172 /* 173 * C99 defines the restrict type qualifier keyword, which was made available 174 * in GCC 2.92. 175 */ 176 #if __STDC_VERSION__ >= 199901L 177 #define __restrict restrict 178 #else 179 #if !__GNUC_PREREQ__(2, 92) 180 #define __restrict /* delete __restrict when not supported */ 181 #endif 182 #endif 183 184 /* 185 * C99 defines __func__ predefined identifier, which was made available 186 * in GCC 2.95. 187 */ 188 #if !(__STDC_VERSION__ >= 199901L) 189 #if __GNUC_PREREQ__(2, 6) 190 #define __func__ __PRETTY_FUNCTION__ 191 #elif __GNUC_PREREQ__(2, 4) 192 #define __func__ __FUNCTION__ 193 #else 194 #define __func__ "" 195 #endif 196 #endif /* !(__STDC_VERSION__ >= 199901L) */ 197 198 #if defined(_KERNEL) 199 #if defined(NO_KERNEL_RCSIDS) 200 #undef __KERNEL_RCSID 201 #define __KERNEL_RCSID(_n, _s) /* nothing */ 202 #endif /* NO_KERNEL_RCSIDS */ 203 #endif /* _KERNEL */ 204 205 #if !defined(_STANDALONE) && !defined(_KERNEL) 206 #ifdef __GNUC__ 207 #define __RENAME(x) ___RENAME(x) 208 #else 209 #ifdef __lint__ 210 #define __RENAME(x) __symbolrename(x) 211 #else 212 #error "No function renaming possible" 213 #endif /* __lint__ */ 214 #endif /* __GNUC__ */ 215 #else /* _STANDALONE || _KERNEL */ 216 #define __RENAME(x) no renaming in kernel or standalone environment 217 #endif 218 219 /* 220 * GNU C version 2.96 adds explicit branch prediction so that 221 * the CPU back-end can hint the processor and also so that 222 * code blocks can be reordered such that the predicted path 223 * sees a more linear flow, thus improving cache behavior, etc. 224 * 225 * The following two macros provide us with a way to utilize this 226 * compiler feature. Use __predict_true() if you expect the expression 227 * to evaluate to true, and __predict_false() if you expect the 228 * expression to evaluate to false. 229 * 230 * A few notes about usage: 231 * 232 * * Generally, __predict_false() error condition checks (unless 233 * you have some _strong_ reason to do otherwise, in which case 234 * document it), and/or __predict_true() `no-error' condition 235 * checks, assuming you want to optimize for the no-error case. 236 * 237 * * Other than that, if you don't know the likelihood of a test 238 * succeeding from empirical or other `hard' evidence, don't 239 * make predictions. 240 * 241 * * These are meant to be used in places that are run `a lot'. 242 * It is wasteful to make predictions in code that is run 243 * seldomly (e.g. at subsystem initialization time) as the 244 * basic block reordering that this affects can often generate 245 * larger code. 246 */ 247 #if __GNUC_PREREQ__(2, 96) 248 #define __predict_true(exp) __builtin_expect(((exp) != 0), 1) 249 #define __predict_false(exp) __builtin_expect(((exp) != 0), 0) 250 #else 251 #define __predict_true(exp) ((exp) != 0) 252 #define __predict_false(exp) ((exp) != 0) 253 #endif 254 255 #endif /* !_SYS_CDEFS_H_ */ 256