** Computes ceil(log2(x)) */
| 33 | ** Computes ceil(log2(x)) |
| 34 | */ |
| 35 | int luaO_ceillog2 (unsigned int x) { |
| 36 | static const lu_byte log_2[256] = { /* log_2[i] = ceil(log2(i - 1)) */ |
| 37 | 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, |
| 38 | 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, |
| 39 | 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, |
| 40 | 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, |
| 41 | 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, |
| 42 | 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, |
| 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 | }; |
| 46 | int l = 0; |
| 47 | x--; |
| 48 | while (x >= 256) { l += 8; x >>= 8; } |
| 49 | return l + log_2[x]; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | static lua_Integer intarith (lua_State *L, int op, lua_Integer v1, |
no outgoing calls
no test coverage detected