MCPcopy Create free account
hub / github.com/numpy/numpy / LogBase2_32

Function LogBase2_32

numpy/core/src/multiarray/dragon4.c:63–104  ·  view source on GitHub ↗

* Get the log base 2 of a 32-bit unsigned integer. * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup */

Source from the content-addressed store, hash-verified

61 * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
62 */
63static npy_uint32
64LogBase2_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
106static npy_uint32
107LogBase2_64(npy_uint64 val)

Callers 4

LogBase2_64Function · 0.85
Dragon4Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected