| 66 | |
| 67 | template<typename T> |
| 68 | constexpr int CTZ(T x) { |
| 69 | static_assert(std::is_integral<T>::value, "T must be integral"); |
| 70 | // It is not unreasonable to ask for trailing zeros in a negative number. As such, do not check |
| 71 | // that T is an unsigned type. |
| 72 | static_assert(sizeof(T) == sizeof(uint64_t) || sizeof(T) <= sizeof(uint32_t), |
| 73 | "Unsupported sizeof(T)"); |
| 74 | DCHECK_NE(x, static_cast<T>(0)); |
| 75 | return (sizeof(T) == sizeof(uint64_t)) ? __builtin_ctzll(x) : __builtin_ctz(x); |
| 76 | } |
| 77 | |
| 78 | // Similar to CTZ except that on zero input it returns bitwidth and supports signed integers. |
| 79 | template<typename T> |
no outgoing calls
no test coverage detected