Debian Codegraph @

apps/snmpnetstat/ffs.c

raw
1 /*
2 * $OpenBSD: ffs.c,v 1.7 2005/08/08 08:05:37 espie Exp $
3 */
4
5 /*
6 * Public domain.
7 * Written by Dale Rahn.
8 */
9
10 #include "ffs.h"
11
12 /*
13 * ffs -- vax ffs instruction
14 */
15 int
16 _ffs(int mask)
17 {
18 int bit;
19 unsigned int r = mask;
20 static const signed char t[16] = {
21 -28, 1, 2, 1,
22 3, 1, 2, 1,
23 4, 1, 2, 1,
24 3, 1, 2, 1
25 };
26
27 bit = 0;
28 if (!(r & 0xffff)) {
29 bit += 16;
30 r >>= 16;
31 }
32 if (!(r & 0xff)) {
33 bit += 8;
34 r >>= 8;
35 }
36 if (!(r & 0xf)) {
37 bit += 4;
38 r >>= 4;
39 }
40
41 return (bit + t[r & 0xf]);
42 }