| 5546 | |
| 5547 | |
| 5548 | static int FloorLog2(unsigned x) { |
| 5549 | // |
| 5550 | // For x > 0, floorLog2(y) returns floor(log(x)/log(2)). |
| 5551 | // |
| 5552 | int y = 0; |
| 5553 | while (x > 1) { |
| 5554 | y += 1; |
| 5555 | x >>= 1u; |
| 5556 | } |
| 5557 | return y; |
| 5558 | } |
| 5559 | |
| 5560 | |
| 5561 | static int CeilLog2(unsigned x) { |