source: rtems-libbsd/freebsd/sys/contrib/ck/include/ck_cc.h @ 1af372a

55-freebsd-126-freebsd-12
Last change on this file since 1af372a was 1af372a, checked in by Sebastian Huber <sebastian.huber@…>, on Sep 14, 2018 at 12:04:09 PM

ck: No hardware barriers in uniprocessor configs

Update #3472.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright 2009-2015 Samy Al Bahra.
3 * Copyright 2014 Paul Khuong.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
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
25 * SUCH DAMAGE.
26 */
27
28#ifndef CK_CC_H
29#define CK_CC_H
30
31#ifdef __rtems__
32#include <rtems/score/cpuopts.h>
33#endif /* __rtems__ */
34#if defined(__GNUC__) || defined(__SUNPRO_C)
35#include "gcc/ck_cc.h"
36#endif
37
38#ifndef CK_CC_RESTRICT
39#define CK_CC_RESTRICT
40#endif
41
42#ifndef CK_CC_INLINE
43#define CK_CC_INLINE inline
44#endif
45
46#ifndef CK_CC_FORCE_INLINE
47#define CK_CC_FORCE_INLINE inline
48#endif
49
50#define CK_CC_DECONST_PTR(X) ((void *)(uintptr_t)(X))
51
52/*
53 * Container function.
54 * This relies on (compiler) implementation-defined behavior.
55 */
56#define CK_CC_CONTAINER(F, T, M, N)                                             \
57        CK_CC_INLINE static T *                                                 \
58        N(F *p)                                                                 \
59        {                                                                       \
60                F *n = p;                                                       \
61                return (T *)(void *)(((char *)n) - ((size_t)&((T *)0)->M));     \
62        }
63
64#define CK_CC_PAD(x) union { char pad[x]; }
65
66#ifndef CK_CC_ALIASED
67#define CK_CC_ALIASED
68#endif
69
70#ifndef CK_CC_UNUSED
71#define CK_CC_UNUSED
72#endif
73
74#ifndef CK_CC_USED
75#define CK_CC_USED
76#endif
77
78#ifndef CK_CC_IMM
79#define CK_CC_IMM
80#endif
81
82#ifndef CK_CC_PACKED
83#define CK_CC_PACKED
84#endif
85
86#ifndef CK_CC_WEAKREF
87#define CK_CC_WEAKREF
88#endif
89
90#ifndef CK_CC_ALIGN
91#define CK_CC_ALIGN(X)
92#endif
93
94#ifndef CK_CC_CACHELINE
95#define CK_CC_CACHELINE
96#endif
97
98#ifndef CK_CC_LIKELY
99#define CK_CC_LIKELY(x) x
100#endif
101
102#ifndef CK_CC_UNLIKELY
103#define CK_CC_UNLIKELY(x) x
104#endif
105
106#ifndef CK_CC_TYPEOF
107#define CK_CC_TYPEOF(X, DEFAULT) (DEFAULT)
108#endif
109
110#define CK_F_CC_FFS_G(L, T)                             \
111CK_CC_INLINE static int                                 \
112ck_cc_##L(T v)                                          \
113{                                                       \
114        unsigned int i;                                 \
115                                                        \
116        if (v == 0)                                     \
117                return 0;                               \
118                                                        \
119        for (i = 1; (v & 1) == 0; i++, v >>= 1);        \
120        return i;                                       \
121}
122
123#ifndef CK_F_CC_FFS
124#define CK_F_CC_FFS
125CK_F_CC_FFS_G(ffs, unsigned int)
126#endif /* CK_F_CC_FFS */
127
128#ifndef CK_F_CC_FFSL
129#define CK_F_CC_FFSL
130CK_F_CC_FFS_G(ffsl, unsigned long)
131#endif /* CK_F_CC_FFSL */
132
133#ifndef CK_F_CC_FFSLL
134#define CK_F_CC_FFSLL
135CK_F_CC_FFS_G(ffsll, unsigned long long)
136#endif /* CK_F_CC_FFSLL */
137
138#undef CK_F_CC_FFS_G
139
140#ifndef CK_F_CC_CTZ
141#define CK_F_CC_CTZ
142CK_CC_INLINE static int
143ck_cc_ctz(unsigned int x)
144{
145        unsigned int i;
146
147        if (x == 0)
148                return 0;
149
150        for (i = 0; (x & 1) == 0; i++, x >>= 1);
151        return i;
152}
153#endif
154
155#ifndef CK_F_CC_POPCOUNT
156#define CK_F_CC_POPCOUNT
157CK_CC_INLINE static int
158ck_cc_popcount(unsigned int x)
159{
160        unsigned int acc;
161
162        for (acc = 0; x != 0; x >>= 1)
163                acc += x & 1;
164
165        return acc;
166}
167#endif
168
169
170#ifdef __cplusplus
171#define CK_CPP_CAST(type, arg) static_cast<type>(arg)
172#else
173#define CK_CPP_CAST(type, arg) arg
174#endif
175
176#endif /* CK_CC_H */
Note: See TracBrowser for help on using the repository browser.