Annotation of src/usr.bin/make/bit.h, Revision 1.4
1.4 ! millert 1: /* $OpenBSD: bit.h,v 1.3 1996/06/26 05:36:25 deraadt Exp $ */
1.2 deraadt 2: /* $NetBSD: bit.h,v 1.5 1995/11/08 02:30:53 christos Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
6: * Copyright (c) 1988, 1989 by Adam de Boor
7: * Copyright (c) 1989 by Berkeley Softworks
8: * All rights reserved.
9: *
10: * This code is derived from software contributed to Berkeley by
11: * Adam de Boor.
12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. All advertising materials mentioning features or use of this software
22: * must display the following acknowledgement:
23: * This product includes software developed by the University of
24: * California, Berkeley and its contributors.
25: * 4. Neither the name of the University nor the names of its contributors
26: * may be used to endorse or promote products derived from this software
27: * without specific prior written permission.
28: *
29: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39: * SUCH DAMAGE.
40: *
41: * from: @(#)bit.h 5.3 (Berkeley) 6/1/90
42: */
43:
44: /*
45: * bit.h --
46: *
47: * Definition of macros for setting and clearing bits in an array
48: * of integers.
49: *
50: * It is assumed that "int" is 32 bits wide.
51: */
52:
53: #ifndef _BIT
54: #define _BIT
55:
56: #include "sprite.h"
57:
58: #define BIT_NUM_BITS_PER_INT 32
59: #define BIT_NUM_BITS_PER_BYTE 8
60:
61: #define Bit_NumInts(numBits) \
62: (((numBits)+BIT_NUM_BITS_PER_INT -1)/BIT_NUM_BITS_PER_INT)
63:
64: #define Bit_NumBytes(numBits) \
65: (Bit_NumInts(numBits) * sizeof(int))
66:
67: #define Bit_Alloc(numBits, bitArrayPtr) \
1.2 deraadt 68: bitArrayPtr = (int *) emalloc((unsigned)Bit_NumBytes(numBits)); \
1.1 deraadt 69: Bit_Zero((numBits), (bitArrayPtr))
70:
71: #define Bit_Free(bitArrayPtr) \
72: free((char *)bitArrayPtr)
73:
74: #define Bit_Set(numBits, bitArrayPtr) \
75: ((bitArrayPtr)[(numBits)/BIT_NUM_BITS_PER_INT] |= \
76: (1 << ((numBits) % BIT_NUM_BITS_PER_INT)))
77:
78: #define Bit_IsSet(numBits, bitArrayPtr) \
79: ((bitArrayPtr)[(numBits)/BIT_NUM_BITS_PER_INT] & \
80: (1 << ((numBits) % BIT_NUM_BITS_PER_INT)))
81:
82: #define Bit_Clear(numBits, bitArrayPtr) \
83: ((bitArrayPtr)[(numBits)/BIT_NUM_BITS_PER_INT] &= \
84: ~(1 << ((numBits) % BIT_NUM_BITS_PER_INT)))
85:
86: #define Bit_IsClear(numBits, bitArrayPtr) \
87: (!(Bit_IsSet((numBits), (bitArrayPtr))))
88:
89: #define Bit_Copy(numBits, srcArrayPtr, destArrayPtr) \
90: bcopy((char *)(srcArrayPtr), (char *)(destArrayPtr), \
91: Bit_NumBytes(numBits))
92:
93: #define Bit_Zero(numBits, bitArrayPtr) \
94: bzero((char *)(bitArrayPtr), Bit_NumBytes(numBits))
95:
96: extern int Bit_FindFirstSet();
97: extern int Bit_FindFirstClear();
98: extern Boolean Bit_Intersect();
99: extern Boolean Bit_Union();
100: extern Boolean Bit_AnySet();
101: extern int *Bit_Expand();
1.4 ! millert 102:
1.1 deraadt 103: #endif /* _BIT */