]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
de355530 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
1c79356b | 11 | * |
de355530 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
de355530 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * HISTORY | |
27 | * | |
28 | * Revision 1.1.1.1 1998/09/22 21:05:35 wsanchez | |
29 | * Import of Mac OS X kernel (~semeria) | |
30 | * | |
31 | * Revision 1.2 1998/04/29 17:35:55 mburg | |
32 | * MK7.3 merger | |
33 | * | |
34 | * Revision 1.1.24.1 1998/02/03 09:27:19 gdt | |
35 | * Merge up to MK7.3 | |
36 | * [1998/02/03 09:12:57 gdt] | |
37 | * | |
38 | * Revision 1.1.21.1 1996/11/29 16:57:21 stephen | |
39 | * nmklinux_1.0b3_shared into pmk1.1 | |
40 | * Added explanatory note. | |
41 | * [1996/04/10 16:54:46 emcmanus] | |
42 | * | |
43 | * Revision 1.1.22.1 1997/06/17 02:57:05 devrcs | |
44 | * Added `testbit()' routine. | |
45 | * [1996/03/18 15:21:50 rkc] | |
46 | * | |
47 | * Revision 1.1.7.3 1995/01/10 05:10:36 devrcs | |
48 | * mk6 CR801 - copyright marker not FREE_ | |
49 | * [1994/12/01 19:24:54 dwm] | |
50 | * | |
51 | * Revision 1.1.7.1 1994/06/14 16:59:49 bolinger | |
52 | * Merge up to NMK17.2. | |
53 | * [1994/06/14 16:53:29 bolinger] | |
54 | * | |
55 | * Revision 1.1.5.1 1994/04/11 09:36:31 bernadat | |
56 | * Checked in NMK16_2 revision | |
57 | * [94/03/15 bernadat] | |
58 | * | |
59 | * Revision 1.1.3.1 1993/12/23 08:53:13 bernadat | |
60 | * Checked in bolinger_860ci revision. | |
61 | * [93/11/29 bernadat] | |
62 | * | |
63 | * Revision 1.1.1.2 1993/09/12 15:44:20 bolinger | |
64 | * Initial checkin of 860 modifications; MD files from NMK14.8. | |
65 | * | |
66 | * $EndLog$ | |
67 | */ | |
68 | /* | |
69 | * C version of bit manipulation routines now required by kernel. | |
70 | * Should be replaced with assembler versions in any real port. | |
71 | * | |
72 | * Note that these routines use little-endian numbering for bits (i.e., | |
73 | * the bit number corresponds to the associated power-of-2). | |
74 | */ | |
75 | #include <mach/machine/vm_param.h> /* for BYTE_SIZE */ | |
76 | ||
77 | #define INT_SIZE (BYTE_SIZE * sizeof (int)) | |
78 | ||
79 | /* | |
80 | * Set indicated bit in bit string. | |
81 | */ | |
82 | void | |
83 | setbit(int bitno, int *s) | |
84 | { | |
85 | for ( ; INT_SIZE <= bitno; bitno -= INT_SIZE, ++s) | |
86 | ; | |
87 | *s |= 1 << bitno; | |
88 | } | |
89 | ||
90 | /* | |
91 | * Clear indicated bit in bit string. | |
92 | */ | |
93 | void | |
94 | clrbit(int bitno, int *s) | |
95 | { | |
96 | for ( ; INT_SIZE <= bitno; bitno -= INT_SIZE, ++s) | |
97 | ; | |
98 | *s &= ~(1 << bitno); | |
99 | } | |
100 | ||
101 | /* | |
102 | * Find first bit set in bit string. | |
103 | */ | |
104 | int | |
105 | ffsbit(int *s) | |
106 | { | |
107 | int offset, mask; | |
108 | ||
109 | for (offset = 0; !*s; offset += INT_SIZE, ++s) | |
110 | ; | |
111 | for (mask = 1; mask; mask <<= 1, ++offset) | |
112 | if (mask & *s) | |
113 | return (offset); | |
114 | /* | |
115 | * Shouldn't get here | |
116 | */ | |
117 | return (0); | |
118 | } | |
119 | ||
120 | /* | |
121 | * Test if indicated bit is set in bit string. | |
122 | */ | |
123 | int | |
124 | testbit(int bitno, int *s) | |
125 | { | |
126 | for ( ; INT_SIZE <= bitno; bitno -= INT_SIZE, ++s) | |
127 | ; | |
128 | return(*s & (1 << bitno)); | |
129 | } |