1174042Sjb/* 2174042Sjb * CDDL HEADER START 3174042Sjb * 4174042Sjb * The contents of this file are subject to the terms of the 5174042Sjb * Common Development and Distribution License (the "License"). 6174042Sjb * You may not use this file except in compliance with the License. 7174042Sjb * 8174042Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9174042Sjb * or http://www.opensolaris.org/os/licensing. 10174042Sjb * See the License for the specific language governing permissions 11174042Sjb * and limitations under the License. 12174042Sjb * 13174042Sjb * When distributing Covered Code, include this CDDL HEADER in each 14174042Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15174042Sjb * If applicable, add the following below this CDDL HEADER, with the 16174042Sjb * fields enclosed by brackets "[]" replaced with your own identifying 17174042Sjb * information: Portions Copyright [yyyy] [name of copyright owner] 18174042Sjb * 19174042Sjb * CDDL HEADER END 20178414Sjb * 21178414Sjb * $FreeBSD$ 22174042Sjb */ 23174042Sjb 24174042Sjb/* 25174042Sjb * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 26174042Sjb * Use is subject to license terms. 27174042Sjb */ 28174042Sjb 29174042Sjb/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 30174042Sjb/* All Rights Reserved */ 31174042Sjb 32174042Sjb 33174042Sjb#ifndef _COMPAT_OPENSOLARIS_SYS_BITMAP_H 34174042Sjb#define _COMPAT_OPENSOLARIS_SYS_BITMAP_H 35174042Sjb 36174042Sjb#include <sys/atomic.h> 37174042Sjb 38174042Sjb/* 39174042Sjb * Operations on bitmaps of arbitrary size 40174042Sjb * A bitmap is a vector of 1 or more ulong_t's. 41174042Sjb * The user of the package is responsible for range checks and keeping 42174042Sjb * track of sizes. 43174042Sjb */ 44174042Sjb 45174042Sjb#ifdef _LP64 46174042Sjb#define BT_ULSHIFT 6 /* log base 2 of BT_NBIPUL, to extract word index */ 47174042Sjb#define BT_ULSHIFT32 5 /* log base 2 of BT_NBIPUL, to extract word index */ 48174042Sjb#else 49174042Sjb#define BT_ULSHIFT 5 /* log base 2 of BT_NBIPUL, to extract word index */ 50174042Sjb#endif 51174042Sjb 52174042Sjb#define BT_NBIPUL (1 << BT_ULSHIFT) /* n bits per ulong_t */ 53174042Sjb#define BT_ULMASK (BT_NBIPUL - 1) /* to extract bit index */ 54174042Sjb 55174042Sjb#ifdef _LP64 56174042Sjb#define BT_NBIPUL32 (1 << BT_ULSHIFT32) /* n bits per ulong_t */ 57174042Sjb#define BT_ULMASK32 (BT_NBIPUL32 - 1) /* to extract bit index */ 58174042Sjb#define BT_ULMAXMASK 0xffffffffffffffff /* used by bt_getlowbit */ 59174042Sjb#else 60174042Sjb#define BT_ULMAXMASK 0xffffffff 61174042Sjb#endif 62174042Sjb 63174042Sjb/* 64174042Sjb * bitmap is a ulong_t *, bitindex an index_t 65174042Sjb * 66174042Sjb * The macros BT_WIM and BT_BIW internal; there is no need 67174042Sjb * for users of this package to use them. 68174042Sjb */ 69174042Sjb 70174042Sjb/* 71174042Sjb * word in map 72174042Sjb */ 73174042Sjb#define BT_WIM(bitmap, bitindex) \ 74174042Sjb ((bitmap)[(bitindex) >> BT_ULSHIFT]) 75174042Sjb/* 76174042Sjb * bit in word 77174042Sjb */ 78174042Sjb#define BT_BIW(bitindex) \ 79174042Sjb (1UL << ((bitindex) & BT_ULMASK)) 80174042Sjb 81174042Sjb#ifdef _LP64 82174042Sjb#define BT_WIM32(bitmap, bitindex) \ 83174042Sjb ((bitmap)[(bitindex) >> BT_ULSHIFT32]) 84174042Sjb 85174042Sjb#define BT_BIW32(bitindex) \ 86174042Sjb (1UL << ((bitindex) & BT_ULMASK32)) 87174042Sjb#endif 88174042Sjb 89174042Sjb/* 90174042Sjb * These are public macros 91174042Sjb * 92174042Sjb * BT_BITOUL == n bits to n ulong_t's 93174042Sjb */ 94174042Sjb#define BT_BITOUL(nbits) \ 95174042Sjb (((nbits) + BT_NBIPUL - 1l) / BT_NBIPUL) 96174042Sjb#define BT_SIZEOFMAP(nbits) \ 97174042Sjb (BT_BITOUL(nbits) * sizeof (ulong_t)) 98174042Sjb#define BT_TEST(bitmap, bitindex) \ 99174042Sjb ((BT_WIM((bitmap), (bitindex)) & BT_BIW(bitindex)) ? 1 : 0) 100174042Sjb#define BT_SET(bitmap, bitindex) \ 101174042Sjb { BT_WIM((bitmap), (bitindex)) |= BT_BIW(bitindex); } 102174042Sjb#define BT_CLEAR(bitmap, bitindex) \ 103174042Sjb { BT_WIM((bitmap), (bitindex)) &= ~BT_BIW(bitindex); } 104174042Sjb 105174042Sjb#ifdef _LP64 106174042Sjb#define BT_BITOUL32(nbits) \ 107174042Sjb (((nbits) + BT_NBIPUL32 - 1l) / BT_NBIPUL32) 108174042Sjb#define BT_SIZEOFMAP32(nbits) \ 109174042Sjb (BT_BITOUL32(nbits) * sizeof (uint_t)) 110174042Sjb#define BT_TEST32(bitmap, bitindex) \ 111174042Sjb ((BT_WIM32((bitmap), (bitindex)) & BT_BIW32(bitindex)) ? 1 : 0) 112174042Sjb#define BT_SET32(bitmap, bitindex) \ 113174042Sjb { BT_WIM32((bitmap), (bitindex)) |= BT_BIW32(bitindex); } 114174042Sjb#define BT_CLEAR32(bitmap, bitindex) \ 115174042Sjb { BT_WIM32((bitmap), (bitindex)) &= ~BT_BIW32(bitindex); } 116174042Sjb#endif /* _LP64 */ 117174042Sjb 118174042Sjb#endif /* _COMPAT_OPENSOLARIS_SYS_BITMAP_H */ 119