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

Function LeastSignificantBit

util/generic/bitops.h:296–314  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

294 * Returns 0-based position of the least significant bit that is set. 0 for 0.
295 */
296Y_FORCE_INLINE ui64 LeastSignificantBit(ui64 v) {
297#ifdef __GNUC__
298 ui64 res = v ? __builtin_ffsll(v) - 1 : 0;
299#elif defined(_MSC_VER) && defined(_64_)
300 unsigned long res = 0;
301 if (v) {
302 _BitScanForward64(&res, v);
303 }
304#else
305 ui64 res = 0;
306 if (v) {
307 while (!(v & 1)) {
308 ++res;
309 v >>= 1;
310 }
311 }
312#endif
313 return res;
314}
315
316/*
317 * Returns 0 - based position of the most significant bit (compile time)

Callers 1

Y_UNIT_TESTFunction · 0.85

Calls 1

_BitScanForward64Function · 0.50

Tested by

no test coverage detected