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