ZAP: Align za_name in zap_attribute_t to 8 bytes
[zfs.git] / include / sys / bitmap.h
blob71eeba592cfd58d8f6cc44906da1b07c176790ba
1 /*
2 * CDDL HEADER START
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 https://opensource.org/licenses/CDDL-1.0.
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]
19 * CDDL HEADER END
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #ifndef _SYS_BITMAP_H
32 #define _SYS_BITMAP_H
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
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.
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
52 #define BT_NBIPUL (1 << BT_ULSHIFT) /* n bits per ulong_t */
53 #define BT_ULMASK (BT_NBIPUL - 1) /* to extract bit index */
56 * bitmap is a ulong_t *, bitindex an index_t
58 * The macros BT_WIM and BT_BIW internal; there is no need
59 * for users of this package to use them.
63 * word in map
65 #define BT_WIM(bitmap, bitindex) \
66 ((bitmap)[(bitindex) >> BT_ULSHIFT])
68 * bit in word
70 #define BT_BIW(bitindex) \
71 (1UL << ((bitindex) & BT_ULMASK))
74 * These are public macros
76 * BT_BITOUL == n bits to n ulong_t's
78 #define BT_BITOUL(nbits) \
79 (((nbits) + BT_NBIPUL - 1l) / BT_NBIPUL)
80 #define BT_SIZEOFMAP(nbits) \
81 (BT_BITOUL(nbits) * sizeof (ulong_t))
82 #define BT_TEST(bitmap, bitindex) \
83 ((BT_WIM((bitmap), (bitindex)) & BT_BIW(bitindex)) ? 1 : 0)
84 #define BT_SET(bitmap, bitindex) \
85 { BT_WIM((bitmap), (bitindex)) |= BT_BIW(bitindex); }
86 #define BT_CLEAR(bitmap, bitindex) \
87 { BT_WIM((bitmap), (bitindex)) &= ~BT_BIW(bitindex); }
89 #ifdef __cplusplus
91 #endif
93 #endif /* _SYS_BITMAP_H */