Rev 33 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 33 | Rev 108 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | /* *INDENT-OFF* */ |
6 | /* *INDENT-OFF* */ |
7 | #if defined(UNIX) |
7 | #if defined(UNIX) |
8 | static __inline__ int MSB(uint64_t word) { |
8 | static __inline__ int MSB(uint64_t word) { |
9 | uint64_t dummy, dummy2; |
9 | uint64_t dummy, dummy2; |
10 | 10 | ||
11 | asm(" bsrq %1, %0 " "\n\t" |
11 | asm(" bsrq %1, %0 " "\n\t" |
12 | : "=&r"(dummy), "=&r" (dummy2) |
12 | : "=&r"(dummy), "=&r" (dummy2) |
13 | : "1"((uint64_t) (word)) |
13 | : "1"((uint64_t) (word)) |
14 | : "cc"); |
14 | : "cc"); |
15 | return (dummy); |
15 | return (dummy); |
16 | } |
16 | } |
17 | static __inline__ int LSB(uint64_t word) { |
17 | static __inline__ int LSB(uint64_t word) { |
18 | uint64_t dummy, dummy2; |
18 | uint64_t dummy, dummy2; |
19 | 19 | ||
20 | asm(" bsfq %1, %0 " "\n\t" |
20 | asm(" bsfq %1, %0 " "\n\t" |
21 | : "=&r"(dummy), "=&r" (dummy2) |
21 | : "=&r"(dummy), "=&r" (dummy2) |
22 | : "1"((uint64_t) (word)) |
22 | : "1"((uint64_t) (word)) |
23 | : "cc"); |
23 | : "cc"); |
24 | return (dummy); |
24 | return (dummy); |
25 | } |
25 | } |
26 | #if defined(POPCNT) |
26 | #if defined(POPCNT) |
27 | static __inline__ int PopCnt(uint64_t word) { |
27 | static __inline__ int PopCnt(uint64_t word) { |
28 | uint64_t dummy, dummy2; |
28 | uint64_t dummy, dummy2; |
29 | 29 | ||
30 | asm(" popcnt %1, %0 " "\n\t" |
30 | asm(" popcnt %1, %0 " "\n\t" |
31 | : "=&r"(dummy), "=&r" (dummy2) |
31 | : "=&r"(dummy), "=&r" (dummy2) |
32 | : "1"((uint64_t) (word)) |
32 | : "1"((uint64_t) (word)) |
33 | : "cc"); |
33 | : "cc"); |
34 | return (dummy); |
34 | return (dummy); |
35 | } |
35 | } |
36 | #else |
36 | #else |
37 | static __inline__ int PopCnt(uint64_t word) { |
37 | static __inline__ int PopCnt(uint64_t word) { |
38 | uint64_t dummy, dummy2, dummy3; |
38 | uint64_t dummy, dummy2, dummy3; |
39 | 39 | ||
40 | asm(" xorq %0, %0 " "\n\t" |
40 | asm(" xorq %0, %0 " "\n\t" |
41 | " testq %1, %1 " "\n\t" |
41 | " testq %1, %1 " "\n\t" |
42 | " jz 2f " "\n\t" |
42 | " jz 2f " "\n\t" |
43 | "1: leaq -1(%1),%2 " "\n\t" |
43 | "1: leaq -1(%1),%2 " "\n\t" |
44 | " incq %0 " "\n\t" |
44 | " incq %0 " "\n\t" |
45 | " andq %2, %1 " "\n\t" |
45 | " andq %2, %1 " "\n\t" |
46 | " jnz 1b " "\n\t" |
46 | " jnz 1b " "\n\t" |
47 | "2: " "\n\t" |
47 | "2: " "\n\t" |
48 | : "=&r"(dummy), "=&r"(dummy2), "=&r"(dummy3) |
48 | : "=&r"(dummy), "=&r"(dummy2), "=&r"(dummy3) |
49 | : "1"((uint64_t) (word)) |
49 | : "1"((uint64_t) (word)) |
50 | : "cc"); |
50 | : "cc"); |
51 | return (dummy); |
51 | return (dummy); |
52 | } |
52 | } |
Line 60... | Line 60... | ||
60 | #else |
60 | #else |
61 | 61 | ||
62 | __forceinline int PopCnt(uint64_t a) { |
62 | __forceinline int PopCnt(uint64_t a) { |
63 | int c = 1; |
63 | int c = 1; |
64 | 64 | ||
- | 65 | if (!a) |
|
- | 66 | return 0; |
|
65 | while (a &= a - 1) |
67 | while (a &= a - 1) |
66 | c++; |
68 | c++; |
67 | return c; |
69 | return c; |
68 | } |
70 | } |
69 | #endif |
71 | #endif |