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 #include <ppc/proc_reg.h>
37 # void setbit(int bitno, int *s)
39 # Set indicated bit in bit string.
40 # Note: being big-endian, bit 0 is 0x80000000.
42 ENTRY(setbit,TAG_NO_FRAME_USED)
44 rlwinm r8,r3,29,3,31 /* Get byte displacement */
45 rlwinm r9,r3,0,29,31 /* Get bit within byte */
46 li r6,0x80 /* Start with bit 0 */
47 lbzx r5,r4,r8 /* Grab target byte */
48 srw r6,r6,r9 /* Get the right bit (fits right into the load cycle) */
49 or r5,r5,r6 /* Turn on the right bit */
50 stbx r5,r4,r8 /* Save the byte back */
54 # void clrbit(int bitno, int *s)
56 # Clear indicated bit in bit string.
57 # Note: being big-endian, bit 0 is 0x80000000.
59 ENTRY(clrbit,TAG_NO_FRAME_USED)
61 rlwinm r8,r3,29,3,31 /* Get byte displacement */
62 rlwinm r9,r3,0,29,31 /* Get bit within byte */
63 li r6,0x80 /* Start with bit 0 */
64 lbzx r5,r4,r8 /* Grab target byte */
65 srw r6,r6,r9 /* Get the right bit (fits right into the load cycle) */
66 andc r5,r5,r6 /* Turn off the right bit */
67 stbx r5,r4,r8 /* Save the byte back */
72 # * Find first bit set in bit string.
77 # Returns the bit index of the first bit set (starting from 0)
78 # Assumes pointer is word-aligned
80 ENTRY(ffsbit, TAG_NO_FRAME_USED)
82 mr ARG1, ARG0 /* Free up ARG0 for result */
84 cmpwi r0, 0 /* Check against zero... */
85 cntlzw ARG0, r0 /* Free inst... find the set bit... */
86 bnelr+ /* Return if bit in first word */
91 cmpwi r0, 0 /* Check against zero... */
93 add ARG0, ARG0, r12 /* ARG0 keeps bit count */
98 * int tstbit(int bitno, int *s)
100 * Test indicated bit in bit string.
101 * Note: being big-endian, bit 0 is 0x80000000.
104 ENTRY2(tstbit, testbit, TAG_NO_FRAME_USED)
106 rlwinm r8,r3,29,3,31 /* Get byte displacement */
107 rlwinm r9,r3,0,29,31 /* Get bit within byte */
108 lbzx r5,r4,r8 /* Grab target byte */
109 addi r9,r9,25 /* Get actual shift value */
110 rlwnm r3,r5,r9,31,31 /* Pass the bit back */