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
31 #if defined(__GNUC__) || defined(__SUNPRO_C)
32 #include "gcc/ck_cc.h"
35 #ifndef CK_CC_RESTRICT
36 #define CK_CC_RESTRICT
40 #define CK_CC_INLINE inline
43 #ifndef CK_CC_FORCE_INLINE
44 #define CK_CC_FORCE_INLINE inline
47 #define CK_CC_DECONST_PTR(X) ((void *)(uintptr_t)(X))
51 * This relies on (compiler) implementation-defined behavior.
53 #define CK_CC_CONTAINER(F, T, M, N) \
54 CK_CC_INLINE static T * \
58 return (T *)(void *)(((char *)n) - ((size_t)&((T *)0)->M)); \
61 #define CK_CC_PAD(x) union { char pad[x]; }
88 #define CK_CC_ALIGN(X)
91 #ifndef CK_CC_CACHELINE
92 #define CK_CC_CACHELINE
96 #define CK_CC_LIKELY(x) x
99 #ifndef CK_CC_UNLIKELY
100 #define CK_CC_UNLIKELY(x) x
104 #define CK_CC_TYPEOF(X, DEFAULT) (DEFAULT)
107 #define CK_F_CC_FFS_G(L, T) \
108 CK_CC_INLINE static int \
116 for (i = 1; (v & 1) == 0; i++, v >>= 1); \
122 CK_F_CC_FFS_G(ffs, unsigned int)
123 #endif /* CK_F_CC_FFS */
127 CK_F_CC_FFS_G(ffsl, unsigned long)
128 #endif /* CK_F_CC_FFSL */
130 #ifndef CK_F_CC_FFSLL
131 #define CK_F_CC_FFSLL
132 CK_F_CC_FFS_G(ffsll, unsigned long long)
133 #endif /* CK_F_CC_FFSLL */
139 CK_CC_INLINE static int
140 ck_cc_ctz(unsigned int x)
147 for (i = 0; (x & 1) == 0; i++, x >>= 1);
152 #ifndef CK_F_CC_POPCOUNT
153 #define CK_F_CC_POPCOUNT
154 CK_CC_INLINE static int
155 ck_cc_popcount(unsigned int x)
159 for (acc = 0; x != 0; x >>= 1)
168 #define CK_CPP_CAST(type, arg) static_cast<type>(arg)
170 #define CK_CPP_CAST(type, arg) arg