]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/i386/i686/ffs.c
Update.
[thirdparty/glibc.git] / sysdeps / i386 / i686 / ffs.c
CommitLineData
fed8f7f7
UD
1/* ffs -- find first set bit in a word, counted from least significant end.
2 For Intel 80x86, x>=6.
3 This file is part of the GNU C Library.
4 Copyright (C) 1991, 92, 93, 94, 97, 98 Free Software Foundation, Inc.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
bdd421cc 22#define ffsl __something_else
fed8f7f7
UD
23#include <string.h>
24
25#undef ffs
26
27#ifdef __GNUC__
28
29int
30__ffs (x)
31 int x;
32{
33 int cnt;
34 int tmp;
35
36 asm ("bsfl %2,%0\n" /* Count low bits in X and store in %1. */
37 "cmovel %1,%0\n" /* If number was zero, use -1 as result. */
38 : "=&r" (cnt), "=r" (tmp) : "rm" (x), "1" (-1));
39
40 return cnt + 1;
41}
42weak_alias (__ffs, ffs)
bdd421cc
UD
43#undef ffsl
44weak_alias (__ffs, ffsl)
fed8f7f7
UD
45
46#else
47#include <sysdeps/generic/ffs.c>
48#endif