Returns the smallest power of two that contains v. If v is already a power of two, it is returned as is.
| 57 | // Returns the smallest power of two that contains v. If v is already a |
| 58 | // power of two, it is returned as is. |
| 59 | static inline int64_t NextPower2(int64_t n) { |
| 60 | // Taken from |
| 61 | // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 |
| 62 | n--; |
| 63 | n |= n >> 1; |
| 64 | n |= n >> 2; |
| 65 | n |= n >> 4; |
| 66 | n |= n >> 8; |
| 67 | n |= n >> 16; |
| 68 | n |= n >> 32; |
| 69 | n++; |
| 70 | return n; |
| 71 | } |
| 72 | |
| 73 | constexpr bool IsMultipleOf64(int64_t n) { return (n & 63) == 0; } |
| 74 |
no outgoing calls