File: ffs.c

package info (click to toggle)
net-snmp 5.7.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 34,348 kB
  • sloc: ansic: 268,086; sh: 18,217; perl: 17,235; makefile: 3,702; xml: 508; python: 495; pascal: 124; sql: 47
file content (38 lines) | stat: -rw-r--r-- 492 bytes parent folder | download | duplicates (9)
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
/*	$OpenBSD: ffs.c,v 1.7 2005/08/08 08:05:37 espie Exp $	*/

/*
 * Public domain.
 * Written by Dale Rahn.
 */

/*
 * ffs -- vax ffs instruction
 */
int
_ffs(int mask)
{
	int bit;
	unsigned int r = mask;
	static const signed char t[16] = {
		-28, 1, 2, 1,
		  3, 1, 2, 1,
		  4, 1, 2, 1,
		  3, 1, 2, 1
	};

	bit = 0;
	if (!(r & 0xffff)) {
		bit += 16;
		r >>= 16;
	}
	if (!(r & 0xff)) {
		bit += 8;
		r >>= 8;
	}
	if (!(r & 0xf)) {
		bit += 4;
		r >>= 4;
	}

	return (bit + t[ r & 0xf ]);
}