2 * Copyright 2009-2015 Samy Al Bahra.
3 * Copyright 2014 Paul Khuong.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #define CK_CC_UNUSED __attribute__((unused))
40 #define CK_CC_USED __attribute__((used))
42 #if defined(__x86_64__) || defined(__x86__)
43 #define CK_CC_IMM_U32 "Z"
44 #define CK_CC_IMM_S32 "e"
46 #define CK_CC_IMM_U32 CK_CC_IMM
47 #define CK_CC_IMM_S32 CK_CC_IMM
48 #endif /* __x86_64__ || __x86__ */
52 #define CK_CC_INLINE CK_CC_UNUSED inline
54 #define CK_CC_INLINE CK_CC_UNUSED
57 #define CK_CC_FORCE_INLINE CK_CC_UNUSED __attribute__((always_inline)) inline
58 #define CK_CC_RESTRICT __restrict__
63 #define CK_CC_PACKED __attribute__((packed))
68 #define CK_CC_WEAKREF __attribute__((weakref))
71 * Alignment attribute.
73 #define CK_CC_ALIGN(B) __attribute__((aligned(B)))
78 #define CK_CC_CACHELINE CK_CC_ALIGN(CK_MD_CACHELINE)
81 * These are functions which should be avoided.
83 #ifdef __freestanding__
84 #pragma GCC poison malloc free
88 * Branch execution hints.
90 #define CK_CC_LIKELY(x) (__builtin_expect(!!(x), 1))
91 #define CK_CC_UNLIKELY(x) (__builtin_expect(!!(x), 0))
94 * Some compilers are overly strict regarding aliasing semantics.
95 * Unfortunately, in many cases it makes more sense to pay aliasing
96 * cost rather than overly expensive register spillage.
98 #define CK_CC_ALIASED __attribute__((__may_alias__))
101 * Compile-time typeof
103 #define CK_CC_TYPEOF(X, DEFAULT) __typeof__(X)
106 * Portability wrappers for bitwise operations.
108 #ifndef CK_MD_CC_BUILTIN_DISABLE
110 CK_CC_INLINE static int
111 ck_cc_ffs(unsigned int x)
114 return __builtin_ffsl(x);
118 CK_CC_INLINE static int
119 ck_cc_ffsl(unsigned long x)
122 return __builtin_ffsll(x);
126 CK_CC_INLINE static int
127 ck_cc_ctz(unsigned int x)
130 return __builtin_ctz(x);
133 #define CK_F_CC_POPCOUNT
134 CK_CC_INLINE static int
135 ck_cc_popcount(unsigned int x)
138 return __builtin_popcount(x);
140 #endif /* CK_MD_CC_BUILTIN_DISABLE */
141 #endif /* CK_GCC_CC_H */