]>
Commit | Line | Data |
---|---|---|
b20e47cb RM |
1 | /* Copyright (C) 1996 Free Software Foundation, Inc. |
2 | Contributed by David Mosberger (davidm@cs.arizona.edu). | |
3 | ||
4 | This file is part of the GNU C Library. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Library General Public License as | |
8 | published by the Free Software Foundation; either version 2 of the | |
9 | License, or (at your option) any later version. | |
10 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Library General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Library General Public | |
17 | License along with the GNU C Library; see the file COPYING.LIB. If | |
18 | not, write to the Free Software Foundation, Inc., 675 Mass Ave, | |
19 | Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* Finds the first bit set in an integer. Optimized for the Alpha | |
22 | architecture. */ | |
23 | ||
24 | #include <sysdep.h> | |
b20e47cb RM |
25 | |
26 | .set noreorder | |
27 | .set noat | |
28 | ||
29 | ENTRY(ffs) | |
2c6fe0bd UD |
30 | #ifdef PROF |
31 | ldgp gp, 0(pv) | |
32 | lda AT, _mcount | |
33 | jsr AT, (AT), _mcount | |
34 | .prologue 1 | |
35 | #else | |
b20e47cb | 36 | .prologue 0 |
2c6fe0bd | 37 | #endif |
b20e47cb RM |
38 | |
39 | ldq_u zero, 0(sp) # on the 21064, this helps dual-issuing | |
40 | addl a0, zero, a0 # the last insn and reduces the stall | |
41 | negq a0, t0 # due to the srl instruction | |
42 | and a0, t0, t0 | |
43 | clr v0 | |
a5113b14 | 44 | beq a0, $done |
b20e47cb RM |
45 | |
46 | # now do binary search for first non-zero bit | |
47 | ||
48 | zapnot t0, 0x03, t2 | |
49 | addq v0, 16, t3 | |
50 | cmoveq t2, t3, v0 | |
51 | ||
52 | zapnot t0, 0x05, t2 | |
53 | addq v0, 8, t3 | |
54 | cmoveq t2, t3, v0 | |
55 | ||
56 | srl t0, v0, t0 | |
57 | addq v0, 1, v0 | |
58 | ||
59 | and t0, 0x0f, t2 | |
60 | addq v0, 4, t3 | |
61 | cmoveq t2, t3, v0 | |
62 | ||
63 | and t0, 0x33, t2 | |
64 | addq v0, 2, t3 | |
65 | cmoveq t2, t3, v0 | |
66 | ||
67 | and t0, 0x55, t2 | |
68 | addq v0, 1, t3 | |
69 | cmoveq t2, t3, v0 | |
70 | ||
a5113b14 | 71 | $done: ret |
b20e47cb | 72 | |
84724245 | 73 | END(ffs) |