9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2014 by Delphix. All rights reserved.
29 */
30
31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
33
34
35 #ifndef _SYS_BITMAP_H
36 #define _SYS_BITMAP_H
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 #include <sys/feature_tests.h>
43 #if defined(__GNUC__) && defined(_ASM_INLINES) && \
44 (defined(__i386) || defined(__amd64))
45 #include <asm/bitmap.h>
46 #endif
47
48 /*
117 (((nbits) + BT_NBIPUL32 - 1l) / BT_NBIPUL32)
118 #define BT_SIZEOFMAP32(nbits) \
119 (BT_BITOUL32(nbits) * sizeof (uint_t))
120 #define BT_TEST32(bitmap, bitindex) \
121 ((BT_WIM32((bitmap), (bitindex)) & BT_BIW32(bitindex)) ? 1 : 0)
122 #define BT_SET32(bitmap, bitindex) \
123 { BT_WIM32((bitmap), (bitindex)) |= BT_BIW32(bitindex); }
124 #define BT_CLEAR32(bitmap, bitindex) \
125 { BT_WIM32((bitmap), (bitindex)) &= ~BT_BIW32(bitindex); }
126 #endif /* _LP64 */
127
128
129 /*
130 * BIT_ONLYONESET is a private macro not designed for bitmaps of
131 * arbitrary size. u must be an unsigned integer/long. It returns
132 * true if one and only one bit is set in u.
133 */
134 #define BIT_ONLYONESET(u) \
135 ((((u) == 0) ? 0 : ((u) & ((u) - 1)) == 0))
136
137 #if defined(_KERNEL) && !defined(_ASM)
138 #include <sys/atomic.h>
139
140 /*
141 * return next available bit index from map with specified number of bits
142 */
143 extern index_t bt_availbit(ulong_t *bitmap, size_t nbits);
144 /*
145 * find the highest order bit that is on, and is within or below
146 * the word specified by wx
147 */
148 extern int bt_gethighbit(ulong_t *mapp, int wx);
149 extern int bt_range(ulong_t *bitmap, size_t *pos1, size_t *pos2,
150 size_t end_pos);
151 /*
152 * Find highest and lowest one bit set.
153 * Returns bit number + 1 of bit that is set, otherwise returns 0.
154 * Low order bit is 0, high order bit is 31.
155 */
156 extern int highbit(ulong_t);
157 extern int highbit64(uint64_t);
171 * to 0 otherwise.
172 */
173 #define BT_ATOMIC_SET(bitmap, bitindex) \
174 { atomic_or_ulong(&(BT_WIM(bitmap, bitindex)), BT_BIW(bitindex)); }
175 #define BT_ATOMIC_CLEAR(bitmap, bitindex) \
176 { atomic_and_ulong(&(BT_WIM(bitmap, bitindex)), ~BT_BIW(bitindex)); }
177
178 #define BT_ATOMIC_SET_EXCL(bitmap, bitindex, result) \
179 { result = atomic_set_long_excl(&(BT_WIM(bitmap, bitindex)), \
180 (bitindex) % BT_NBIPUL); }
181 #define BT_ATOMIC_CLEAR_EXCL(bitmap, bitindex, result) \
182 { result = atomic_clear_long_excl(&(BT_WIM(bitmap, bitindex)), \
183 (bitindex) % BT_NBIPUL); }
184
185 /*
186 * Extracts bits between index h (high, inclusive) and l (low, exclusive) from
187 * u, which must be an unsigned integer.
188 */
189 #define BITX(u, h, l) (((u) >> (l)) & ((1LU << ((h) - (l) + 1LU)) - 1LU))
190
191 #endif /* _KERNEL && !_ASM */
192
193 #ifdef __cplusplus
194 }
195 #endif
196
197 #endif /* _SYS_BITMAP_H */
|
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright (c) 2014 by Delphix. All rights reserved.
29 * Copyright 2017 RackTop Systems.
30 */
31
32 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
33 /* All Rights Reserved */
34
35
36 #ifndef _SYS_BITMAP_H
37 #define _SYS_BITMAP_H
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 #include <sys/feature_tests.h>
44 #if defined(__GNUC__) && defined(_ASM_INLINES) && \
45 (defined(__i386) || defined(__amd64))
46 #include <asm/bitmap.h>
47 #endif
48
49 /*
118 (((nbits) + BT_NBIPUL32 - 1l) / BT_NBIPUL32)
119 #define BT_SIZEOFMAP32(nbits) \
120 (BT_BITOUL32(nbits) * sizeof (uint_t))
121 #define BT_TEST32(bitmap, bitindex) \
122 ((BT_WIM32((bitmap), (bitindex)) & BT_BIW32(bitindex)) ? 1 : 0)
123 #define BT_SET32(bitmap, bitindex) \
124 { BT_WIM32((bitmap), (bitindex)) |= BT_BIW32(bitindex); }
125 #define BT_CLEAR32(bitmap, bitindex) \
126 { BT_WIM32((bitmap), (bitindex)) &= ~BT_BIW32(bitindex); }
127 #endif /* _LP64 */
128
129
130 /*
131 * BIT_ONLYONESET is a private macro not designed for bitmaps of
132 * arbitrary size. u must be an unsigned integer/long. It returns
133 * true if one and only one bit is set in u.
134 */
135 #define BIT_ONLYONESET(u) \
136 ((((u) == 0) ? 0 : ((u) & ((u) - 1)) == 0))
137
138 #if (defined(_KERNEL) || defined(_FAKE_KERNEL)) && !defined(_ASM)
139 #include <sys/atomic.h>
140
141 /*
142 * return next available bit index from map with specified number of bits
143 */
144 extern index_t bt_availbit(ulong_t *bitmap, size_t nbits);
145 /*
146 * find the highest order bit that is on, and is within or below
147 * the word specified by wx
148 */
149 extern int bt_gethighbit(ulong_t *mapp, int wx);
150 extern int bt_range(ulong_t *bitmap, size_t *pos1, size_t *pos2,
151 size_t end_pos);
152 /*
153 * Find highest and lowest one bit set.
154 * Returns bit number + 1 of bit that is set, otherwise returns 0.
155 * Low order bit is 0, high order bit is 31.
156 */
157 extern int highbit(ulong_t);
158 extern int highbit64(uint64_t);
172 * to 0 otherwise.
173 */
174 #define BT_ATOMIC_SET(bitmap, bitindex) \
175 { atomic_or_ulong(&(BT_WIM(bitmap, bitindex)), BT_BIW(bitindex)); }
176 #define BT_ATOMIC_CLEAR(bitmap, bitindex) \
177 { atomic_and_ulong(&(BT_WIM(bitmap, bitindex)), ~BT_BIW(bitindex)); }
178
179 #define BT_ATOMIC_SET_EXCL(bitmap, bitindex, result) \
180 { result = atomic_set_long_excl(&(BT_WIM(bitmap, bitindex)), \
181 (bitindex) % BT_NBIPUL); }
182 #define BT_ATOMIC_CLEAR_EXCL(bitmap, bitindex, result) \
183 { result = atomic_clear_long_excl(&(BT_WIM(bitmap, bitindex)), \
184 (bitindex) % BT_NBIPUL); }
185
186 /*
187 * Extracts bits between index h (high, inclusive) and l (low, exclusive) from
188 * u, which must be an unsigned integer.
189 */
190 #define BITX(u, h, l) (((u) >> (l)) & ((1LU << ((h) - (l) + 1LU)) - 1LU))
191
192 #endif /* (_KERNEL || _FAKE_KERNEL) && !_ASM */
193
194 #ifdef __cplusplus
195 }
196 #endif
197
198 #endif /* _SYS_BITMAP_H */
|