| 13 | |
| 14 | template <typename T> |
| 15 | unsigned int select1(T x, unsigned int i) |
| 16 | { |
| 17 | // TODO: Fast implementation of select1. |
| 18 | ASSERT(i > 0 && i <= sizeof(T) * 8, (i)); |
| 19 | for (unsigned int j = 0; j < sizeof(T) * 8; x >>= 1, ++j) |
| 20 | if (x & 1) |
| 21 | if (--i == 0) |
| 22 | return j; |
| 23 | return static_cast<unsigned int>(SELECT1_ERROR); |
| 24 | } |
| 25 | |
| 26 | constexpr uint8_t FloorLog(uint64_t x) noexcept |
| 27 | { |