1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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 * $FreeBSD$
22 */
23
24 /*
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28
29 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
30 /* All Rights Reserved */
31
32
33 #ifndef _COMPAT_OPENSOLARIS_SYS_BITMAP_H
34 #define _COMPAT_OPENSOLARIS_SYS_BITMAP_H
35
36 #include <sys/atomic.h>
37
38 /*
39 * Operations on bitmaps of arbitrary size
40 * A bitmap is a vector of 1 or more ulong_t's.
41 * The user of the package is responsible for range checks and keeping
42 * track of sizes.
43 */
44
45 #ifdef _LP64
46 #define BT_ULSHIFT 6 /* log base 2 of BT_NBIPUL, to extract word index */
47 #define BT_ULSHIFT32 5 /* log base 2 of BT_NBIPUL, to extract word index */
48 #else
49 #define BT_ULSHIFT 5 /* log base 2 of BT_NBIPUL, to extract word index */
50 #endif
51
52 #define BT_NBIPUL (1 << BT_ULSHIFT) /* n bits per ulong_t */
53 #define BT_ULMASK (BT_NBIPUL - 1) /* to extract bit index */
54
55 #ifdef _LP64
56 #define BT_NBIPUL32 (1 << BT_ULSHIFT32) /* n bits per ulong_t */
57 #define BT_ULMASK32 (BT_NBIPUL32 - 1) /* to extract bit index */
58 #define BT_ULMAXMASK 0xffffffffffffffff /* used by bt_getlowbit */
59 #else
60 #define BT_ULMAXMASK 0xffffffff
61 #endif
62
63 /*
64 * bitmap is a ulong_t *, bitindex an index_t
65 *
66 * The macros BT_WIM and BT_BIW internal; there is no need
67 * for users of this package to use them.
68 */
69
70 /*
71 * word in map
72 */
73 #define BT_WIM(bitmap, bitindex) \
74 ((bitmap)[(bitindex) >> BT_ULSHIFT])
75 /*
76 * bit in word
77 */
78 #define BT_BIW(bitindex) \
79 (1UL << ((bitindex) & BT_ULMASK))
80
81 #ifdef _LP64
82 #define BT_WIM32(bitmap, bitindex) \
83 ((bitmap)[(bitindex) >> BT_ULSHIFT32])
84
85 #define BT_BIW32(bitindex) \
86 (1UL << ((bitindex) & BT_ULMASK32))
87 #endif
88
89 /*
90 * These are public macros
91 *
92 * BT_BITOUL == n bits to n ulong_t's
93 */
94 #define BT_BITOUL(nbits) \
95 (((nbits) + BT_NBIPUL - 1l) / BT_NBIPUL)
96 #define BT_SIZEOFMAP(nbits) \
97 (BT_BITOUL(nbits) * sizeof (ulong_t))
98 #define BT_TEST(bitmap, bitindex) \
99 ((BT_WIM((bitmap), (bitindex)) & BT_BIW(bitindex)) ? 1 : 0)
100 #define BT_SET(bitmap, bitindex) \
101 { BT_WIM((bitmap), (bitindex)) |= BT_BIW(bitindex); }
102 #define BT_CLEAR(bitmap, bitindex) \
103 { BT_WIM((bitmap), (bitindex)) &= ~BT_BIW(bitindex); }
104
105 #ifdef _LP64
106 #define BT_BITOUL32(nbits) \
107 (((nbits) + BT_NBIPUL32 - 1l) / BT_NBIPUL32)
108 #define BT_SIZEOFMAP32(nbits) \
109 (BT_BITOUL32(nbits) * sizeof (uint_t))
110 #define BT_TEST32(bitmap, bitindex) \
111 ((BT_WIM32((bitmap), (bitindex)) & BT_BIW32(bitindex)) ? 1 : 0)
112 #define BT_SET32(bitmap, bitindex) \
113 { BT_WIM32((bitmap), (bitindex)) |= BT_BIW32(bitindex); }
114 #define BT_CLEAR32(bitmap, bitindex) \
115 { BT_WIM32((bitmap), (bitindex)) &= ~BT_BIW32(bitindex); }
116 #endif /* _LP64 */
117
118 #endif /* _COMPAT_OPENSOLARIS_SYS_BITMAP_H */
Cache object: 3cdfd2697179d193749fdf354923760f
|