returns 0..31 for the highest set bit
| 5904 | |
| 5905 | // returns 0..31 for the highest set bit |
| 5906 | static 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 | |
| 5932 | static int stbi__bitcount(unsigned int a) { |
| 5933 | a = (a & 0x55555555) + ((a >> 1) & 0x55555555); // max 2 |