summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ffs-mips.S
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ffs-mips.S')
-rw-r--r--firmware/target/mips/ffs-mips.S54
1 files changed, 54 insertions, 0 deletions
diff --git a/firmware/target/mips/ffs-mips.S b/firmware/target/mips/ffs-mips.S
new file mode 100644
index 0000000000..4f798720a5
--- /dev/null
+++ b/firmware/target/mips/ffs-mips.S
@@ -0,0 +1,54 @@
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
42find_first_set_bit:
43 beqz a0, no_bits_set # If val == 0 branch to no_bits_set
44
45 clz v0, a0 # Get lead 0's count
46 li t0, 31 # t0 = 31
47 sub v0, t0, v0 # Return value = t0 - v0
48 jr ra # Return
49 nop
50
51no_bits_set:
52 li v0, 32 # Return value = 32
53 jr ra # Return
54 nop