diff options
author | Mike Pall <mike> | 2013-02-23 02:17:50 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2013-02-23 02:17:50 +0100 |
commit | 60e380fd936ef45b57e89d8df23ab16325f29e9b (patch) | |
tree | e4b60a535833ff6415e252ad228b965e9656a4a2 | |
parent | 73ef845fcaf65937ad63e9cf6b681cb3e61f4504 (diff) | |
download | luajit-60e380fd936ef45b57e89d8df23ab16325f29e9b.tar.gz luajit-60e380fd936ef45b57e89d8df23ab16325f29e9b.tar.bz2 luajit-60e380fd936ef45b57e89d8df23ab16325f29e9b.zip |
Replace table.getn/foreach/foreachi with bytecode builtins.
-rw-r--r-- | src/host/buildvm_libbc.h | 12 | ||||
-rw-r--r-- | src/lib_table.c | 68 | ||||
-rw-r--r-- | src/lj_dispatch.h | 2 | ||||
-rw-r--r-- | src/lj_ffrecord.c | 8 | ||||
-rw-r--r-- | src/vm_arm.dasc | 11 | ||||
-rw-r--r-- | src/vm_mips.dasc | 12 | ||||
-rw-r--r-- | src/vm_ppc.dasc | 8 | ||||
-rw-r--r-- | src/vm_x86.dasc | 15 |
8 files changed, 37 insertions, 99 deletions
diff --git a/src/host/buildvm_libbc.h b/src/host/buildvm_libbc.h index 6b0e1d03..a71aa630 100644 --- a/src/host/buildvm_libbc.h +++ b/src/host/buildvm_libbc.h | |||
@@ -4,12 +4,20 @@ static const int libbc_endian = 0; | |||
4 | 4 | ||
5 | static const uint8_t libbc_code[] = { | 5 | static const uint8_t libbc_code[] = { |
6 | 0,1,2,0,0,1,2,24,1,0,0,76,1,2,0,241,135,158,166,3,220,203,178,130,4,0,1,2,0, | 6 | 0,1,2,0,0,1,2,24,1,0,0,76,1,2,0,241,135,158,166,3,220,203,178,130,4,0,1,2,0, |
7 | 0,1,2,24,1,0,0,76,1,2,0,243,244,148,165,20,198,190,199,252,3,0 | 7 | 0,1,2,24,1,0,0,76,1,2,0,243,244,148,165,20,198,190,199,252,3,0,2,9,0,0,0,15, |
8 | 16,0,12,0,16,1,9,0,41,2,1,0,21,3,0,0,41,4,1,0,77,2,8,128,18,6,1,0,18,7,5,0, | ||
9 | 59,8,5,0,66,6,3,2,10,6,0,0,88,7,1,128,76,6,2,0,79,2,248,127,75,0,1,0,0,2,10, | ||
10 | 0,0,0,16,16,0,12,0,16,1,9,0,43,2,0,0,18,3,0,0,41,4,0,0,88,5,7,128,18,7,1,0, | ||
11 | 18,8,5,0,18,9,6,0,66,7,3,2,10,7,0,0,88,8,1,128,76,7,2,0,70,5,3,3,82,5,247,127, | ||
12 | 75,0,1,0,0,1,2,0,0,0,3,16,0,12,0,21,1,0,0,76,1,2,0,0 | ||
8 | }; | 13 | }; |
9 | 14 | ||
10 | static const struct { const char *name; int ofs; } libbc_map[] = { | 15 | static const struct { const char *name; int ofs; } libbc_map[] = { |
11 | {"math_deg",0}, | 16 | {"math_deg",0}, |
12 | {"math_rad",25}, | 17 | {"math_rad",25}, |
13 | {NULL,50} | 18 | {"table_foreachi",50}, |
19 | {"table_foreach",117}, | ||
20 | {"table_getn",188}, | ||
21 | {NULL,207} | ||
14 | }; | 22 | }; |
15 | 23 | ||
diff --git a/src/lib_table.c b/src/lib_table.c index 8d53a6cd..13aff24e 100644 --- a/src/lib_table.c +++ b/src/lib_table.c | |||
@@ -23,50 +23,34 @@ | |||
23 | 23 | ||
24 | #define LJLIB_MODULE_table | 24 | #define LJLIB_MODULE_table |
25 | 25 | ||
26 | LJLIB_CF(table_foreachi) | 26 | LJLIB_LUA(table_foreachi) /* |
27 | { | 27 | function(t, f) |
28 | GCtab *t = lj_lib_checktab(L, 1); | 28 | CHECK_tab(t) |
29 | GCfunc *func = lj_lib_checkfunc(L, 2); | 29 | CHECK_func(f) |
30 | MSize i, n = lj_tab_len(t); | 30 | for i=1,#t do |
31 | for (i = 1; i <= n; i++) { | 31 | local r = f(i, t[i]) |
32 | cTValue *val; | 32 | if r ~= nil then return r end |
33 | setfuncV(L, L->top, func); | 33 | end |
34 | setintV(L->top+1, i); | 34 | end |
35 | val = lj_tab_getint(t, (int32_t)i); | 35 | */ |
36 | if (val) { copyTV(L, L->top+2, val); } else { setnilV(L->top+2); } | ||
37 | L->top += 3; | ||
38 | lua_call(L, 2, 1); | ||
39 | if (!tvisnil(L->top-1)) | ||
40 | return 1; | ||
41 | L->top--; | ||
42 | } | ||
43 | return 0; | ||
44 | } | ||
45 | 36 | ||
46 | LJLIB_CF(table_foreach) | 37 | LJLIB_LUA(table_foreach) /* |
47 | { | 38 | function(t, f) |
48 | GCtab *t = lj_lib_checktab(L, 1); | 39 | CHECK_tab(t) |
49 | GCfunc *func = lj_lib_checkfunc(L, 2); | 40 | CHECK_func(f) |
50 | L->top = L->base+3; | 41 | for k, v in PAIRS(t) do |
51 | setnilV(L->top-1); | 42 | local r = f(k, v) |
52 | while (lj_tab_next(L, t, L->top-1)) { | 43 | if r ~= nil then return r end |
53 | copyTV(L, L->top+2, L->top); | 44 | end |
54 | copyTV(L, L->top+1, L->top-1); | 45 | end |
55 | setfuncV(L, L->top, func); | 46 | */ |
56 | L->top += 3; | ||
57 | lua_call(L, 2, 1); | ||
58 | if (!tvisnil(L->top-1)) | ||
59 | return 1; | ||
60 | L->top--; | ||
61 | } | ||
62 | return 0; | ||
63 | } | ||
64 | 47 | ||
65 | LJLIB_ASM(table_getn) LJLIB_REC(.) | 48 | LJLIB_LUA(table_getn) /* |
66 | { | 49 | function(t) |
67 | lj_lib_checktab(L, 1); | 50 | CHECK_tab(t) |
68 | return FFH_UNREACHABLE; | 51 | return #t |
69 | } | 52 | end |
53 | */ | ||
70 | 54 | ||
71 | LJLIB_CF(table_maxn) | 55 | LJLIB_CF(table_maxn) |
72 | { | 56 | { |
diff --git a/src/lj_dispatch.h b/src/lj_dispatch.h index a662439b..a03804af 100644 --- a/src/lj_dispatch.h +++ b/src/lj_dispatch.h | |||
@@ -60,7 +60,7 @@ typedef uint16_t HotCount; | |||
60 | #define HOTCOUNT_CALL 1 | 60 | #define HOTCOUNT_CALL 1 |
61 | 61 | ||
62 | /* This solves a circular dependency problem -- bump as needed. Sigh. */ | 62 | /* This solves a circular dependency problem -- bump as needed. Sigh. */ |
63 | #define GG_NUM_ASMFF 60 | 63 | #define GG_NUM_ASMFF 59 |
64 | 64 | ||
65 | #define GG_LEN_DDISP (BC__MAX + GG_NUM_ASMFF) | 65 | #define GG_LEN_DDISP (BC__MAX + GG_NUM_ASMFF) |
66 | #define GG_LEN_SDISP BC_FUNCF | 66 | #define GG_LEN_SDISP BC_FUNCF |
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 30d5c44e..51981477 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
@@ -729,14 +729,6 @@ static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd) | |||
729 | 729 | ||
730 | /* -- Table library fast functions ---------------------------------------- */ | 730 | /* -- Table library fast functions ---------------------------------------- */ |
731 | 731 | ||
732 | static void LJ_FASTCALL recff_table_getn(jit_State *J, RecordFFData *rd) | ||
733 | { | ||
734 | if (tref_istab(J->base[0])) | ||
735 | J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, J->base[0]); | ||
736 | /* else: Interpreter will throw. */ | ||
737 | UNUSED(rd); | ||
738 | } | ||
739 | |||
740 | static void LJ_FASTCALL recff_table_remove(jit_State *J, RecordFFData *rd) | 732 | static void LJ_FASTCALL recff_table_remove(jit_State *J, RecordFFData *rd) |
741 | { | 733 | { |
742 | TRef tab = J->base[0]; | 734 | TRef tab = J->base[0]; |
diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc index d999d5ff..6928e03b 100644 --- a/src/vm_arm.dasc +++ b/src/vm_arm.dasc | |||
@@ -1861,17 +1861,6 @@ static void build_subroutines(BuildCtx *ctx) | |||
1861 | |ffstring_case string_lower, 65 | 1861 | |ffstring_case string_lower, 65 |
1862 | |ffstring_case string_upper, 97 | 1862 | |ffstring_case string_upper, 97 |
1863 | | | 1863 | | |
1864 | |//-- Table library ------------------------------------------------------ | ||
1865 | | | ||
1866 | |.ffunc_1 table_getn | ||
1867 | | checktab CARG2, ->fff_fallback | ||
1868 | | .IOS mov RA, BASE | ||
1869 | | bl extern lj_tab_len // (GCtab *t) | ||
1870 | | // Returns uint32_t (but less than 2^31). | ||
1871 | | .IOS mov BASE, RA | ||
1872 | | mvn CARG2, #~LJ_TISNUM | ||
1873 | | b ->fff_restv | ||
1874 | | | ||
1875 | |//-- Bit library -------------------------------------------------------- | 1864 | |//-- Bit library -------------------------------------------------------- |
1876 | | | 1865 | | |
1877 | |// FP number to bit conversion for soft-float. Clobbers r0-r3. | 1866 | |// FP number to bit conversion for soft-float. Clobbers r0-r3. |
diff --git a/src/vm_mips.dasc b/src/vm_mips.dasc index 6db5801f..5808e182 100644 --- a/src/vm_mips.dasc +++ b/src/vm_mips.dasc | |||
@@ -1812,18 +1812,6 @@ static void build_subroutines(BuildCtx *ctx) | |||
1812 | |ffstring_case string_lower, 65 | 1812 | |ffstring_case string_lower, 65 |
1813 | |ffstring_case string_upper, 97 | 1813 | |ffstring_case string_upper, 97 |
1814 | | | 1814 | | |
1815 | |//-- Table library ------------------------------------------------------ | ||
1816 | | | ||
1817 | |.ffunc_1 table_getn | ||
1818 | | li AT, LJ_TTAB | ||
1819 | | bne CARG3, AT, ->fff_fallback | ||
1820 | |. load_got lj_tab_len | ||
1821 | | call_intern lj_tab_len // (GCtab *t) | ||
1822 | |. nop | ||
1823 | | // Returns uint32_t (but less than 2^31). | ||
1824 | | b ->fff_resi | ||
1825 | |. nop | ||
1826 | | | ||
1827 | |//-- Bit library -------------------------------------------------------- | 1815 | |//-- Bit library -------------------------------------------------------- |
1828 | | | 1816 | | |
1829 | |.macro .ffunc_bit, name | 1817 | |.macro .ffunc_bit, name |
diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc index d76e3a7b..bff50c59 100644 --- a/src/vm_ppc.dasc +++ b/src/vm_ppc.dasc | |||
@@ -2281,14 +2281,6 @@ static void build_subroutines(BuildCtx *ctx) | |||
2281 | |ffstring_case string_lower, 65 | 2281 | |ffstring_case string_lower, 65 |
2282 | |ffstring_case string_upper, 97 | 2282 | |ffstring_case string_upper, 97 |
2283 | | | 2283 | | |
2284 | |//-- Table library ------------------------------------------------------ | ||
2285 | | | ||
2286 | |.ffunc_1 table_getn | ||
2287 | | checktab CARG3; bne ->fff_fallback | ||
2288 | | bl extern lj_tab_len // (GCtab *t) | ||
2289 | | // Returns uint32_t (but less than 2^31). | ||
2290 | | b ->fff_resi | ||
2291 | | | ||
2292 | |//-- Bit library -------------------------------------------------------- | 2284 | |//-- Bit library -------------------------------------------------------- |
2293 | | | 2285 | | |
2294 | |.macro .ffunc_bit, name | 2286 | |.macro .ffunc_bit, name |
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index 0c4b0ce6..0a53ffde 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc | |||
@@ -2434,21 +2434,6 @@ static void build_subroutines(BuildCtx *ctx) | |||
2434 | |ffstring_case string_lower, 0x41, 0x5a | 2434 | |ffstring_case string_lower, 0x41, 0x5a |
2435 | |ffstring_case string_upper, 0x61, 0x7a | 2435 | |ffstring_case string_upper, 0x61, 0x7a |
2436 | | | 2436 | | |
2437 | |//-- Table library ------------------------------------------------------ | ||
2438 | | | ||
2439 | |.ffunc_1 table_getn | ||
2440 | | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback | ||
2441 | | mov RB, BASE // Save BASE. | ||
2442 | | mov TAB:FCARG1, [BASE] | ||
2443 | | call extern lj_tab_len@4 // LJ_FASTCALL (GCtab *t) | ||
2444 | | // Length of table returned in eax (RD). | ||
2445 | | mov BASE, RB // Restore BASE. | ||
2446 | |.if DUALNUM | ||
2447 | | mov RB, RD; jmp ->fff_resi | ||
2448 | |.else | ||
2449 | | cvtsi2sd xmm0, RD; jmp ->fff_resxmm0 | ||
2450 | |.endif | ||
2451 | | | ||
2452 | |//-- Bit library -------------------------------------------------------- | 2437 | |//-- Bit library -------------------------------------------------------- |
2453 | | | 2438 | | |
2454 | |.define TOBIT_BIAS, 0x59c00000 // 2^52 + 2^51 (float, not double!). | 2439 | |.define TOBIT_BIAS, 0x59c00000 // 2^52 + 2^51 (float, not double!). |