* Returns 0-based position of the most significant bit that is set. 0 for 0. */
| 272 | * Returns 0-based position of the most significant bit that is set. 0 for 0. |
| 273 | */ |
| 274 | Y_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. |
no test coverage detected