Home | History | Annotate | Line # | Download | only in string
ffs.S revision 1.1.2.2
      1  1.1.2.2  pgoyette /*	$NetBSD: ffs.S,v 1.1.2.2 2016/08/06 00:18:38 pgoyette Exp $	*/
      2  1.1.2.2  pgoyette 
      3  1.1.2.2  pgoyette /*
      4  1.1.2.2  pgoyette  * Copyright (c) 1995 Christopher G. Demetriou
      5  1.1.2.2  pgoyette  * All rights reserved.
      6  1.1.2.2  pgoyette  *
      7  1.1.2.2  pgoyette  * Redistribution and use in source and binary forms, with or without
      8  1.1.2.2  pgoyette  * modification, are permitted provided that the following conditions
      9  1.1.2.2  pgoyette  * are met:
     10  1.1.2.2  pgoyette  * 1. Redistributions of source code must retain the above copyright
     11  1.1.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer.
     12  1.1.2.2  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     14  1.1.2.2  pgoyette  *    documentation and/or other materials provided with the distribution.
     15  1.1.2.2  pgoyette  * 3. All advertising materials mentioning features or use of this software
     16  1.1.2.2  pgoyette  *    must display the following acknowledgement:
     17  1.1.2.2  pgoyette  *      This product includes software developed by Christopher G. Demetriou
     18  1.1.2.2  pgoyette  *	for the NetBSD Project.
     19  1.1.2.2  pgoyette  * 4. The name of the author may not be used to endorse or promote products
     20  1.1.2.2  pgoyette  *    derived from this software without specific prior written permission
     21  1.1.2.2  pgoyette  *
     22  1.1.2.2  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1.2.2  pgoyette  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1.2.2  pgoyette  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1.2.2  pgoyette  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1.2.2  pgoyette  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1.2.2  pgoyette  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1.2.2  pgoyette  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1.2.2  pgoyette  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1.2.2  pgoyette  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1.2.2  pgoyette  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1.2.2  pgoyette  *
     33  1.1.2.2  pgoyette  * __FBSDID("$FreeBSD: releng/10.1/lib/libc/ia64/string/ffs.S 111777 2003-03-03 01:09:46Z obrien $");
     34  1.1.2.2  pgoyette  *
     35  1.1.2.2  pgoyette  */
     36  1.1.2.2  pgoyette 
     37  1.1.2.2  pgoyette #include <machine/asm.h>
     38  1.1.2.2  pgoyette /*
     39  1.1.2.2  pgoyette 
     40  1.1.2.2  pgoyette /*
     41  1.1.2.2  pgoyette  * int
     42  1.1.2.2  pgoyette  * ffs(int value);
     43  1.1.2.2  pgoyette  */
     44  1.1.2.2  pgoyette ENTRY(ffs, 1)
     45  1.1.2.2  pgoyette 	sxt4	r14=in0 ;;
     46  1.1.2.2  pgoyette 	cmp.eq	p6,p0=r14,r0
     47  1.1.2.2  pgoyette (p6)	br.dpnt.few Lallzero
     48  1.1.2.2  pgoyette 
     49  1.1.2.2  pgoyette 	/*
     50  1.1.2.2  pgoyette 	 * Initialize return value (ret0), and set up r15 so that it
     51  1.1.2.2  pgoyette 	 * contains the mask with only the lowest bit set.
     52  1.1.2.2  pgoyette 	 */
     53  1.1.2.2  pgoyette 	sub	r15=r0,r14
     54  1.1.2.2  pgoyette 	mov	ret0=1 ;;
     55  1.1.2.2  pgoyette 	and	r15=r14,r15 ;;
     56  1.1.2.2  pgoyette 
     57  1.1.2.2  pgoyette 	extr.u	r16=r15,0,8 ;;
     58  1.1.2.2  pgoyette 	cmp.ne	p6,p0=r0,r16
     59  1.1.2.2  pgoyette (p6)	br.dptk.few Ldo8
     60  1.1.2.2  pgoyette 
     61  1.1.2.2  pgoyette 	/*
     62  1.1.2.2  pgoyette 	 * If lower 16 bits empty, add 16 to result and use upper 16.
     63  1.1.2.2  pgoyette 	 */
     64  1.1.2.2  pgoyette 	extr.u	r16=r15,0,16 ;;
     65  1.1.2.2  pgoyette 	cmp.ne	p6,p0=r0,r16
     66  1.1.2.2  pgoyette (p6)	br.dptk.few Ldo16
     67  1.1.2.2  pgoyette 	extr.u	r15=r15,16,16
     68  1.1.2.2  pgoyette 	add	ret0=16,ret0 ;;
     69  1.1.2.2  pgoyette 
     70  1.1.2.2  pgoyette Ldo16:
     71  1.1.2.2  pgoyette 	/*
     72  1.1.2.2  pgoyette 	 * If lower 8 bits empty, add 8 to result and use upper 8.
     73  1.1.2.2  pgoyette 	 */
     74  1.1.2.2  pgoyette 	extr.u	r16=r15,0,8 ;;
     75  1.1.2.2  pgoyette 	cmp.ne	p6,p0=r0,r16
     76  1.1.2.2  pgoyette (p6)	br.dptk.few Ldo8
     77  1.1.2.2  pgoyette 	extr.u	r15=r15,8,24
     78  1.1.2.2  pgoyette 	add	ret0=8,ret0 ;;
     79  1.1.2.2  pgoyette 
     80  1.1.2.2  pgoyette Ldo8:
     81  1.1.2.2  pgoyette 	and	r16=0x0f,r15		/* lower 4 of 8 empty? */
     82  1.1.2.2  pgoyette 	and	r17=0x33,r15		/* lower 2 of each 4 empty? */
     83  1.1.2.2  pgoyette 	and	r18=0x55,r15 ;;		/* lower 1 of each 2 empty? */
     84  1.1.2.2  pgoyette 	cmp.ne	p6,p0=r16,r0
     85  1.1.2.2  pgoyette 	cmp.ne	p7,p0=r17,r0
     86  1.1.2.2  pgoyette 	cmp.ne	p8,p0=r18,r0
     87  1.1.2.2  pgoyette 
     88  1.1.2.2  pgoyette 	/* If lower 4 bits empty, add 4 to result. */
     89  1.1.2.2  pgoyette (p6)	br.dptk.few Ldo4
     90  1.1.2.2  pgoyette 	add	ret0=4,ret0 ;;
     91  1.1.2.2  pgoyette 
     92  1.1.2.2  pgoyette Ldo4:	/* If lower 2 bits of each 4 empty, add 2 to result. */
     93  1.1.2.2  pgoyette (p7)	br.dptk.few Ldo2
     94  1.1.2.2  pgoyette 	add	ret0=2,ret0 ;;
     95  1.1.2.2  pgoyette 
     96  1.1.2.2  pgoyette Ldo2:	/* If lower bit of each 2 empty, add 1 to result. */
     97  1.1.2.2  pgoyette (p8)	br.dptk.few Ldone
     98  1.1.2.2  pgoyette 	add	ret0=1,ret0
     99  1.1.2.2  pgoyette 
    100  1.1.2.2  pgoyette Ldone:
    101  1.1.2.2  pgoyette 	br.ret.sptk.few rp
    102  1.1.2.2  pgoyette 
    103  1.1.2.2  pgoyette Lallzero:
    104  1.1.2.2  pgoyette 	mov	ret0=0
    105  1.1.2.2  pgoyette 	br.ret.sptk.few rp
    106  1.1.2.2  pgoyette END(ffs)
    107