1 /****************************************************************************
2 * Copyright 2002-2005: Level 5 Networks Inc.
3 * Copyright 2005-2008: Solarflare Communications Inc,
4 * 9501 Jeronimo Road, Suite 250,
5 * Irvine, CA 92618, USA
7 * Maintained by Solarflare Communications
8 * <linux-xen-drivers@solarflare.com>
9 * <onload-dev@solarflare.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation, incorporated herein by reference.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 ****************************************************************************
26 /*! \cidoxg_include_ci_compat */
28 #ifndef __CI_COMPAT_GCC_H__
29 #define __CI_COMPAT_GCC_H__
35 #if defined(__linux__) && defined(__KERNEL__)
37 # include <linux/types.h>
39 typedef __u64 ci_uint64;
40 typedef __s64 ci_int64;
41 # if BITS_PER_LONG == 32
42 typedef __s32 ci_ptr_arith_t;
43 typedef __u32 ci_uintptr_t;
45 typedef __s64 ci_ptr_arith_t;
46 typedef __u64 ci_uintptr_t;
50 /* it's not obvious to me why the below is wrong for x64_64, but
51 * gcc seems to complain on this platform
53 # if defined(__ia64__)
54 # define CI_PRId64 "ld"
55 # define CI_PRIi64 "li"
56 # define CI_PRIo64 "lo"
57 # define CI_PRIu64 "lu"
58 # define CI_PRIx64 "lx"
59 # define CI_PRIX64 "lX"
61 # define CI_PRId64 "lld"
62 # define CI_PRIi64 "lli"
63 # define CI_PRIo64 "llo"
64 # define CI_PRIu64 "llu"
65 # define CI_PRIx64 "llx"
66 # define CI_PRIX64 "llX"
69 # define CI_PRId32 "d"
70 # define CI_PRIi32 "i"
71 # define CI_PRIo32 "o"
72 # define CI_PRIu32 "u"
73 # define CI_PRIx32 "x"
74 # define CI_PRIX32 "X"
79 # include <inttypes.h>
81 typedef uint64_t ci_uint64;
82 typedef int64_t ci_int64;
83 typedef intptr_t ci_ptr_arith_t;
84 typedef uintptr_t ci_uintptr_t;
86 # define CI_PRId64 PRId64
87 # define CI_PRIi64 PRIi64
88 # define CI_PRIo64 PRIo64
89 # define CI_PRIu64 PRIu64
90 # define CI_PRIx64 PRIx64
91 # define CI_PRIX64 PRIX64
93 # define CI_PRId32 PRId32
94 # define CI_PRIi32 PRIi32
95 # define CI_PRIo32 PRIo32
96 # define CI_PRIu32 PRIu32
97 # define CI_PRIx32 PRIx32
98 # define CI_PRIX32 PRIX32
103 typedef ci_uint64 ci_fixed_descriptor_t;
105 #define from_fixed_descriptor(desc) ((ci_uintptr_t)(desc))
106 #define to_fixed_descriptor(desc) ((ci_fixed_descriptor_t)(ci_uintptr_t)(desc))
109 #if __GNUC__ >= 3 && !defined(__cplusplus)
111 ** Checks that [p_mbr] has the same type as [&c_type::mbr_name].
113 # define CI_CONTAINER(c_type, mbr_name, p_mbr) \
114 __builtin_choose_expr( \
115 __builtin_types_compatible_p(__typeof__(&((c_type*)0)->mbr_name), \
116 __typeof__(p_mbr)), \
117 __CI_CONTAINER(c_type, mbr_name, p_mbr), (void)0)
119 # define ci_restrict __restrict__
123 #if !defined(__KERNEL__) || defined(__unix__)
124 #define CI_HAVE_NPRINTF 1
128 /* At what version was this introduced? */
129 #if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ > 91)
130 # define CI_LIKELY(t) __builtin_expect((t), 1)
131 # define CI_UNLIKELY(t) __builtin_expect((t), 0)
134 /**********************************************************************
137 #if __GNUC__ >= 3 && defined(NDEBUG)
138 # define CI_HF __attribute__((visibility("hidden")))
139 # define CI_HV __attribute__((visibility("hidden")))
145 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
146 # define ci_noinline static __attribute__((__noinline__))
147 /* (Linux 2.6 defines its own "noinline", so we use the "__noinline__" form) */
149 # define ci_noinline static
152 #define CI_ALIGN(x) __attribute__ ((aligned (x)))
154 #define CI_PRINTF_LIKE(a,b) __attribute__((format(printf,a,b)))
156 #endif /* __CI_COMPAT_GCC_H__ */