- Update Xen patches to 3.3-rc5 and c/s 1157.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / sfc_netback / ci / compat / gcc.h
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
6  *
7  * Maintained by Solarflare Communications
8  *  <linux-xen-drivers@solarflare.com>
9  *  <onload-dev@solarflare.com>
10  *
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.
14  *
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.
19  *
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  ****************************************************************************
24  */
25
26 /*! \cidoxg_include_ci_compat  */
27
28 #ifndef __CI_COMPAT_GCC_H__
29 #define __CI_COMPAT_GCC_H__
30
31
32 #define CI_HAVE_INT64
33
34
35 #if defined(__linux__) && defined(__KERNEL__)
36
37 # include <linux/types.h>
38
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;
44 # else
45 typedef __s64                 ci_ptr_arith_t;
46 typedef __u64                 ci_uintptr_t;
47 # endif
48
49
50 /* it's not obvious to me why the below is wrong for x64_64, but
51  * gcc seems to complain on this platform
52  */
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"
60 # else
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"
67 # endif
68
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"
75
76 #else
77
78 # include <stdint.h>
79 # include <inttypes.h>
80
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;
85
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
92
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
99
100 #endif
101
102
103 typedef ci_uint64                       ci_fixed_descriptor_t;
104
105 #define from_fixed_descriptor(desc) ((ci_uintptr_t)(desc))
106 #define to_fixed_descriptor(desc) ((ci_fixed_descriptor_t)(ci_uintptr_t)(desc))
107
108
109 #if __GNUC__ >= 3 && !defined(__cplusplus)
110 /*
111 ** Checks that [p_mbr] has the same type as [&c_type::mbr_name].
112 */
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)
118
119 # define ci_restrict  __restrict__
120 #endif
121
122
123 #if !defined(__KERNEL__) || defined(__unix__)
124 #define CI_HAVE_NPRINTF  1
125 #endif
126
127
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)
132 #endif
133
134 /**********************************************************************
135  * Attributes
136  */
137 #if __GNUC__ >= 3 && defined(NDEBUG)
138 # define CI_HF __attribute__((visibility("hidden")))
139 # define CI_HV __attribute__((visibility("hidden")))
140 #else
141 # define CI_HF
142 # define CI_HV
143 #endif
144
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) */
148 #else
149 # define ci_noinline  static
150 #endif
151
152 #define CI_ALIGN(x) __attribute__ ((aligned (x)))
153
154 #define CI_PRINTF_LIKE(a,b) __attribute__((format(printf,a,b)))
155
156 #endif  /* __CI_COMPAT_GCC_H__ */
157
158 /*! \cidoxg_end */