News for hackers. Stuff that matters.
Re:EABitTricks.h by 10000truths on Monday December 19, 2022 @11:16AM (#34053798)
Modern CPUs have a count-leading-zeros instruction to calculate floor(log2(x)) efficiently. GCC and clang expose this with the __builtin_clz* family of intrinsics. MSVC exposes this with _BitScanReverse.

  static inline uint64_t floor_log2(uint64_t x) {
      return 63 - __builtin_clzll(x);
  }
Re:EABitTricks.h by vinkelhake on Monday December 19, 2022 @01:08PM (#34055368)
And C++ (as of C++20) exposes this and more in the header <bit>.

https://en.cppreference.com/w/cpp/header/bit