** Computes ceil(log2(x)), which is the smallest integer n such that ** x <= (1 << n). */
| 35 | ** x <= (1 << n). |
| 36 | */ |
| 37 | lu_byte luaO_ceillog2 (unsigned int x) { |
| 38 | static const lu_byte log_2[256] = { /* log_2[i - 1] = ceil(log2(i)) */ |
| 39 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, |
| 40 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
| 41 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
| 42 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
| 43 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, |
| 44 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, |
| 45 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, |
| 46 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 |
| 47 | }; |
| 48 | int l = 0; |
| 49 | x--; |
| 50 | while (x >= 256) { l += 8; x >>= 8; } |
| 51 | return cast_byte(l + log_2[x]); |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | ** Encodes 'p'% as a floating-point byte, represented as (eeeexxxx). |
no outgoing calls
no test coverage detected