]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
8f6c56a5 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
8f6c56a5 A |
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. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
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 | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * HISTORY | |
33 | * | |
34 | * Revision 1.1.1.1 1998/09/22 21:05:35 wsanchez | |
35 | * Import of Mac OS X kernel (~semeria) | |
36 | * | |
37 | * Revision 1.2 1998/04/29 17:35:55 mburg | |
38 | * MK7.3 merger | |
39 | * | |
40 | * Revision 1.1.24.1 1998/02/03 09:27:19 gdt | |
41 | * Merge up to MK7.3 | |
42 | * [1998/02/03 09:12:57 gdt] | |
43 | * | |
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] | |
48 | * | |
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] | |
52 | * | |
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] | |
56 | * | |
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] | |
60 | * | |
61 | * Revision 1.1.5.1 1994/04/11 09:36:31 bernadat | |
62 | * Checked in NMK16_2 revision | |
63 | * [94/03/15 bernadat] | |
64 | * | |
65 | * Revision 1.1.3.1 1993/12/23 08:53:13 bernadat | |
66 | * Checked in bolinger_860ci revision. | |
67 | * [93/11/29 bernadat] | |
68 | * | |
69 | * Revision 1.1.1.2 1993/09/12 15:44:20 bolinger | |
70 | * Initial checkin of 860 modifications; MD files from NMK14.8. | |
71 | * | |
72 | * $EndLog$ | |
73 | */ | |
74 | /* | |
75 | * C version of bit manipulation routines now required by kernel. | |
76 | * Should be replaced with assembler versions in any real port. | |
77 | * | |
78 | * Note that these routines use little-endian numbering for bits (i.e., | |
79 | * the bit number corresponds to the associated power-of-2). | |
80 | */ | |
81 | #include <mach/machine/vm_param.h> /* for BYTE_SIZE */ | |
82 | ||
83 | #define INT_SIZE (BYTE_SIZE * sizeof (int)) | |
84 | ||
85 | /* | |
86 | * Set indicated bit in bit string. | |
87 | */ | |
88 | void | |
89 | setbit(int bitno, int *s) | |
90 | { | |
91 | for ( ; INT_SIZE <= bitno; bitno -= INT_SIZE, ++s) | |
92 | ; | |
93 | *s |= 1 << bitno; | |
94 | } | |
95 | ||
96 | /* | |
97 | * Clear indicated bit in bit string. | |
98 | */ | |
99 | void | |
100 | clrbit(int bitno, int *s) | |
101 | { | |
102 | for ( ; INT_SIZE <= bitno; bitno -= INT_SIZE, ++s) | |
103 | ; | |
104 | *s &= ~(1 << bitno); | |
105 | } | |
106 | ||
107 | /* | |
108 | * Find first bit set in bit string. | |
109 | */ | |
110 | int | |
111 | ffsbit(int *s) | |
112 | { | |
113 | int offset, mask; | |
114 | ||
115 | for (offset = 0; !*s; offset += INT_SIZE, ++s) | |
116 | ; | |
117 | for (mask = 1; mask; mask <<= 1, ++offset) | |
118 | if (mask & *s) | |
119 | return (offset); | |
120 | /* | |
121 | * Shouldn't get here | |
122 | */ | |
123 | return (0); | |
124 | } | |
125 | ||
126 | /* | |
127 | * Test if indicated bit is set in bit string. | |
128 | */ | |
129 | int | |
130 | testbit(int bitno, int *s) | |
131 | { | |
132 | for ( ; INT_SIZE <= bitno; bitno -= INT_SIZE, ++s) | |
133 | ; | |
134 | return(*s & (1 << bitno)); | |
135 | } |