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