| 7000 | |
| 7001 | |
| 7002 | static int CeilLog2(unsigned x) { |
| 7003 | // |
| 7004 | // For x > 0, ceilLog2(y) returns ceil(log(x)/log(2)). |
| 7005 | // |
| 7006 | int y = 0; |
| 7007 | int r = 0; |
| 7008 | while (x > 1) { |
| 7009 | if (x & 1) |
| 7010 | r = 1; |
| 7011 | |
| 7012 | y += 1; |
| 7013 | x >>= 1u; |
| 7014 | } |
| 7015 | return y + r; |
| 7016 | } |
| 7017 | |
| 7018 | static int RoundLog2(int x, int tile_rounding_mode) { |
| 7019 | return (tile_rounding_mode == TINYEXR_TILE_ROUND_DOWN) ? FloorLog2(static_cast<unsigned>(x)) : CeilLog2(static_cast<unsigned>(x)); |