File: ffs.c

package info (click to toggle)
wine 1.0.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 108,580 kB
  • ctags: 210,474
  • sloc: ansic: 1,461,628; perl: 17,558; makefile: 8,856; yacc: 7,992; sh: 3,864; lex: 2,919; cpp: 499; awk: 69
file content (64 lines) | stat: -rw-r--r-- 2,068 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * ffs function
 *
 * Copyright 2004 Hans Leidekker
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "config.h"
#include "wine/port.h"

#ifndef HAVE_FFS
int ffs( int x )
{
    unsigned int y = (unsigned int)x;

    if (y & 0x00000001) return 1;
    if (y & 0x00000002) return 2;
    if (y & 0x00000004) return 3;
    if (y & 0x00000008) return 4;
    if (y & 0x00000010) return 5;
    if (y & 0x00000020) return 6;
    if (y & 0x00000040) return 7;
    if (y & 0x00000080) return 8;
    if (y & 0x00000100) return 9;
    if (y & 0x00000200) return 10;
    if (y & 0x00000400) return 11;
    if (y & 0x00000800) return 12;
    if (y & 0x00001000) return 13;
    if (y & 0x00002000) return 14;
    if (y & 0x00004000) return 15;
    if (y & 0x00008000) return 16;
    if (y & 0x00010000) return 17;
    if (y & 0x00020000) return 18;
    if (y & 0x00040000) return 19;
    if (y & 0x00080000) return 20;
    if (y & 0x00100000) return 21;
    if (y & 0x00200000) return 22;
    if (y & 0x00400000) return 23;
    if (y & 0x00800000) return 24;
    if (y & 0x01000000) return 25;
    if (y & 0x02000000) return 26;
    if (y & 0x04000000) return 27;
    if (y & 0x08000000) return 28;
    if (y & 0x10000000) return 29;
    if (y & 0x20000000) return 30;
    if (y & 0x40000000) return 31;
    if (y & 0x80000000) return 32;

    return 0;
}
#endif /* HAVE_FFS */