]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
d7e50217 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
d7e50217 A |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
d7e50217 A |
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. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * @OSF_COPYRIGHT@ | |
27 | * | |
28 | */ | |
29 | ||
30 | #include <ppc/asm.h> | |
31 | #include <ppc/proc_reg.h> | |
32 | ||
33 | # | |
34 | # void setbit(int bitno, int *s) | |
35 | # | |
36 | # Set indicated bit in bit string. | |
37 | # Note: being big-endian, bit 0 is 0x80000000. | |
38 | ||
39 | ENTRY(setbit,TAG_NO_FRAME_USED) | |
40 | ||
41 | rlwinm r8,r3,29,3,31 /* Get byte displacement */ | |
42 | rlwinm r9,r3,0,29,31 /* Get bit within byte */ | |
43 | li r6,0x80 /* Start with bit 0 */ | |
44 | lbzx r5,r4,r8 /* Grab target byte */ | |
45 | srw r6,r6,r9 /* Get the right bit (fits right into the load cycle) */ | |
46 | or r5,r5,r6 /* Turn on the right bit */ | |
47 | stbx r5,r4,r8 /* Save the byte back */ | |
48 | blr | |
49 | ||
50 | # | |
51 | # void clrbit(int bitno, int *s) | |
52 | # | |
53 | # Clear indicated bit in bit string. | |
54 | # Note: being big-endian, bit 0 is 0x80000000. | |
55 | ||
56 | ENTRY(clrbit,TAG_NO_FRAME_USED) | |
57 | ||
58 | rlwinm r8,r3,29,3,31 /* Get byte displacement */ | |
59 | rlwinm r9,r3,0,29,31 /* Get bit within byte */ | |
60 | li r6,0x80 /* Start with bit 0 */ | |
61 | lbzx r5,r4,r8 /* Grab target byte */ | |
62 | srw r6,r6,r9 /* Get the right bit (fits right into the load cycle) */ | |
63 | andc r5,r5,r6 /* Turn off the right bit */ | |
64 | stbx r5,r4,r8 /* Save the byte back */ | |
65 | blr | |
66 | ||
67 | ||
68 | # /* | |
69 | # * Find first bit set in bit string. | |
70 | # */ | |
71 | # int | |
72 | # ffsbit(int *s) | |
73 | # | |
74 | # Returns the bit index of the first bit set (starting from 0) | |
75 | # Assumes pointer is word-aligned | |
76 | ||
77 | ENTRY(ffsbit, TAG_NO_FRAME_USED) | |
78 | lwz r0, 0(ARG0) | |
79 | mr ARG1, ARG0 /* Free up ARG0 for result */ | |
80 | ||
81 | cmpwi r0, 0 /* Check against zero... */ | |
82 | cntlzw ARG0, r0 /* Free inst... find the set bit... */ | |
83 | bnelr+ /* Return if bit in first word */ | |
84 | ||
85 | .L_ffsbit_lp: | |
86 | lwz r0, 4(ARG1) | |
87 | addi ARG1, ARG1, 4 | |
88 | cmpwi r0, 0 /* Check against zero... */ | |
89 | cntlzw r12, r0 | |
90 | add ARG0, ARG0, r12 /* ARG0 keeps bit count */ | |
91 | beq+ .L_ffsbit_lp | |
92 | blr | |
93 | ||
94 | /* | |
95 | * int tstbit(int bitno, int *s) | |
96 | * | |
97 | * Test indicated bit in bit string. | |
98 | * Note: being big-endian, bit 0 is 0x80000000. | |
99 | */ | |
100 | ||
101 | ENTRY2(tstbit, testbit, TAG_NO_FRAME_USED) | |
102 | ||
103 | rlwinm r8,r3,29,3,31 /* Get byte displacement */ | |
104 | rlwinm r9,r3,0,29,31 /* Get bit within byte */ | |
105 | lbzx r5,r4,r8 /* Grab target byte */ | |
106 | addi r9,r9,25 /* Get actual shift value */ | |
107 | rlwnm r3,r5,r9,31,31 /* Pass the bit back */ | |
108 | blr |