diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-01-30 16:05:23 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-01-30 16:05:23 -0200 |
| commit | a76fa251998ea83679cfad24542cf4c1aa3d6131 (patch) | |
| tree | 66bc7f3d28c8dc4b1a1b812aa746a4cbafd649b5 /lobject.c | |
| parent | dd3519ab89078fb270797332f0d661b5f6b7612a (diff) | |
| download | lua-a76fa251998ea83679cfad24542cf4c1aa3d6131.tar.gz lua-a76fa251998ea83679cfad24542cf4c1aa3d6131.tar.bz2 lua-a76fa251998ea83679cfad24542cf4c1aa3d6131.zip | |
'ceillog2' now is exported (other modules may need it)
Diffstat (limited to 'lobject.c')
| -rw-r--r-- | lobject.c | 22 |
1 files changed, 20 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.26 2007/11/09 18:54:25 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.27 2007/12/19 17:24:38 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -33,7 +33,7 @@ const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; | |||
| 33 | ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if | 33 | ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if |
| 34 | ** eeeee != 0 and (xxx) otherwise. | 34 | ** eeeee != 0 and (xxx) otherwise. |
| 35 | */ | 35 | */ |
| 36 | int luaO_int2fb (unsigned int x) { | 36 | int luaO_int2fb (lu_int32 x) { |
| 37 | int e = 0; /* exponent */ | 37 | int e = 0; /* exponent */ |
| 38 | if (x < 8) return x; | 38 | if (x < 8) return x; |
| 39 | while (x >= 0x10) { | 39 | while (x >= 0x10) { |
| @@ -52,6 +52,24 @@ int luaO_fb2int (int x) { | |||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | int luaO_ceillog2 (unsigned int x) { | ||
| 56 | static const lu_byte log_2[256] = { | ||
| 57 | 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, | ||
| 58 | 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, | ||
| 59 | 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, | ||
| 60 | 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, | ||
| 61 | 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, | ||
| 62 | 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, | ||
| 63 | 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, | ||
| 64 | 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 | ||
| 65 | }; | ||
| 66 | int l = 0; | ||
| 67 | x--; | ||
| 68 | while (x >= 256) { l += 8; x >>= 8; } | ||
| 69 | return l + log_2[x]; | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 55 | int luaO_rawequalObj (const TValue *t1, const TValue *t2) { | 73 | int luaO_rawequalObj (const TValue *t1, const TValue *t2) { |
| 56 | if (ttype(t1) != ttype(t2)) return 0; | 74 | if (ttype(t1) != ttype(t2)) return 0; |
| 57 | else switch (ttype(t1)) { | 75 | else switch (ttype(t1)) { |
