1/*-
2 * Copyright (c) 1991, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Berkeley Software Design, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
33 * $FreeBSD$
34 */
35#ifndef _FBSD_COMPAT_SYS_CDEFS_H_
36#define _FBSD_COMPAT_SYS_CDEFS_H_
37
38
39#include <posix/sys/cdefs.h>
40
41
42#define __FBSDID(str)	static const char __fbsdid[] = str
43
44/*
45 * This code has been put in place to help reduce the addition of
46 * compiler specific defines in FreeBSD code.  It helps to aid in
47 * having a compiler-agnostic source tree.
48 */
49
50#if defined(__GNUC__) || defined(__INTEL_COMPILER)
51
52#if __GNUC__ >= 3 || defined(__INTEL_COMPILER)
53#define __GNUCLIKE_ASM 3
54#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS
55#else
56#define __GNUCLIKE_ASM 2
57#endif
58#define __GNUCLIKE___TYPEOF 1
59#define __GNUCLIKE___OFFSETOF 1
60#define __GNUCLIKE___SECTION 1
61
62#define __GNUCLIKE_ATTRIBUTE_MODE_DI 1
63
64#ifndef __INTEL_COMPILER
65# define __GNUCLIKE_CTOR_SECTION_HANDLING 1
66#endif
67
68#define __GNUCLIKE_BUILTIN_CONSTANT_P 1
69# if defined(__INTEL_COMPILER) && defined(__cplusplus) \
70    && __INTEL_COMPILER < 800
71#  undef __GNUCLIKE_BUILTIN_CONSTANT_P
72# endif
73
74#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER)
75# define __GNUCLIKE_BUILTIN_VARARGS 1
76# define __GNUCLIKE_BUILTIN_STDARG 1
77# define __GNUCLIKE_BUILTIN_VAALIST 1
78#endif
79
80#if defined(__GNUC__)
81# define __GNUC_VA_LIST_COMPATIBILITY 1
82#endif
83
84#ifndef __INTEL_COMPILER
85# define __GNUCLIKE_BUILTIN_NEXT_ARG 1
86# define __GNUCLIKE_MATH_BUILTIN_RELOPS
87#endif
88
89#define __GNUCLIKE_BUILTIN_MEMCPY 1
90
91/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */
92#define __CC_SUPPORTS_INLINE 1
93#define __CC_SUPPORTS___INLINE 1
94#define __CC_SUPPORTS___INLINE__ 1
95
96#define __CC_SUPPORTS___FUNC__ 1
97#define __CC_SUPPORTS_WARNING 1
98
99#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */
100
101#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1
102
103#endif /* __GNUC__ || __INTEL_COMPILER */
104
105
106/*
107 * Macro to test if we're using a specific version of gcc or later.
108 */
109#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
110#define	__GNUC_PREREQ__(ma, mi)	\
111	(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
112#else
113#define	__GNUC_PREREQ__(ma, mi)	0
114#endif
115
116/*
117 * GNU C version 2.96 adds explicit branch prediction so that
118 * the CPU back-end can hint the processor and also so that
119 * code blocks can be reordered such that the predicted path
120 * sees a more linear flow, thus improving cache behavior, etc.
121 *
122 * The following two macros provide us with a way to utilize this
123 * compiler feature.  Use __predict_true() if you expect the expression
124 * to evaluate to true, and __predict_false() if you expect the
125 * expression to evaluate to false.
126 *
127 * A few notes about usage:
128 *
129 *	* Generally, __predict_false() error condition checks (unless
130 *	  you have some _strong_ reason to do otherwise, in which case
131 *	  document it), and/or __predict_true() `no-error' condition
132 *	  checks, assuming you want to optimize for the no-error case.
133 *
134 *	* Other than that, if you don't know the likelihood of a test
135 *	  succeeding from empirical or other `hard' evidence, don't
136 *	  make predictions.
137 *
138 *	* These are meant to be used in places that are run `a lot'.
139 *	  It is wasteful to make predictions in code that is run
140 *	  seldomly (e.g. at subsystem initialization time) as the
141 *	  basic block reordering that this affects can often generate
142 *	  larger code.
143 */
144#if __GNUC_PREREQ__(2, 96)
145#define __predict_true(exp)     __builtin_expect((exp), 1)
146#define __predict_false(exp)    __builtin_expect((exp), 0)
147#else
148#define __predict_true(exp)     (exp)
149#define __predict_false(exp)    (exp)
150#endif
151
152/*
153 * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
154 * require it.
155 */
156#if __GNUC_PREREQ__(4, 1)
157#define __offsetof(type, field)	 __builtin_offsetof(type, field)
158#else
159#ifndef __cplusplus
160#define	__offsetof(type, field)	((size_t)(&((type *)0)->field))
161#else
162#define __offsetof(type, field)					\
163  (__offsetof__ (reinterpret_cast <size_t>			\
164                 (&reinterpret_cast <const volatile char &>	\
165                  (static_cast<type *> (0)->field))))
166#endif
167#endif
168#define	__rangeof(type, start, end) \
169	(__offsetof(type, end) - __offsetof(type, start))
170
171/*
172 * Compiler-dependent macros to help declare dead (non-returning) and
173 * pure (no side effects) functions, and unused variables.  They are
174 * null except for versions of gcc that are known to support the features
175 * properly (old versions of gcc-2 supported the dead and pure features
176 * in a different (wrong) way).  If we do not provide an implementation
177 * for a given compiler, let the compile fail if it is told to use
178 * a feature that we cannot live without.
179 */
180#ifdef lint
181#define	__pure2
182#define	__unused
183#define	__packed
184#define	__aligned(x)
185#define	__section(x)
186#else
187#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER)
188#define	__pure2
189#define	__unused
190#endif
191#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER)
192#define	__pure2		__attribute__((__const__))
193#define	__unused
194/* XXX Find out what to do for __packed, __aligned and __section */
195#endif
196#if __GNUC_PREREQ__(2, 7)
197#define	__pure2		__attribute__((__const__))
198#define	__unused	__attribute__((__unused__))
199#define	__packed	__attribute__((__packed__))
200#define	__aligned(x)	__attribute__((__aligned__(x)))
201#define	__section(x)	__attribute__((__section__(x)))
202#endif
203
204#if __GNUC_PREREQ__(3, 1)
205#define	__used		__attribute__((__used__))
206#else
207#if __GNUC_PREREQ__(2, 7)
208#define	__used
209#endif
210#endif
211
212#if defined(__INTEL_COMPILER)
213#define __pure2		__attribute__((__const__))
214#define __unused	__attribute__((__unused__))
215#define __used		__attribute__((__used__))
216#define __packed	__attribute__((__packed__))
217#define __aligned(x)	__attribute__((__aligned__(x)))
218#define __section(x)	__attribute__((__section__(x)))
219#endif
220#endif
221
222/*
223 * Compiler-dependent macros to declare that functions take printf-like
224 * or scanf-like arguments.  They are null except for versions of gcc
225 * that are known to support the features properly (old versions of gcc-2
226 * didn't permit keeping the keywords out of the application namespace).
227 */
228#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
229#define	__printflike(fmtarg, firstvararg)
230#define	__scanflike(fmtarg, firstvararg)
231#define	__format_arg(fmtarg)
232#else
233#define	__printflike(fmtarg, firstvararg) \
234	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
235#define	__scanflike(fmtarg, firstvararg) \
236	    __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
237#define	__format_arg(fmtarg)	__attribute__((__format_arg__ (fmtarg)))
238#endif
239
240#if __GNUC_PREREQ__(3, 1)
241#define	__noinline	__attribute__ ((__noinline__))
242#else
243#define	__noinline
244#endif
245
246#if __GNUC_PREREQ__(3, 3)
247#define __nonnull(x)	__attribute__((__nonnull__(x)))
248#else
249#define __nonnull(x)
250#endif
251
252/*
253 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
254 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
255 * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
256 * mode -- there must be no spaces between its arguments, and for nested
257 * __CONCAT's, all the __CONCAT's must be at the left.  __CONCAT can also
258 * concatenate double-quoted strings produced by the __STRING macro, but
259 * this only works with ANSI C.
260 *
261 * __XSTRING is like __STRING, but it expands any macros in its argument
262 * first.  It is only available with ANSI C.
263 */
264#if defined(__STDC__) || defined(__cplusplus)
265#define	__XSTRING(x)	__STRING(x)	/* expand x, then stringify */
266
267#define	__const		const		/* define reserved names to standard */
268#define	__signed	signed
269#define	__volatile	volatile
270#if defined(__cplusplus)
271#define	__inline	inline		/* convert to C++ keyword */
272#else
273#if !(defined(__CC_SUPPORTS___INLINE))
274#define	__inline			/* delete GCC keyword */
275#endif /* ! __CC_SUPPORTS___INLINE */
276#endif /* !__cplusplus */
277
278#else	/* !(__STDC__ || __cplusplus) */
279
280#if !defined(__CC_SUPPORTS___INLINE)
281#define	__const				/* delete pseudo-ANSI C keywords */
282#define	__inline
283#define	__signed
284#define	__volatile
285/*
286 * In non-ANSI C environments, new programs will want ANSI-only C keywords
287 * deleted from the program and old programs will want them left alone.
288 * When using a compiler other than gcc, programs using the ANSI C keywords
289 * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
290 * When using "gcc -traditional", we assume that this is the intent; if
291 * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
292 */
293#ifndef	NO_ANSI_KEYWORDS
294#define	const				/* delete ANSI C keywords */
295#define	inline
296#define	signed
297#define	volatile
298#endif	/* !NO_ANSI_KEYWORDS */
299#endif	/* !__CC_SUPPORTS___INLINE */
300#endif	/* !(__STDC__ || __cplusplus) */
301
302#ifndef	__DECONST
303#define	__DECONST(type, var)	((type)(uintptr_t)(const void *)(var))
304#endif
305
306#endif
307