MCPcopy Create free account
hub / github.com/catboost/catboost / MostSignificantBit

Function MostSignificantBit

util/generic/bitops.h:274–291  ·  view source on GitHub ↗

* Returns 0-based position of the most significant bit that is set. 0 for 0. */

Source from the content-addressed store, hash-verified

272 * Returns 0-based position of the most significant bit that is set. 0 for 0.
273 */
274Y_FORCE_INLINE ui64 MostSignificantBit(ui64 v) {
275#ifdef __GNUC__
276 ui64 res = v ? (63 - __builtin_clzll(v)) : 0;
277#elif defined(_MSC_VER) && defined(_64_)
278 unsigned long res = 0;
279 if (v) {
280 _BitScanReverse64(&res, v);
281 }
282#else
283 ui64 res = 0;
284 if (v) {
285 while (v >>= 1) {
286 ++res;
287 }
288 }
289#endif
290 return res;
291}
292
293/**
294 * Returns 0-based position of the least significant bit that is set. 0 for 0.

Callers 3

CeilLog2Function · 0.70
Y_UNIT_TESTFunction · 0.70
GetUpperBoundMethod · 0.50

Calls 1

__builtin_clzllFunction · 0.85

Tested by

no test coverage detected