* Get the log base 2 of a 32-bit unsigned integer. * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup */
| 61 | * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup |
| 62 | */ |
| 63 | static npy_uint32 |
| 64 | LogBase2_32(npy_uint32 val) |
| 65 | { |
| 66 | static const npy_uint8 logTable[256] = |
| 67 | { |
| 68 | 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, |
| 69 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
| 70 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 71 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 72 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
| 73 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
| 74 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
| 75 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
| 76 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 77 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 78 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 79 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 80 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 81 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 82 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 83 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 |
| 84 | }; |
| 85 | |
| 86 | npy_uint32 temp; |
| 87 | |
| 88 | temp = val >> 24; |
| 89 | if (temp) { |
| 90 | return 24 + logTable[temp]; |
| 91 | } |
| 92 | |
| 93 | temp = val >> 16; |
| 94 | if (temp) { |
| 95 | return 16 + logTable[temp]; |
| 96 | } |
| 97 | |
| 98 | temp = val >> 8; |
| 99 | if (temp) { |
| 100 | return 8 + logTable[temp]; |
| 101 | } |
| 102 | |
| 103 | return logTable[val]; |
| 104 | } |
| 105 | |
| 106 | static npy_uint32 |
| 107 | LogBase2_64(npy_uint64 val) |
no outgoing calls
no test coverage detected