| 333 | // Returns value with bit set in hightest one-bit position or 0 if 0. (java.lang.X.highestOneBit). |
| 334 | template <typename T> |
| 335 | inline static T HighestOneBitValue(T opnd) { |
| 336 | using unsigned_type = typename std::make_unsigned<T>::type; |
| 337 | T res; |
| 338 | if (opnd == 0) { |
| 339 | res = 0; |
| 340 | } else { |
| 341 | int bit_position = BitSizeOf<T>() - (CLZ(static_cast<unsigned_type>(opnd)) + 1); |
| 342 | res = static_cast<T>(UINT64_C(1) << bit_position); |
| 343 | } |
| 344 | return res; |
| 345 | } |
| 346 | |
| 347 | // Rotate bits. |
| 348 | template <typename T, bool left> |