]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/lib/libc/alpha/string/ffs.S
Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
[FreeBSD/FreeBSD.git] / 6 / lib / libc / alpha / string / ffs.S
1 /*      $NetBSD: ffs.S,v 1.3 1996/10/17 03:08:13 cgd Exp $      */
2
3 /*
4  * Copyright (c) 1995 Christopher G. Demetriou
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Christopher G. Demetriou
18  *      for the NetBSD Project.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <machine/asm.h>
35 __FBSDID("$FreeBSD$");
36
37 LEAF(ffs, 1)
38         addl    a0, 0, t0
39         beq     t0, Lallzero
40
41         /*
42          * Initialize return value (v0), and set up t1 so that it
43          * contains the mask with only the lowest bit set.
44          */
45         subl    zero, t0, t1
46         ldil    v0, 1
47         and     t0, t1, t1
48
49         and     t1, 0xff, t2
50         bne     t2, Ldo8
51
52         /*
53          * If lower 16 bits empty, add 16 to result and use upper 16.
54          */
55         zapnot  t1, 0x03, t3
56         bne     t3, Ldo16
57         sra     t1, 16, t1
58         addl    v0, 16, v0
59
60 Ldo16:
61         /*
62          * If lower 8 bits empty, add 8 to result and use upper 8.
63          */
64         and     t1, 0xff, t4
65         bne     t4, Ldo8
66         sra     t1, 8, t1
67         addl    v0, 8, v0
68
69 Ldo8:
70         and     t1, 0x0f, t5            /* lower 4 of 8 empty? */
71         and     t1, 0x33, t6            /* lower 2 of each 4 empty? */
72         and     t1, 0x55, t7            /* lower 1 of each 2 empty? */
73
74         /* If lower 4 bits empty, add 4 to result. */
75         bne     t5, Ldo4
76         addl    v0, 4, v0
77
78 Ldo4:   /* If lower 2 bits of each 4 empty, add 2 to result. */
79         bne     t6, Ldo2
80         addl    v0, 2, v0
81
82 Ldo2:   /* If lower bit of each 2 empty, add 1 to result. */
83         bne     t7, Ldone
84         addl    v0, 1, v0
85
86 Ldone:
87         RET
88
89 Lallzero:
90         bis     zero, zero, v0
91         RET
92 END(ffs)