MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-ValidationLayers / MostSignificantBit

Function MostSignificantBit

layers/utils/math_utils.h:77–91  ·  view source on GitHub ↗

Returns the 0-based index of the MSB, like the x86 bit scan reverse (bsr) instruction Note: an input mask of 0 yields -1

Source from the content-addressed store, hash-verified

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
93static inline int u_ffs(int val) {
94#ifdef WIN32

Calls

no outgoing calls

Tested by

no test coverage detected