Bump version to 3.12
[maemo-rb.git] / firmware / asm / ffs.c
bloba4512e0c5585ce62214bb990765ae175d7cd7006
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Michael Sevakis
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
22 #include <inttypes.h>
25 * Find the index of the least significant set bit in the word.
26 * return values:
27 * 0 - bit 0 is set
28 * 1 - bit 1 is set
29 * ...
30 * 31 - bit 31 is set
31 * 32 - no bits set
33 int find_first_set_bit(uint32_t val)
35 if (val == 0)
36 return 32;
38 /* __builtin_ctz[l[l]]: Returns the number of trailing 0-bits in x,
39 * starting at the least significant bit position. If x is 0, the result
40 * is undefined. */
41 return __builtin_ctz(val);