Returns the 0-based index of the MSB, like the x86 bit scan reverse (bsr) instruction Note: an input mask of 0 yields -1
| 75 | // Returns the 0-based index of the MSB, like the x86 bit scan reverse (bsr) instruction |
| 76 | // Note: an input mask of 0 yields -1 |
| 77 | [[maybe_unused]] static inline int MostSignificantBit(uint32_t mask) { |
| 78 | #if defined __GNUC__ |
| 79 | return mask ? __builtin_clz(mask) ^ 31 : -1; |
| 80 | #elif defined _MSC_VER |
| 81 | unsigned long bit_pos; |
| 82 | return _BitScanReverse(&bit_pos, mask) ? int(bit_pos) : -1; |
| 83 | #else |
| 84 | for (int k = 31; k >= 0; --k) { |
| 85 | if (((mask >> k) & 1) != 0) { |
| 86 | return k; |
| 87 | } |
| 88 | } |
| 89 | return -1; |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | static inline int u_ffs(int val) { |
| 94 | #ifdef WIN32 |
no outgoing calls
no test coverage detected