]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/bits.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34 * Revision 1.1.1.1 1998/09/22 21:05:35 wsanchez
35 * Import of Mac OS X kernel (~semeria)
37 * Revision 1.2 1998/04/29 17:35:55 mburg
40 * Revision 1.1.24.1 1998/02/03 09:27:19 gdt
42 * [1998/02/03 09:12:57 gdt]
44 * Revision 1.1.21.1 1996/11/29 16:57:21 stephen
45 * nmklinux_1.0b3_shared into pmk1.1
46 * Added explanatory note.
47 * [1996/04/10 16:54:46 emcmanus]
49 * Revision 1.1.22.1 1997/06/17 02:57:05 devrcs
50 * Added `testbit()' routine.
51 * [1996/03/18 15:21:50 rkc]
53 * Revision 1.1.7.3 1995/01/10 05:10:36 devrcs
54 * mk6 CR801 - copyright marker not FREE_
55 * [1994/12/01 19:24:54 dwm]
57 * Revision 1.1.7.1 1994/06/14 16:59:49 bolinger
58 * Merge up to NMK17.2.
59 * [1994/06/14 16:53:29 bolinger]
61 * Revision 1.1.5.1 1994/04/11 09:36:31 bernadat
62 * Checked in NMK16_2 revision
65 * Revision 1.1.3.1 1993/12/23 08:53:13 bernadat
66 * Checked in bolinger_860ci revision.
69 * Revision 1.1.1.2 1993/09/12 15:44:20 bolinger
70 * Initial checkin of 860 modifications; MD files from NMK14.8.
75 * C version of bit manipulation routines now required by kernel.
76 * Should be replaced with assembler versions in any real port.
78 * Note that these routines use little-endian numbering for bits (i.e.,
79 * the bit number corresponds to the associated power-of-2).
81 #include <mach/machine/vm_param.h> /* for BYTE_SIZE */
83 #define INT_SIZE (BYTE_SIZE * sizeof (int))
86 * Set indicated bit in bit string.
89 setbit(int bitno
, int *s
)
91 for ( ; INT_SIZE
<= bitno
; bitno
-= INT_SIZE
, ++s
)
97 * Clear indicated bit in bit string.
100 clrbit(int bitno
, int *s
)
102 for ( ; INT_SIZE
<= bitno
; bitno
-= INT_SIZE
, ++s
)
108 * Find first bit set in bit string.
115 for (offset
= 0; !*s
; offset
+= INT_SIZE
, ++s
)
117 for (mask
= 1; mask
; mask
<<= 1, ++offset
)
127 * Test if indicated bit is set in bit string.
130 testbit(int bitno
, int *s
)
132 for ( ; INT_SIZE
<= bitno
; bitno
-= INT_SIZE
, ++s
)
134 return(*s
& (1 << bitno
));