MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / stbi__high_bit

Function stbi__high_bit

lite/example/cpp_example/mge/cv/stb_image.h:5906–5930  ·  view source on GitHub ↗

returns 0..31 for the highest set bit

Source from the content-addressed store, hash-verified

5904
5905// returns 0..31 for the highest set bit
5906static int stbi__high_bit(unsigned int z) {
5907 int n = 0;
5908 if (z == 0)
5909 return -1;
5910 if (z >= 0x10000) {
5911 n += 16;
5912 z >>= 16;
5913 }
5914 if (z >= 0x00100) {
5915 n += 8;
5916 z >>= 8;
5917 }
5918 if (z >= 0x00010) {
5919 n += 4;
5920 z >>= 4;
5921 }
5922 if (z >= 0x00004) {
5923 n += 2;
5924 z >>= 2;
5925 }
5926 if (z >= 0x00002) {
5927 n += 1; /* >>= 1;*/
5928 }
5929 return n;
5930}
5931
5932static int stbi__bitcount(unsigned int a) {
5933 a = (a & 0x55555555) + ((a >> 1) & 0x55555555); // max 2

Callers 1

stbi__bmp_loadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected