blob: bceff76c77d928f605a97b0054328cbefb011b61 (
plain)
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
65
66
67
|
$NetBSD: patch-ab,v 1.4 2002/09/11 10:52:10 jlam Exp $
--- boolean.c.orig Thu May 23 10:02:28 2002
+++ boolean.c
@@ -61,23 +61,49 @@ int PopCnt(register BITBOARD a) {
}
int FirstOne(BITBOARD arg1) {
+ unsigned int i, j, k;
+
+ j = k = 0;
if (arg1>>48)
- return (first_one[arg1>>48]);
- if ((arg1>>32)&65535)
- return (first_one[(arg1>>32)&65535]+16);
- if ((arg1>>16)&65535)
- return (first_one[(arg1>>16)&65535]+32);
- return (first_one[arg1&65535]+48);
+ i = ((BITBOARD)(arg1>>48));
+ else if ((arg1>>32)&65535) {
+ i = ((arg1>>32)&65535);
+ j = 16;
+ } else if ((arg1>>16)&65535) {
+ i = (arg1>>16)&65535;
+ j = 32;
+ } else {
+ i = arg1&65535;
+ j = 48;
+ }
+ while (i >>= 1)
+ k++;
+ k = 16 - k;
+ return (j + k - 1);
}
int LastOne(BITBOARD arg1) {
- if (arg1&65535)
- return (last_one[arg1&65535]+48);
- if ((arg1>>16)&65535)
- return (last_one[(arg1>>16)&65535]+32);
- if ((arg1>>32)&65535)
- return (last_one[(arg1>>32)&65535]+16);
- return (last_one[arg1>>48]);
+ unsigned int i,j,k;
+
+ j = k = 0;
+ if (arg1&65535) {
+ i = arg1&65535;
+ j = 48;
+ } else if ((arg1>>16)&65535) {
+ i = (arg1>>16)&65535;
+ j = 32;
+ } else if ((arg1>>32)&65535) {
+ i = (arg1>>32)&65535;
+ j = 16;
+ } else
+ i = arg1>>48;
+
+ while ((i & 0x1) == 0) {
+ i >>= 1;
+ k++;
+ }
+ k = 16 - k;
+ return j + k - 1;
}
#endif
#endif
|