| 44 | } |
| 45 | |
| 46 | inline int Log2Floor(uint32_t n) { |
| 47 | if (n == 0) return -1; |
| 48 | int log = 0; |
| 49 | uint32_t value = n; |
| 50 | for (int i = 4; i >= 0; --i) { |
| 51 | int shift = (1 << i); |
| 52 | uint32_t x = value >> shift; |
| 53 | if (x != 0) { |
| 54 | value = x; |
| 55 | log += shift; |
| 56 | } |
| 57 | } |
| 58 | return log; |
| 59 | } |
| 60 | |
| 61 | inline int Log2Ceiling(uint32_t n) { |
| 62 | int floor = Log2Floor(n); |