2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
31 #include <ppc/proc_reg.h>
34 # void setbit(int bitno, int *s)
36 # Set indicated bit in bit string.
37 # Note: being big-endian, bit 0 is 0x80000000.
39 ENTRY(setbit,TAG_NO_FRAME_USED)
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 */
51 # void clrbit(int bitno, int *s)
53 # Clear indicated bit in bit string.
54 # Note: being big-endian, bit 0 is 0x80000000.
56 ENTRY(clrbit,TAG_NO_FRAME_USED)
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 */
69 # * Find first bit set in bit string.
74 # Returns the bit index of the first bit set (starting from 0)
75 # Assumes pointer is word-aligned
77 ENTRY(ffsbit, TAG_NO_FRAME_USED)
79 mr ARG1, ARG0 /* Free up ARG0 for result */
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 */
88 cmpwi r0, 0 /* Check against zero... */
90 add ARG0, ARG0, r12 /* ARG0 keeps bit count */
95 * int tstbit(int bitno, int *s)
97 * Test indicated bit in bit string.
98 * Note: being big-endian, bit 0 is 0x80000000.
101 ENTRY2(tstbit, testbit, TAG_NO_FRAME_USED)
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 */