Last active
April 2, 2017 22:15
-
-
Save kusma/a4ddf3513f51fff6578f2027d0082a97 to your computer and use it in GitHub Desktop.
clz emulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline int clz(uint32_t input) | |
{ | |
const uint8_t clz_lut[16] = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; | |
unsigned c = 0; | |
if (input & 0xFFFF0000) | |
input >>= 16; | |
else | |
c = 16; | |
if (input & 0xFF00) | |
input >>= 8; | |
else | |
c += 8; | |
if (input & 0xF0) | |
input >>= 4; | |
else | |
c += 4; | |
return clz_lut[input] + c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment