Rev 102 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 102 | Rev 104 | ||
---|---|---|---|
Line 70... | Line 70... | ||
70 | static const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f; //binary: 4 zeros, 4 ones ... |
70 | static const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f; //binary: 4 zeros, 4 ones ... |
71 | static const unsigned long long h01 = 0x0101010101010101; //the sum of 256 to the power of 0,1,2,3... |
71 | static const unsigned long long h01 = 0x0101010101010101; //the sum of 256 to the power of 0,1,2,3... |
72 | x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits |
72 | x -= (x >> 1) & m1; //put count of each 2 bits into those 2 bits |
73 | x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits |
73 | x = (x & m2) + ((x >> 2) & m2); //put count of each 4 bits into those 4 bits |
74 | x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits |
74 | x = (x + (x >> 4)) & m4; //put count of each 8 bits into those 8 bits |
75 | return |
75 | return (int)((x * h01) >> 56); //returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ... |
76 | } |
76 | } |
77 | #endif // Pierre-Marie Baty -- __builtin_popcountll support for MSVC 32-bit |
77 | #endif // Pierre-Marie Baty -- __builtin_popcountll support for MSVC 32-bit |
78 | 78 | ||
79 | #ifndef __builtin_ctzll // Pierre-Marie Baty -- __builtin_ctzll support for MSVC 32-bit |
79 | #ifndef __builtin_ctzll // Pierre-Marie Baty -- __builtin_ctzll support for MSVC 32-bit |
80 | #include <intrin.h> |
- | |
81 | int __builtin_ctzll (unsigned long long x) |
80 | int __builtin_ctzll (unsigned long long x) |
82 | { |
81 | { |
83 | // Returns the number of trailing 0-bits in x, starting at the least significant bit position. |
82 | // Returns the number of trailing 0-bits in x, starting at the least significant bit position. |
84 | // If x is zero, the result is undefined. |
83 | // If x is zero, the result is undefined. |
85 | // This uses a binary search algorithm from Hacker's Delight. |
84 | // This uses a binary search algorithm from Hacker's Delight. |