]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/bits.s
xnu-1228.12.14.tar.gz
[apple/xnu.git] / osfmk / ppc / bits.s
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 *
31 */
32
33#include <ppc/asm.h>
34#include <ppc/proc_reg.h>
35
36#
37# void setbit(int bitno, int *s)
38#
39# Set indicated bit in bit string.
40# Note: being big-endian, bit 0 is 0x80000000.
41
42ENTRY(setbit,TAG_NO_FRAME_USED)
43
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 */
51 blr
52
53#
54# void clrbit(int bitno, int *s)
55#
56# Clear indicated bit in bit string.
57# Note: being big-endian, bit 0 is 0x80000000.
58
59ENTRY(clrbit,TAG_NO_FRAME_USED)
60
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 */
68 blr
69
70
71# /*
72# * Find first bit set in bit string.
73# */
74# int
75# ffsbit(int *s)
76#
77# Returns the bit index of the first bit set (starting from 0)
78# Assumes pointer is word-aligned
79
80ENTRY(ffsbit, TAG_NO_FRAME_USED)
81 lwz r0, 0(ARG0)
82 mr ARG1, ARG0 /* Free up ARG0 for result */
83
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 */
87
88.L_ffsbit_lp:
89 lwz r0, 4(ARG1)
90 addi ARG1, ARG1, 4
91 cmpwi r0, 0 /* Check against zero... */
92 cntlzw r12, r0
93 add ARG0, ARG0, r12 /* ARG0 keeps bit count */
94 beq+ .L_ffsbit_lp
95 blr
96
97/*
98 * int tstbit(int bitno, int *s)
99 *
100 * Test indicated bit in bit string.
101 * Note: being big-endian, bit 0 is 0x80000000.
102 */
103
104ENTRY2(tstbit, testbit, TAG_NO_FRAME_USED)
105
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 */
111 blr