]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/bits.s
xnu-792.13.8.tar.gz
[apple/xnu.git] / osfmk / ppc / bits.s
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
1c79356b
A
29 */
30/*
31 * @OSF_COPYRIGHT@
32 *
33 */
34
35#include <ppc/asm.h>
36#include <ppc/proc_reg.h>
37
38#
39# void setbit(int bitno, int *s)
40#
41# Set indicated bit in bit string.
42# Note: being big-endian, bit 0 is 0x80000000.
43
44ENTRY(setbit,TAG_NO_FRAME_USED)
45
46 rlwinm r8,r3,29,3,31 /* Get byte displacement */
47 rlwinm r9,r3,0,29,31 /* Get bit within byte */
48 li r6,0x80 /* Start with bit 0 */
49 lbzx r5,r4,r8 /* Grab target byte */
50 srw r6,r6,r9 /* Get the right bit (fits right into the load cycle) */
51 or r5,r5,r6 /* Turn on the right bit */
52 stbx r5,r4,r8 /* Save the byte back */
53 blr
54
55#
56# void clrbit(int bitno, int *s)
57#
58# Clear indicated bit in bit string.
59# Note: being big-endian, bit 0 is 0x80000000.
60
61ENTRY(clrbit,TAG_NO_FRAME_USED)
62
63 rlwinm r8,r3,29,3,31 /* Get byte displacement */
64 rlwinm r9,r3,0,29,31 /* Get bit within byte */
65 li r6,0x80 /* Start with bit 0 */
66 lbzx r5,r4,r8 /* Grab target byte */
67 srw r6,r6,r9 /* Get the right bit (fits right into the load cycle) */
68 andc r5,r5,r6 /* Turn off the right bit */
69 stbx r5,r4,r8 /* Save the byte back */
70 blr
71
72
73# /*
74# * Find first bit set in bit string.
75# */
76# int
77# ffsbit(int *s)
78#
79# Returns the bit index of the first bit set (starting from 0)
80# Assumes pointer is word-aligned
81
82ENTRY(ffsbit, TAG_NO_FRAME_USED)
83 lwz r0, 0(ARG0)
84 mr ARG1, ARG0 /* Free up ARG0 for result */
85
86 cmpwi r0, 0 /* Check against zero... */
87 cntlzw ARG0, r0 /* Free inst... find the set bit... */
88 bnelr+ /* Return if bit in first word */
89
90.L_ffsbit_lp:
91 lwz r0, 4(ARG1)
92 addi ARG1, ARG1, 4
93 cmpwi r0, 0 /* Check against zero... */
94 cntlzw r12, r0
95 add ARG0, ARG0, r12 /* ARG0 keeps bit count */
96 beq+ .L_ffsbit_lp
97 blr
98
99/*
100 * int tstbit(int bitno, int *s)
101 *
102 * Test indicated bit in bit string.
103 * Note: being big-endian, bit 0 is 0x80000000.
104 */
105
106ENTRY2(tstbit, testbit, TAG_NO_FRAME_USED)
107
108 rlwinm r8,r3,29,3,31 /* Get byte displacement */
109 rlwinm r9,r3,0,29,31 /* Get bit within byte */
110 lbzx r5,r4,r8 /* Grab target byte */
111 addi r9,r9,25 /* Get actual shift value */
112 rlwnm r3,r5,r9,31,31 /* Pass the bit back */
113 blr