xref: /openbsd-src/sys/sys/cdefs.h (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: cdefs.h,v 1.7 2001/08/07 21:33:03 millert Exp $	*/
2 /*	$NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $	*/
3 
4 /*
5  * Copyright (c) 1991, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Berkeley Software Design, Inc.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the University of
22  *	California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *	@(#)cdefs.h	8.7 (Berkeley) 1/21/94
40  */
41 
42 #ifndef	_CDEFS_H_
43 #define	_CDEFS_H_
44 
45 /*
46  * Gratuitous NetBSD gcc extensions we can do without.
47  */
48 
49 #ifdef __KPRINTF_ATTRIBUTE__
50 #undef __KPRINTF_ATTRIBUTE__
51 #endif
52 
53 #include <machine/cdefs.h>
54 
55 #if defined(__cplusplus)
56 #define	__BEGIN_DECLS	extern "C" {
57 #define	__END_DECLS	};
58 #else
59 #define	__BEGIN_DECLS
60 #define	__END_DECLS
61 #endif
62 
63 /*
64  * Macro to test if we're using a specific version of gcc or later.
65  */
66 #ifdef __GNUC__
67 #define __GNUC_PREREQ__(ma, mi) \
68 	((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)))
69 #else
70 #define __GNUC_PREREQ__(ma, mi) 0
71 #endif
72 
73 /*
74  * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
75  * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
76  * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
77  * in between its arguments.  __CONCAT can also concatenate double-quoted
78  * strings produced by the __STRING macro, but this only works with ANSI C.
79  */
80 #if defined(__STDC__) || defined(__cplusplus)
81 #define	__P(protos)	protos		/* full-blown ANSI C */
82 #define	__CONCAT(x,y)	x ## y
83 #define	__STRING(x)	#x
84 
85 #define	__const		const		/* define reserved names to standard */
86 #define	__signed	signed
87 #define	__volatile	volatile
88 #if defined(__cplusplus)
89 #define	__inline	inline		/* convert to C++ keyword */
90 #else
91 #if !defined(__GNUC__) && !defined(lint)
92 #define	__inline			/* delete GCC keyword */
93 #endif /* !__GNUC__ && !lint */
94 #endif /* !__cplusplus */
95 
96 #else	/* !(__STDC__ || __cplusplus) */
97 #define	__P(protos)	()		/* traditional C preprocessor */
98 #define	__CONCAT(x,y)	x/**/y
99 #define	__STRING(x)	"x"
100 
101 #if !defined(__GNUC__) && !defined(lint)
102 #define	__const				/* delete pseudo-ANSI C keywords */
103 #define	__inline
104 #define	__signed
105 #define	__volatile
106 #endif	/* !__GNUC__ && !lint */
107 
108 /*
109  * In non-ANSI C environments, new programs will want ANSI-only C keywords
110  * deleted from the program and old programs will want them left alone.
111  * Programs using the ANSI C keywords const, inline etc. as normal
112  * identifiers should define -DNO_ANSI_KEYWORDS.
113  */
114 #ifndef	NO_ANSI_KEYWORDS
115 #define	const		__const		/* convert ANSI C keywords */
116 #define	inline		__inline
117 #define	signed		__signed
118 #define	volatile	__volatile
119 #endif /* !NO_ANSI_KEYWORDS */
120 #endif	/* !(__STDC__ || __cplusplus) */
121 
122 /*
123  * GCC1 and some versions of GCC2 declare dead (non-returning) and
124  * pure (no side effects) functions using "volatile" and "const";
125  * unfortunately, these then cause warnings under "-ansi -pedantic".
126  * GCC >= 2.5 uses the __attribute__((attrs)) style.  All of these
127  * work for GNU C++ (modulo a slight glitch in the C++ grammar in
128  * the distribution version of 2.5.5).
129  */
130 
131 #if !__GNUC_PREREQ__(2, 5)
132 #define	__attribute__(x)	/* delete __attribute__ if non-gcc or gcc1 */
133 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
134 #define	__dead		__volatile
135 #define	__pure		__const
136 #endif
137 #elif !defined(__STRICT_ANSI__)
138 #define __dead		__attribute__((__noreturn__))
139 #define __pure		__attribute__((__const__))
140 #endif
141 
142 /*
143  * GNU C version 2.96 adds explicit branch prediction so that
144  * the CPU back-end can hint the processor and also so that
145  * code blocks can be reordered such that the predicted path
146  * sees a more linear flow, thus improving cache behavior, etc.
147  *
148  * The following two macros provide us with a way to utilize this
149  * compiler feature.  Use __predict_true() if you expect the expression
150  * to evaluate to true, and __predict_false() if you expect the
151  * expression to evaluate to false.
152  *
153  * A few notes about usage:
154  *
155  *	* Generally, __predict_false() error condition checks (unless
156  *	  you have some _strong_ reason to do otherwise, in which case
157  *	  document it), and/or __predict_true() `no-error' condition
158  *	  checks, assuming you want to optimize for the no-error case.
159  *
160  *	* Other than that, if you don't know the likelihood of a test
161  *	  succeeding from empirical or other `hard' evidence, don't
162  *	  make predictions.
163  *
164  *	* These are meant to be used in places that are run `a lot'.
165  *	  It is wasteful to make predictions in code that is run
166  *	  seldomly (e.g. at subsystem initialization time) as the
167  *	  basic block reordering that this affects can often generate
168  *	  larger code.
169  */
170 #if __GNUC_PREREQ__(2, 96)
171 #define __predict_true(exp)	__builtin_expect(((exp) != 0), 1)
172 #define __predict_false(exp)	__builtin_expect(((exp) != 0), 0)
173 #else
174 #define __predict_true(exp)	((exp) != 0)
175 #define __predict_false(exp)	((exp) != 0)
176 #endif
177 
178 #ifdef __KPRINTF_ATTRIBUTE__
179 #define __kprintf_attribute__(a) __attribute__(a)
180 #else
181 #define __kprintf_attribute__(a)
182 #endif
183 
184 /* Delete pseudo-keywords wherever they are not available or needed. */
185 #ifndef __dead
186 #define	__dead
187 #define	__pure
188 #endif
189 
190 #endif /* !_CDEFS_H_ */
191