Annotation of XNU/osfmk/ppc/bits.s, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             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.
        !            11:  * 
        !            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
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /*
        !            23:  * @OSF_COPYRIGHT@
        !            24:  * 
        !            25:  */
        !            26: 
        !            27: #include <ppc/asm.h>
        !            28: #include <ppc/proc_reg.h>
        !            29: 
        !            30: #      
        !            31: # void setbit(int bitno, int *s)
        !            32: # 
        !            33: # Set indicated bit in bit string.
        !            34: #     Note:    being big-endian, bit 0 is 0x80000000.
        !            35:        
        !            36: ENTRY(setbit,TAG_NO_FRAME_USED)
        !            37: 
        !            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 */
        !            45:        blr     
        !            46:        
        !            47: #      
        !            48: # void clrbit(int bitno, int *s)
        !            49: # 
        !            50: # Clear indicated bit in bit string.
        !            51: #     Note:    being big-endian, bit 0 is 0x80000000.
        !            52:        
        !            53: ENTRY(clrbit,TAG_NO_FRAME_USED)
        !            54: 
        !            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 */
        !            62:        blr     
        !            63: 
        !            64: 
        !            65: # /*
        !            66: #  * Find first bit set in bit string.
        !            67: #  */
        !            68: # int
        !            69: # ffsbit(int *s)
        !            70: #
        !            71: # Returns the bit index of the first bit set (starting from 0)
        !            72: # Assumes pointer is word-aligned
        !            73: 
        !            74: ENTRY(ffsbit, TAG_NO_FRAME_USED)
        !            75:        lwz     r0,     0(ARG0)
        !            76:                mr      ARG1,   ARG0    /* Free up ARG0 for result */
        !            77: 
        !            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 */
        !            81: 
        !            82: .L_ffsbit_lp:
        !            83:        lwz     r0,     4(ARG1)
        !            84:        addi    ARG1,   ARG1,   4
        !            85:        cmpwi   r0,     0               /* Check against zero... */
        !            86:                cntlzw  r12,    r0
        !            87:                add     ARG0,   ARG0,   r12     /* ARG0 keeps bit count */
        !            88:        beq+    .L_ffsbit_lp
        !            89:        blr
        !            90:        
        !            91: /*
        !            92:  * int tstbit(int bitno, int *s)
        !            93:  *
        !            94:  * Test indicated bit in bit string.
        !            95:  *     Note:    being big-endian, bit 0 is 0x80000000.
        !            96:  */
        !            97: 
        !            98: ENTRY2(tstbit, testbit, TAG_NO_FRAME_USED)
        !            99: 
        !           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 */
        !           105:        blr     

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.