The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/osfmk/ppc/bits.s

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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     

Cache object: 98790d80a7478a12e53661ffb303de54


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.