1250395Sattilio/*- 2250395Sattilio * Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org> 3250395Sattilio * All rights reserved. 4250395Sattilio * 5250395Sattilio * Copyright (c) 2008 Nokia Corporation 6250395Sattilio * All rights reserved. 7250395Sattilio * 8250395Sattilio * Redistribution and use in source and binary forms, with or without 9250395Sattilio * modification, are permitted provided that the following conditions 10250395Sattilio * are met: 11250395Sattilio * 1. Redistributions of source code must retain the above copyright 12250395Sattilio * notice unmodified, this list of conditions, and the following 13250395Sattilio * disclaimer. 14250395Sattilio * 2. Redistributions in binary form must reproduce the above copyright 15250395Sattilio * notice, this list of conditions and the following disclaimer in the 16250395Sattilio * documentation and/or other materials provided with the distribution. 17250395Sattilio * 18250395Sattilio * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19250395Sattilio * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20250395Sattilio * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21250395Sattilio * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22250395Sattilio * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23250395Sattilio * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24250395Sattilio * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25250395Sattilio * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26250395Sattilio * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27250395Sattilio * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28250395Sattilio * 29250395Sattilio * $FreeBSD$ 30250395Sattilio */ 31250395Sattilio 32250395Sattilio#ifndef _SYS__BITSET_H_ 33250395Sattilio#define _SYS__BITSET_H_ 34250395Sattilio 35250395Sattilio/* 36250395Sattilio * Macros addressing word and bit within it, tuned to make compiler 37250395Sattilio * optimize cases when SETSIZE fits into single machine word. 38250395Sattilio */ 39250395Sattilio#define _BITSET_BITS (sizeof(long) * NBBY) 40250395Sattilio 41250395Sattilio#define __bitset_words(_s) (howmany(_s, _BITSET_BITS)) 42250395Sattilio 43250395Sattilio#define __bitset_mask(_s, n) \ 44250395Sattilio (1L << ((__bitset_words((_s)) == 1) ? \ 45250395Sattilio (__size_t)(n) : ((n) % _BITSET_BITS))) 46250395Sattilio 47250395Sattilio#define __bitset_word(_s, n) \ 48250395Sattilio ((__bitset_words((_s)) == 1) ? 0 : ((n) / _BITSET_BITS)) 49250395Sattilio 50250395Sattilio#define BITSET_DEFINE(t, _s) \ 51250395Sattiliostruct t { \ 52250395Sattilio long __bits[__bitset_words((_s))]; \ 53250395Sattilio}; 54250395Sattilio 55250395Sattilio#define BITSET_T_INITIALIZER(x) \ 56250395Sattilio { .__bits = { x } } 57250395Sattilio 58250395Sattilio#define BITSET_FSET(n) \ 59250395Sattilio [ 0 ... ((n) - 1) ] = (-1L) 60250395Sattilio 61250395Sattilio#endif /* !_SYS__BITSET_H_ */ 62