| 5559 | |
| 5560 | |
| 5561 | static int CeilLog2(unsigned x) { |
| 5562 | // |
| 5563 | // For x > 0, ceilLog2(y) returns ceil(log(x)/log(2)). |
| 5564 | // |
| 5565 | int y = 0; |
| 5566 | int r = 0; |
| 5567 | while (x > 1) { |
| 5568 | if (x & 1) |
| 5569 | r = 1; |
| 5570 | |
| 5571 | y += 1; |
| 5572 | x >>= 1u; |
| 5573 | } |
| 5574 | return y + r; |
| 5575 | } |
| 5576 | |
| 5577 | static int RoundLog2(int x, int tile_rounding_mode) { |
| 5578 | return (tile_rounding_mode == TINYEXR_TILE_ROUND_DOWN) ? FloorLog2(static_cast<unsigned>(x)) : CeilLog2(static_cast<unsigned>(x)); |