1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 by Maurus Cuelenaere
11 * based on ffs-arm.S by Michael Sevakis
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
26 /****************************************************************************
27 * int find_first_set_bit(uint32_t val);
29 * Find the index of the least significant set bit in the 32-bit word.
37 ****************************************************************************/
39 .global find_first_set_bit
40 .type find_first_set_bit, %function
45 beqz a0, l # if(a0 == 0) goto l
47 negu t0, a0 # t0 = -a0
48 and t0, a0, t0 # t0 = a0 & t0
49 clz v0, t0 # get lead 0's count
52 subu v0, t0, v0 # v0 = t0 - v0