diff options
Diffstat (limited to 'firmware/asm/mips/ffs.S')
-rw-r--r-- | firmware/asm/mips/ffs.S | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/firmware/asm/mips/ffs.S b/firmware/asm/mips/ffs.S new file mode 100644 index 0000000000..a2a82a6a32 --- /dev/null +++ b/firmware/asm/mips/ffs.S | |||
@@ -0,0 +1,59 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 by Maurus Cuelenaere | ||
11 | * based on ffs-arm.S by Michael Sevakis | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | |||
23 | #include "config.h" | ||
24 | #include "mips.h" | ||
25 | |||
26 | /**************************************************************************** | ||
27 | * int find_first_set_bit(uint32_t val); | ||
28 | * | ||
29 | * Find the index of the least significant set bit in the 32-bit word. | ||
30 | * | ||
31 | * return values: | ||
32 | * 0 - bit 0 is set | ||
33 | * 1 - bit 1 is set | ||
34 | * ... | ||
35 | * 31 - bit 31 is set | ||
36 | * 32 - no bits set | ||
37 | ****************************************************************************/ | ||
38 | .align 2 | ||
39 | .global find_first_set_bit | ||
40 | .type find_first_set_bit, %function | ||
41 | .set noreorder | ||
42 | .set noat | ||
43 | |||
44 | find_first_set_bit: | ||
45 | beqz a0, l # if(a0 == 0) goto l | ||
46 | nop # | ||
47 | negu t0, a0 # t0 = -a0 | ||
48 | and t0, a0, t0 # t0 = a0 & t0 | ||
49 | clz v0, t0 # get lead 0's count | ||
50 | li t0, 31 # t0 = 31 | ||
51 | jr ra # | ||
52 | subu v0, t0, v0 # v0 = t0 - v0 | ||
53 | |||
54 | l: | ||
55 | jr ra # | ||
56 | li v0, 32 # v0 = 32 | ||
57 | |||
58 | .set reorder | ||
59 | .set at | ||