* Returns 0-based position of the least significant bit that is set. 0 for 0. */
| 294 | * Returns 0-based position of the least significant bit that is set. 0 for 0. |
| 295 | */ |
| 296 | Y_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) |
no test coverage detected