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.
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.
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]
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
30 /* All Rights Reserved */
33 #ifndef _COMPAT_OPENSOLARIS_SYS_BITMAP_H
34 #define _COMPAT_OPENSOLARIS_SYS_BITMAP_H
36 #include <sys/atomic.h>
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
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 */
49 #define BT_ULSHIFT 5 /* log base 2 of BT_NBIPUL, to extract word index */
52 #define BT_NBIPUL (1 << BT_ULSHIFT) /* n bits per ulong_t */
53 #define BT_ULMASK (BT_NBIPUL - 1) /* to extract bit index */
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 */
60 #define BT_ULMAXMASK 0xffffffff
64 * bitmap is a ulong_t *, bitindex an index_t
66 * The macros BT_WIM and BT_BIW internal; there is no need
67 * for users of this package to use them.
73 #define BT_WIM(bitmap, bitindex) \
74 ((bitmap)[(bitindex) >> BT_ULSHIFT])
78 #define BT_BIW(bitindex) \
79 (1UL << ((bitindex) & BT_ULMASK))
82 #define BT_WIM32(bitmap, bitindex) \
83 ((bitmap)[(bitindex) >> BT_ULSHIFT32])
85 #define BT_BIW32(bitindex) \
86 (1UL << ((bitindex) & BT_ULMASK32))
90 * These are public macros
92 * BT_BITOUL == n bits to n ulong_t's
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); }
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); }
118 #endif /* _COMPAT_OPENSOLARIS_SYS_BITMAP_H */