- 论坛徽章:
- 0
|
- // sys/lib/libkern/ffs.c
- /* $OpenBSD: ffs.c,v 1.7 2004/11/28 07:23:41 mickey Exp $ */
- /*
- * 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 ]);
- }
复制代码
- 0x0000 000? +0 00000
- 0x0000 00?0 +4 00100
- 0x0000 0?00 +8 01000
- 0x0000 ?000 +12 01100
- 0x000? 0000 +16 10000
- 0x00?0 0000 +20 10100
- 0x0?00 0000 +24 11000
- 0x?000 0000 +28 11100
- 000 0x0 0x0 0000 0000
- 001 0x1 0x1 0001 0001
- 002 0x2 0x2 0010 0010
- 003 0x3 0x1 0011 0001
- 004 0x4 0x3 0100 0011
- 005 0x5 0x1 0101 0001
- 006 0x6 0x2 0110 0010
- 007 0x7 0x1 0111 0001
- 010 0x8 0x4 1000 0100
- 011 0x9 0x1 1001 0001
- 012 0xa 0x2 1010 0010
- 013 0xb 0x1 1011 0001
- 014 0xc 0x3 1100 0011
- 015 0xd 0x1 1101 0001
- 016 0xe 0x2 1110 0010
- 017 0xf 0x1 1111 0001
复制代码
没搞懂到底是用来做什么的,头晕中... |
|