stolen from: https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
| 4 | // stolen from: |
| 5 | // https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog |
| 6 | static inline int SI_LOG2(int v) |
| 7 | { |
| 8 | const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000}; |
| 9 | const unsigned int S[] = {1, 2, 4, 8, 16}; |
| 10 | |
| 11 | unsigned int r = 0; // result of log2(v) will go here |
| 12 | if (v & b[4]) { v >>= S[4]; r |= S[4]; } |
| 13 | if (v & b[3]) { v >>= S[3]; r |= S[3]; } |
| 14 | if (v & b[2]) { v >>= S[2]; r |= S[2]; } |
| 15 | if (v & b[1]) { v >>= S[1]; r |= S[1]; } |
| 16 | if (v & b[0]) { v >>= S[0]; r |= S[0]; } |
| 17 | return (int)r; |
| 18 | } |
| 19 | #if SIZEOF_LONG==4 |
| 20 | #define SI_LOG2_LONG(A) SI_LOG2(A) |
| 21 | #else |
no outgoing calls
no test coverage detected