7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
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 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30
31 #ifndef _SYS_BITMAP_H
32 #define _SYS_BITMAP_H
33
34 #pragma ident "%Z%%M% %I% %E% SMI"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 #include <sys/feature_tests.h>
41 #if defined(__GNUC__) && defined(_ASM_INLINES) && \
42 (defined(__i386) || defined(__amd64))
43 #include <asm/bitmap.h>
44 #endif
45
46 /*
47 * Operations on bitmaps of arbitrary size
48 * A bitmap is a vector of 1 or more ulong_t's.
49 * The user of the package is responsible for range checks and keeping
50 * track of sizes.
51 */
52
53 #ifdef _LP64
54 #define BT_ULSHIFT 6 /* log base 2 of BT_NBIPUL, to extract word index */
55 #define BT_ULSHIFT32 5 /* log base 2 of BT_NBIPUL, to extract word index */
135 #if defined(_KERNEL) && !defined(_ASM)
136 #include <sys/atomic.h>
137
138 /*
139 * return next available bit index from map with specified number of bits
140 */
141 extern index_t bt_availbit(ulong_t *bitmap, size_t nbits);
142 /*
143 * find the highest order bit that is on, and is within or below
144 * the word specified by wx
145 */
146 extern int bt_gethighbit(ulong_t *mapp, int wx);
147 extern int bt_range(ulong_t *bitmap, size_t *pos1, size_t *pos2,
148 size_t end_pos);
149 /*
150 * Find highest and lowest one bit set.
151 * Returns bit number + 1 of bit that is set, otherwise returns 0.
152 * Low order bit is 0, high order bit is 31.
153 */
154 extern int highbit(ulong_t);
155 extern int lowbit(ulong_t);
156 extern int bt_getlowbit(ulong_t *bitmap, size_t start, size_t stop);
157 extern void bt_copy(ulong_t *, ulong_t *, ulong_t);
158
159 /*
160 * find the parity
161 */
162 extern int odd_parity(ulong_t);
163
164 /*
165 * Atomically set/clear bits
166 * Atomic exclusive operations will set "result" to "-1"
167 * if the bit is already set/cleared. "result" will be set
168 * to 0 otherwise.
169 */
170 #define BT_ATOMIC_SET(bitmap, bitindex) \
171 { atomic_or_long(&(BT_WIM(bitmap, bitindex)), BT_BIW(bitindex)); }
172 #define BT_ATOMIC_CLEAR(bitmap, bitindex) \
173 { atomic_and_long(&(BT_WIM(bitmap, bitindex)), ~BT_BIW(bitindex)); }
174
|
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
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 /*
49 * Operations on bitmaps of arbitrary size
50 * A bitmap is a vector of 1 or more ulong_t's.
51 * The user of the package is responsible for range checks and keeping
52 * track of sizes.
53 */
54
55 #ifdef _LP64
56 #define BT_ULSHIFT 6 /* log base 2 of BT_NBIPUL, to extract word index */
57 #define BT_ULSHIFT32 5 /* log base 2 of BT_NBIPUL, to extract word index */
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);
158 extern int lowbit(ulong_t);
159 extern int bt_getlowbit(ulong_t *bitmap, size_t start, size_t stop);
160 extern void bt_copy(ulong_t *, ulong_t *, ulong_t);
161
162 /*
163 * find the parity
164 */
165 extern int odd_parity(ulong_t);
166
167 /*
168 * Atomically set/clear bits
169 * Atomic exclusive operations will set "result" to "-1"
170 * if the bit is already set/cleared. "result" will be set
171 * to 0 otherwise.
172 */
173 #define BT_ATOMIC_SET(bitmap, bitindex) \
174 { atomic_or_long(&(BT_WIM(bitmap, bitindex)), BT_BIW(bitindex)); }
175 #define BT_ATOMIC_CLEAR(bitmap, bitindex) \
176 { atomic_and_long(&(BT_WIM(bitmap, bitindex)), ~BT_BIW(bitindex)); }
177
|