** Computes ceil(log2(x)) */
| 63 | ** Computes ceil(log2(x)) |
| 64 | */ |
| 65 | int luaO_ceillog2 (unsigned int x) { |
| 66 | static const lu_byte log_2[256] = { /* log_2[i] = ceil(log2(i - 1)) */ |
| 67 | 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, |
| 68 | 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, |
| 69 | 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, |
| 70 | 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, |
| 71 | 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, |
| 72 | 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, |
| 73 | 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, |
| 74 | 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 |
| 75 | }; |
| 76 | int l = 0; |
| 77 | x--; |
| 78 | while (x >= 256) { l += 8; x >>= 8; } |
| 79 | return l + log_2[x]; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | static lua_Integer intarith (lua_State *L, int op, lua_Integer v1, |
no outgoing calls
no test coverage detected