2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
28 #include <ppc/proc_reg.h>
31 # void setbit(int bitno, int *s)
33 # Set indicated bit in bit string.
34 # Note: being big-endian, bit 0 is 0x80000000.
36 ENTRY(setbit,TAG_NO_FRAME_USED)
38 rlwinm r8,r3,29,3,31 /* Get byte displacement */
39 rlwinm r9,r3,0,29,31 /* Get bit within byte */
40 li r6,0x80 /* Start with bit 0 */
41 lbzx r5,r4,r8 /* Grab target byte */
42 srw r6,r6,r9 /* Get the right bit (fits right into the load cycle) */
43 or r5,r5,r6 /* Turn on the right bit */
44 stbx r5,r4,r8 /* Save the byte back */
48 # void clrbit(int bitno, int *s)
50 # Clear indicated bit in bit string.
51 # Note: being big-endian, bit 0 is 0x80000000.
53 ENTRY(clrbit,TAG_NO_FRAME_USED)
55 rlwinm r8,r3,29,3,31 /* Get byte displacement */
56 rlwinm r9,r3,0,29,31 /* Get bit within byte */
57 li r6,0x80 /* Start with bit 0 */
58 lbzx r5,r4,r8 /* Grab target byte */
59 srw r6,r6,r9 /* Get the right bit (fits right into the load cycle) */
60 andc r5,r5,r6 /* Turn off the right bit */
61 stbx r5,r4,r8 /* Save the byte back */
66 # * Find first bit set in bit string.
71 # Returns the bit index of the first bit set (starting from 0)
72 # Assumes pointer is word-aligned
74 ENTRY(ffsbit, TAG_NO_FRAME_USED)
76 mr ARG1, ARG0 /* Free up ARG0 for result */
78 cmpwi r0, 0 /* Check against zero... */
79 cntlzw ARG0, r0 /* Free inst... find the set bit... */
80 bnelr+ /* Return if bit in first word */
85 cmpwi r0, 0 /* Check against zero... */
87 add ARG0, ARG0, r12 /* ARG0 keeps bit count */
92 * int tstbit(int bitno, int *s)
94 * Test indicated bit in bit string.
95 * Note: being big-endian, bit 0 is 0x80000000.
98 ENTRY2(tstbit, testbit, TAG_NO_FRAME_USED)
100 rlwinm r8,r3,29,3,31 /* Get byte displacement */
101 rlwinm r9,r3,0,29,31 /* Get bit within byte */
102 lbzx r5,r4,r8 /* Grab target byte */
103 addi r9,r9,25 /* Get actual shift value */
104 rlwnm r3,r5,r9,31,31 /* Pass the bit back */