aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-02-05 18:54:08 +0100
committerMike Pall <mike>2011-02-05 18:54:08 +0100
commitbf05209e1446aa13416b3dfffe021c85057b9a5d (patch)
tree7082cc97aab24dd010617e6001bfa8ee2548c116 /src
parentda3f256a52504ae6019875a80de1e0f7d1a19ebd (diff)
downloadluajit-bf05209e1446aa13416b3dfffe021c85057b9a5d.tar.gz
luajit-bf05209e1446aa13416b3dfffe021c85057b9a5d.tar.bz2
luajit-bf05209e1446aa13416b3dfffe021c85057b9a5d.zip
FFI: Optimize snapshots for cdata comparisons.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.dep6
-rw-r--r--src/lj_crecord.c10
-rw-r--r--src/lj_jit.h1
-rw-r--r--src/lj_record.c14
4 files changed, 23 insertions, 8 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep
index b869fdff..de46c57e 100644
--- a/src/Makefile.dep
+++ b/src/Makefile.dep
@@ -75,9 +75,9 @@ lj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
75 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cparse.h lj_frame.h \ 75 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cparse.h lj_frame.h \
76 lj_bc.h lj_vm.h lj_char.h 76 lj_bc.h lj_vm.h lj_char.h
77lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ 77lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
78 lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_gc.h lj_cparse.h \ 78 lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h \
79 lj_cconv.h lj_clib.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h \ 79 lj_gc.h lj_cparse.h lj_cconv.h lj_clib.h lj_ir.h lj_jit.h lj_iropt.h \
80 lj_dispatch.h lj_bc.h lj_traceerr.h lj_ffrecord.h lj_crecord.h 80 lj_trace.h lj_dispatch.h lj_traceerr.h lj_ffrecord.h lj_crecord.h
81lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ 81lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
82 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h 82 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h
83lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ 83lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index e5413fb3..b4bfd0c2 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -13,6 +13,7 @@
13#include "lj_err.h" 13#include "lj_err.h"
14#include "lj_str.h" 14#include "lj_str.h"
15#include "lj_tab.h" 15#include "lj_tab.h"
16#include "lj_frame.h"
16#include "lj_ctype.h" 17#include "lj_ctype.h"
17#include "lj_cparse.h" 18#include "lj_cparse.h"
18#include "lj_cconv.h" 19#include "lj_cconv.h"
@@ -835,6 +836,15 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd)
835 err_type: 836 err_type:
836 lj_trace_err(J, LJ_TRERR_BADTYPE); 837 lj_trace_err(J, LJ_TRERR_BADTYPE);
837 } 838 }
839 /* Fixup cdata comparisons, too. Avoids some cdata escapes. */
840 if (J->postproc == LJ_POST_FIXGUARD && frame_iscont(J->L->base-1)) {
841 const BCIns *pc = frame_contpc(J->L->base-1) - 1;
842 if (bc_op(*pc) <= BC_ISNEP) {
843 setframe_pc(&J2G(J)->tmptv, pc);
844 J2G(J)->tmptv.u32.lo = ((tref_istrue(tr) ^ bc_op(*pc)) & 1);
845 J->postproc = LJ_POST_FIXCOMP;
846 }
847 }
838 J->base[0] = tr; 848 J->base[0] = tr;
839 } 849 }
840} 850}
diff --git a/src/lj_jit.h b/src/lj_jit.h
index 38970fc7..2f3df2a0 100644
--- a/src/lj_jit.h
+++ b/src/lj_jit.h
@@ -111,6 +111,7 @@ typedef enum {
111/* Post-processing action. */ 111/* Post-processing action. */
112typedef enum { 112typedef enum {
113 LJ_POST_NONE, /* No action. */ 113 LJ_POST_NONE, /* No action. */
114 LJ_POST_FIXCOMP, /* Fixup comparison and emit pending guard. */
114 LJ_POST_FIXGUARD /* Fixup and emit pending guard. */ 115 LJ_POST_FIXGUARD /* Fixup and emit pending guard. */
115} PostProc; 116} PostProc;
116 117
diff --git a/src/lj_record.c b/src/lj_record.c
index 94bd0ed4..d8c67499 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -1355,10 +1355,10 @@ static void rec_comp_prep(jit_State *J)
1355} 1355}
1356 1356
1357/* Fixup comparison. */ 1357/* Fixup comparison. */
1358static void rec_comp_fixup(jit_State *J, int cond) 1358static void rec_comp_fixup(jit_State *J, const BCIns *pc, int cond)
1359{ 1359{
1360 BCIns jmpins = J->pc[1]; 1360 BCIns jmpins = pc[1];
1361 const BCIns *npc = J->pc + 2 + (cond ? bc_j(jmpins) : 0); 1361 const BCIns *npc = pc + 2 + (cond ? bc_j(jmpins) : 0);
1362 SnapShot *snap = &J->cur.snap[J->cur.nsnap-1]; 1362 SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];
1363 /* Set PC to opposite target to avoid re-recording the comp. in side trace. */ 1363 /* Set PC to opposite target to avoid re-recording the comp. in side trace. */
1364 J->cur.snapmap[snap->mapofs + snap->nent] = SNAP_MKPC(npc); 1364 J->cur.snapmap[snap->mapofs + snap->nent] = SNAP_MKPC(npc);
@@ -1383,6 +1383,10 @@ void lj_record_ins(jit_State *J)
1383 /* Perform post-processing action before recording the next instruction. */ 1383 /* Perform post-processing action before recording the next instruction. */
1384 if (LJ_UNLIKELY(J->postproc != LJ_POST_NONE)) { 1384 if (LJ_UNLIKELY(J->postproc != LJ_POST_NONE)) {
1385 switch (J->postproc) { 1385 switch (J->postproc) {
1386 case LJ_POST_FIXCOMP: /* Fixup comparison. */
1387 pc = frame_pc(&J2G(J)->tmptv);
1388 rec_comp_fixup(J, pc, (!tvistruecond(&J2G(J)->tmptv2) ^ (bc_op(*pc)&1)));
1389 /* fallthrough */
1386 case LJ_POST_FIXGUARD: /* Fixup and emit pending guard. */ 1390 case LJ_POST_FIXGUARD: /* Fixup and emit pending guard. */
1387 if (!tvistruecond(&J2G(J)->tmptv2)) { 1391 if (!tvistruecond(&J2G(J)->tmptv2)) {
1388 BCReg s; 1392 BCReg s;
@@ -1505,7 +1509,7 @@ void lj_record_ins(jit_State *J)
1505 break; 1509 break;
1506 } 1510 }
1507 emitir(IRTG(irop, ta), ra, rc); 1511 emitir(IRTG(irop, ta), ra, rc);
1508 rec_comp_fixup(J, ((int)op ^ irop) & 1); 1512 rec_comp_fixup(J, J->pc, ((int)op ^ irop) & 1);
1509 } 1513 }
1510 break; 1514 break;
1511 1515
@@ -1529,7 +1533,7 @@ void lj_record_ins(jit_State *J)
1529 rec_mm_equal(J, &ix, (int)op); 1533 rec_mm_equal(J, &ix, (int)op);
1530 break; 1534 break;
1531 } 1535 }
1532 rec_comp_fixup(J, ((int)op & 1) == !diff); 1536 rec_comp_fixup(J, J->pc, ((int)op & 1) == !diff);
1533 } 1537 }
1534 break; 1538 break;
1535 1539