aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2010-09-30 21:55:32 +0200
committerMike Pall <mike>2010-09-30 21:55:32 +0200
commitac76493df113e6e648b03e61c0fa56c5754e832d (patch)
treee79e60ea60be028b1ae10587b80eb5f2aa33857d
parentfce05fd6e18a9b1f032f5c7409e1516214220f3c (diff)
downloadluajit-ac76493df113e6e648b03e61c0fa56c5754e832d.tar.gz
luajit-ac76493df113e6e648b03e61c0fa56c5754e832d.tar.bz2
luajit-ac76493df113e6e648b03e61c0fa56c5754e832d.zip
Specialize bytecode for pairs()/next() iterator. Speedup: 3.5x.
Parser predict pairs/next and emits specialized bytecode. Bytecode is descpecialized at runtime if the prediction was wrong. Store slot index in hidden control var to avoid key lookups.
-rw-r--r--src/buildvm_ppc.dasc8
-rw-r--r--src/buildvm_x64.h255
-rw-r--r--src/buildvm_x64win.h259
-rw-r--r--src/buildvm_x86.dasc103
-rw-r--r--src/buildvm_x86.h253
-rw-r--r--src/lib_base.c3
-rw-r--r--src/lj_bc.h5
-rw-r--r--src/lj_parse.c100
-rw-r--r--src/lj_record.c2
9 files changed, 634 insertions, 354 deletions
diff --git a/src/buildvm_ppc.dasc b/src/buildvm_ppc.dasc
index 6ab8f7f7..43c3caca 100644
--- a/src/buildvm_ppc.dasc
+++ b/src/buildvm_ppc.dasc
@@ -2450,6 +2450,14 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2450 | ins_call 2450 | ins_call
2451 break; 2451 break;
2452 2452
2453 case BC_ITERN:
2454 | NYI
2455 break;
2456
2457 case BC_ISNEXT:
2458 | NYI
2459 break;
2460
2453 case BC_VARG: 2461 case BC_VARG:
2454 | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8 2462 | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
2455 | lwz TMP0, FRAME_PC(BASE) 2463 | lwz TMP0, FRAME_PC(BASE)
diff --git a/src/buildvm_x64.h b/src/buildvm_x64.h
index b3022a17..8bcfd63f 100644
--- a/src/buildvm_x64.h
+++ b/src/buildvm_x64.h
@@ -12,7 +12,7 @@
12#define DASM_SECTION_CODE_OP 0 12#define DASM_SECTION_CODE_OP 0
13#define DASM_SECTION_CODE_SUB 1 13#define DASM_SECTION_CODE_SUB 1
14#define DASM_MAXSECTION 2 14#define DASM_MAXSECTION 2
15static const unsigned char build_actionlist[13946] = { 15static const unsigned char build_actionlist[14263] = {
16 254,1,248,10,252,247,195,237,15,132,244,11,131,227,252,248,41,218,72,141, 16 254,1,248,10,252,247,195,237,15,132,244,11,131,227,252,248,41,218,72,141,
17 76,25,252,248,139,90,252,252,199,68,10,4,237,248,12,131,192,1,137,68,36,4, 17 76,25,252,248,139,90,252,252,199,68,10,4,237,248,12,131,192,1,137,68,36,4,
18 252,247,195,237,15,132,244,13,248,14,129,252,243,239,252,247,195,237,15,133, 18 252,247,195,237,15,132,244,13,248,14,129,252,243,239,252,247,195,237,15,133,
@@ -636,58 +636,73 @@ static const unsigned char build_actionlist[13946] = {
636 105,232,72,139,65,252,240,72,137,41,72,137,65,8,139,105,224,139,65,228,137, 636 105,232,72,139,65,252,240,72,137,41,72,137,65,8,139,105,224,139,65,228,137,
637 105,252,248,137,65,252,252,129,252,248,239,184,237,15,133,244,28,137,202, 637 105,252,248,137,65,252,252,129,252,248,239,184,237,15,133,244,28,137,202,
638 137,90,252,252,139,157,233,139,11,15,182,252,233,15,182,205,131,195,4,65, 638 137,90,252,252,139,157,233,139,11,15,182,252,233,15,182,205,131,195,4,65,
639 252,255,36,252,238,255,15,182,252,236,15,182,192,68,137,60,36,68,141,188, 639 252,255,36,252,238,255,68,137,60,36,68,137,116,36,4,139,108,202,252,240,139,
640 253,194,233,141,12,202,68,43,122,252,252,133,252,237,15,132,244,251,141,108, 640 68,202,252,248,68,139,181,233,131,195,4,68,139,189,233,248,1,68,57,252,240,
641 252,233,252,248,65,57,215,15,131,244,248,248,1,73,139,71,252,248,65,131,199, 641 15,131,244,251,65,129,124,253,199,4,239,15,132,244,250,255,252,242,15,42,
642 8,72,137,1,131,193,8,57,252,233,15,131,244,249,65,57,215,15,130,244,1,248, 642 192,255,219,68,202,252,248,255,73,139,44,199,72,137,108,202,8,131,192,1,255,
643 2,199,65,4,237,131,193,8,57,252,233,15,130,244,2,248,3,68,139,60,36,139,3, 643 137,68,202,252,248,248,2,15,183,67,252,254,141,156,253,131,233,248,3,68,139,
644 15,182,204,15,182,232,131,195,4,193,232,16,65,252,255,36,252,238,248,5,199, 644 116,36,4,68,139,60,36,139,3,15,182,204,15,182,232,131,195,4,193,232,16,65,
645 68,36,4,1,0,0,0,137,208,68,41,252,248,15,134,244,3,137,197,193,252,237,3, 645 252,255,36,252,238,248,4,131,192,1,255,137,68,202,252,248,255,252,233,244,
646 131,197,1,137,108,36,4,139,108,36,24,1,200,59,133,233,15,135,244,253,248, 646 1,248,5,68,41,252,240,248,6,59,133,233,15,135,244,3,68,105,252,248,239,68,
647 6,255,73,139,71,252,248,65,131,199,8,72,137,1,131,193,8,65,57,215,15,130, 647 3,189,233,65,129,191,233,239,15,132,244,253,70,141,116,48,1,73,139,175,233,
648 244,6,252,233,244,3,248,7,137,149,233,137,141,233,137,92,36,28,65,41,215, 648 73,139,135,233,72,137,44,202,72,137,68,202,8,68,137,116,202,252,248,252,233,
649 139,116,36,4,131,252,238,1,137,252,239,232,251,1,0,139,149,233,139,141,233, 649 244,2,248,7,131,192,1,252,233,244,6,255,129,124,253,202,252,236,239,15,133,
650 65,1,215,252,233,244,6,255,193,225,3,255,248,1,139,90,252,252,137,68,36,4, 650 244,251,139,108,202,232,129,124,253,202,252,244,239,15,133,244,251,129,124,
651 252,247,195,237,15,133,244,253,255,248,13,65,137,215,131,232,1,15,132,244, 651 253,202,252,252,239,15,133,244,251,128,189,233,235,15,133,244,251,141,156,
652 249,248,2,73,139,44,15,73,137,111,252,248,65,131,199,8,131,232,1,15,133,244, 652 253,131,233,199,68,202,252,248,0,0,0,0,248,1,139,3,15,182,204,15,182,232,
653 2,248,3,139,68,36,4,15,182,107,252,255,248,5,57,197,15,135,244,252,255,72, 653 131,195,4,193,232,16,65,252,255,36,252,238,248,5,198,67,252,252,235,141,156,
654 139,44,10,72,137,106,252,248,255,248,5,56,67,252,255,15,135,244,252,255,15, 654 253,131,233,198,3,235,252,233,244,1,255,15,182,252,236,15,182,192,68,137,
655 182,75,252,253,72,252,247,209,141,20,202,68,139,122,252,248,69,139,191,233, 655 60,36,68,141,188,253,194,233,141,12,202,68,43,122,252,252,133,252,237,15,
656 69,139,191,233,139,3,15,182,204,15,182,232,131,195,4,193,232,16,65,252,255, 656 132,244,251,141,108,252,233,252,248,65,57,215,15,131,244,248,248,1,73,139,
657 36,252,238,248,6,255,65,199,71,252,252,237,65,131,199,8,255,199,68,194,252, 657 71,252,248,65,131,199,8,72,137,1,131,193,8,57,252,233,15,131,244,249,65,57,
658 244,237,255,131,192,1,252,233,244,5,248,7,141,171,233,252,247,197,237,15, 658 215,15,130,244,1,248,2,199,65,4,237,131,193,8,57,252,233,15,130,244,2,248,
659 133,244,14,41,252,234,255,1,252,233,255,137,221,209,252,237,129,229,239,102, 659 3,68,139,60,36,139,3,15,182,204,15,182,232,131,195,4,193,232,16,65,252,255,
660 65,131,172,253,46,233,1,15,132,244,140,255,141,12,202,255,129,121,253,4,239, 660 36,252,238,248,5,199,68,36,4,1,0,0,0,137,208,68,41,252,248,15,134,244,3,137,
661 15,135,244,53,129,121,253,12,239,15,135,244,53,255,139,105,20,255,129,252, 661 197,193,252,237,3,131,197,1,137,108,36,4,139,108,36,24,1,200,59,133,233,15,
662 253,239,15,135,244,53,255,252,242,15,16,1,252,242,15,16,73,8,255,252,242, 662 135,244,253,248,6,255,73,139,71,252,248,65,131,199,8,72,137,1,131,193,8,65,
663 15,88,65,16,252,242,15,17,1,133,252,237,15,136,244,249,255,15,140,244,249, 663 57,215,15,130,244,6,252,233,244,3,248,7,137,149,233,137,141,233,137,92,36,
664 255,102,15,46,200,248,1,252,242,15,17,65,24,255,221,65,8,221,1,255,220,65, 664 28,65,41,215,139,116,36,4,131,252,238,1,137,252,239,232,251,1,0,139,149,233,
665 16,221,17,221,81,24,133,252,237,15,136,244,247,255,221,81,24,15,140,244,247, 665 139,141,233,65,1,215,252,233,244,6,255,193,225,3,255,248,1,139,90,252,252,
666 255,217,201,248,1,255,15,183,67,252,254,255,15,131,244,248,141,156,253,131, 666 137,68,36,4,252,247,195,237,15,133,244,253,255,248,13,65,137,215,131,232,
667 233,255,141,156,253,131,233,15,183,67,252,254,15,131,245,255,15,130,244,248, 667 1,15,132,244,249,248,2,73,139,44,15,73,137,111,252,248,65,131,199,8,131,232,
668 141,156,253,131,233,255,248,3,102,15,46,193,252,233,244,1,255,141,12,202, 668 1,15,133,244,2,248,3,139,68,36,4,15,182,107,252,255,248,5,57,197,15,135,244,
669 139,105,4,129,252,253,239,15,132,244,247,255,137,105,252,252,139,41,137,105, 669 252,255,72,139,44,10,72,137,106,252,248,255,248,5,56,67,252,255,15,135,244,
670 252,248,252,233,245,255,141,156,253,131,233,139,1,137,105,252,252,137,65, 670 252,255,15,182,75,252,253,72,252,247,209,141,20,202,68,139,122,252,248,69,
671 252,248,255,65,139,142,233,139,4,129,72,139,128,233,139,108,36,24,65,137, 671 139,191,233,69,139,191,233,139,3,15,182,204,15,182,232,131,195,4,193,232,
672 150,233,65,137,174,233,76,137,36,36,76,137,108,36,8,72,131,252,236,16,252, 672 16,65,252,255,36,252,238,248,6,255,65,199,71,252,252,237,65,131,199,8,255,
673 255,224,255,141,156,253,131,233,139,3,15,182,204,15,182,232,131,195,4,193, 673 199,68,194,252,244,237,255,131,192,1,252,233,244,5,248,7,141,171,233,252,
674 232,16,65,252,255,36,252,238,255,137,221,209,252,237,129,229,239,102,65,131, 674 247,197,237,15,133,244,14,41,252,234,255,1,252,233,255,137,221,209,252,237,
675 172,253,46,233,1,15,132,244,142,255,68,139,187,233,139,108,36,24,141,12,202, 675 129,229,239,102,65,131,172,253,46,233,1,15,132,244,140,255,141,12,202,255,
676 59,141,233,15,135,244,23,15,182,139,233,57,200,15,134,244,249,248,2,255,15, 676 129,121,253,4,239,15,135,244,53,129,121,253,12,239,15,135,244,53,255,139,
677 183,67,252,254,252,233,245,255,248,3,199,68,194,252,252,237,131,192,1,57, 677 105,20,255,129,252,253,239,15,135,244,53,255,252,242,15,16,1,252,242,15,16,
678 200,15,134,244,3,252,233,244,2,255,141,44,197,237,141,4,194,68,139,122,252, 678 73,8,255,252,242,15,88,65,16,252,242,15,17,1,133,252,237,15,136,244,249,255,
679 248,137,104,252,252,68,137,120,252,248,139,108,36,24,141,12,200,59,141,233, 679 15,140,244,249,255,102,15,46,200,248,1,252,242,15,17,65,24,255,221,65,8,221,
680 15,135,244,22,137,209,137,194,15,182,171,233,133,252,237,15,132,244,248,248, 680 1,255,220,65,16,221,17,221,81,24,133,252,237,15,136,244,247,255,221,81,24,
681 1,131,193,8,57,209,15,131,244,249,68,139,121,252,248,68,137,56,68,139,121, 681 15,140,244,247,255,217,201,248,1,255,15,183,67,252,254,255,15,131,244,248,
682 252,252,68,137,120,4,131,192,8,199,65,252,252,237,131,252,237,1,15,133,244, 682 141,156,253,131,233,255,141,156,253,131,233,15,183,67,252,254,15,131,245,
683 1,248,2,255,68,139,187,233,139,3,15,182,204,15,182,232,131,195,4,193,232, 683 255,15,130,244,248,141,156,253,131,233,255,248,3,102,15,46,193,252,233,244,
684 16,65,252,255,36,252,238,255,248,3,199,64,4,237,131,192,8,131,252,237,1,15, 684 1,255,141,12,202,139,105,4,129,252,253,239,15,132,244,247,255,137,105,252,
685 133,244,3,252,233,244,2,255,139,106,252,248,76,139,189,233,139,108,36,24, 685 252,139,41,137,105,252,248,252,233,245,255,141,156,253,131,233,139,1,137,
686 141,68,194,252,248,137,149,233,141,136,233,59,141,233,137,133,233,255,137, 686 105,252,252,137,65,252,248,255,65,139,142,233,139,4,129,72,139,128,233,139,
687 252,239,255,76,137,252,254,137,252,239,255,15,135,244,21,65,199,134,233,237, 687 108,36,24,65,137,150,233,65,137,174,233,76,137,36,36,76,137,108,36,8,72,131,
688 255,65,252,255,215,255,65,252,255,150,233,255,65,199,134,233,237,139,149, 688 252,236,16,252,255,224,255,141,156,253,131,233,139,3,15,182,204,15,182,232,
689 233,141,12,194,252,247,217,3,141,233,139,90,252,252,252,233,244,12,255,254, 689 131,195,4,193,232,16,65,252,255,36,252,238,255,137,221,209,252,237,129,229,
690 0 690 239,102,65,131,172,253,46,233,1,15,132,244,142,255,68,139,187,233,139,108,
691 36,24,141,12,202,59,141,233,15,135,244,23,15,182,139,233,57,200,15,134,244,
692 249,248,2,255,15,183,67,252,254,252,233,245,255,248,3,199,68,194,252,252,
693 237,131,192,1,57,200,15,134,244,3,252,233,244,2,255,141,44,197,237,141,4,
694 194,68,139,122,252,248,137,104,252,252,68,137,120,252,248,139,108,36,24,141,
695 12,200,59,141,233,15,135,244,22,137,209,137,194,15,182,171,233,133,252,237,
696 15,132,244,248,248,1,131,193,8,57,209,15,131,244,249,68,139,121,252,248,68,
697 137,56,68,139,121,252,252,68,137,120,4,131,192,8,199,65,252,252,237,131,252,
698 237,1,15,133,244,1,248,2,255,68,139,187,233,139,3,15,182,204,15,182,232,131,
699 195,4,193,232,16,65,252,255,36,252,238,255,248,3,199,64,4,237,131,192,8,131,
700 252,237,1,15,133,244,3,252,233,244,2,255,139,106,252,248,76,139,189,233,139,
701 108,36,24,141,68,194,252,248,137,149,233,141,136,233,59,141,233,137,133,233,
702 255,137,252,239,255,76,137,252,254,137,252,239,255,15,135,244,21,65,199,134,
703 233,237,255,65,252,255,215,255,65,252,255,150,233,255,65,199,134,233,237,
704 139,149,233,141,12,194,252,247,217,3,141,233,139,90,252,252,252,233,244,12,
705 255,254,0
691}; 706};
692 707
693enum { 708enum {
@@ -1982,9 +1997,35 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
1982 dasm_put(Dst, 12823, LJ_TFUNC, 2+1, Dt7(->pc)); 1997 dasm_put(Dst, 12823, LJ_TFUNC, 2+1, Dt7(->pc));
1983 break; 1998 break;
1984 1999
2000 case BC_ITERN:
2001#if LJ_HASJIT
2002#endif
2003 dasm_put(Dst, 12895, Dt6(->asize), Dt6(->array), LJ_TNIL);
2004 if (sse) {
2005 dasm_put(Dst, 12947);
2006 } else {
2007 dasm_put(Dst, 12953);
2008 }
2009 dasm_put(Dst, 12959);
2010 if (sse) {
2011 dasm_put(Dst, 9917);
2012 } else {
2013 dasm_put(Dst, 9929);
2014 }
2015 dasm_put(Dst, 12972, -BCBIAS_J*4);
2016 if (!sse) {
2017 dasm_put(Dst, 13026);
2018 }
2019 dasm_put(Dst, 13032, Dt6(->hmask), sizeof(Node), Dt6(->node), DtB(->val.it), LJ_TNIL, DtB(->key), DtB(->val));
2020 break;
2021
2022 case BC_ISNEXT:
2023 dasm_put(Dst, 13111, LJ_TFUNC, LJ_TTAB, LJ_TNIL, Dt8(->ffid), FF_next_N, -BCBIAS_J*4, BC_JMP, -BCBIAS_J*4, BC_ITERC);
2024 break;
2025
1985 case BC_VARG: 2026 case BC_VARG:
1986 dasm_put(Dst, 12895, (8+FRAME_VARG), LJ_TNIL, Dt1(->maxstack)); 2027 dasm_put(Dst, 13212, (8+FRAME_VARG), LJ_TNIL, Dt1(->maxstack));
1987 dasm_put(Dst, 13062, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top)); 2028 dasm_put(Dst, 13379, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top));
1988 break; 2029 break;
1989 2030
1990 /* -- Returns ----------------------------------------------------------- */ 2031 /* -- Returns ----------------------------------------------------------- */
@@ -1995,30 +2036,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
1995 2036
1996 case BC_RET: case BC_RET0: case BC_RET1: 2037 case BC_RET: case BC_RET0: case BC_RET1:
1997 if (op != BC_RET0) { 2038 if (op != BC_RET0) {
1998 dasm_put(Dst, 13132); 2039 dasm_put(Dst, 13449);
1999 } 2040 }
2000 dasm_put(Dst, 13136, FRAME_TYPE); 2041 dasm_put(Dst, 13453, FRAME_TYPE);
2001 switch (op) { 2042 switch (op) {
2002 case BC_RET: 2043 case BC_RET:
2003 dasm_put(Dst, 13155); 2044 dasm_put(Dst, 13472);
2004 break; 2045 break;
2005 case BC_RET1: 2046 case BC_RET1:
2006 dasm_put(Dst, 13209); 2047 dasm_put(Dst, 13526);
2007 /* fallthrough */ 2048 /* fallthrough */
2008 case BC_RET0: 2049 case BC_RET0:
2009 dasm_put(Dst, 13219); 2050 dasm_put(Dst, 13536);
2010 default: 2051 default:
2011 break; 2052 break;
2012 } 2053 }
2013 dasm_put(Dst, 13230, Dt7(->pc), PC2PROTO(k)); 2054 dasm_put(Dst, 13547, Dt7(->pc), PC2PROTO(k));
2014 if (op == BC_RET) { 2055 if (op == BC_RET) {
2015 dasm_put(Dst, 13278, LJ_TNIL); 2056 dasm_put(Dst, 13595, LJ_TNIL);
2016 } else { 2057 } else {
2017 dasm_put(Dst, 13289, LJ_TNIL); 2058 dasm_put(Dst, 13606, LJ_TNIL);
2018 } 2059 }
2019 dasm_put(Dst, 13296, -FRAME_VARG, FRAME_TYPEP); 2060 dasm_put(Dst, 13613, -FRAME_VARG, FRAME_TYPEP);
2020 if (op != BC_RET0) { 2061 if (op != BC_RET0) {
2021 dasm_put(Dst, 13320); 2062 dasm_put(Dst, 13637);
2022 } 2063 }
2023 dasm_put(Dst, 4531); 2064 dasm_put(Dst, 4531);
2024 break; 2065 break;
@@ -2028,7 +2069,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2028 2069
2029 case BC_FORL: 2070 case BC_FORL:
2030#if LJ_HASJIT 2071#if LJ_HASJIT
2031 dasm_put(Dst, 13324, HOTCOUNT_PCMASK, GG_DISP2HOT); 2072 dasm_put(Dst, 13641, HOTCOUNT_PCMASK, GG_DISP2HOT);
2032#endif 2073#endif
2033 break; 2074 break;
2034 2075
@@ -2040,57 +2081,57 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2040 case BC_FORI: 2081 case BC_FORI:
2041 case BC_IFORL: 2082 case BC_IFORL:
2042 vk = (op == BC_IFORL || op == BC_JFORL); 2083 vk = (op == BC_IFORL || op == BC_JFORL);
2043 dasm_put(Dst, 13345); 2084 dasm_put(Dst, 13662);
2044 if (!vk) { 2085 if (!vk) {
2045 dasm_put(Dst, 13349, LJ_TISNUM, LJ_TISNUM); 2086 dasm_put(Dst, 13666, LJ_TISNUM, LJ_TISNUM);
2046 } 2087 }
2047 dasm_put(Dst, 13368); 2088 dasm_put(Dst, 13685);
2048 if (!vk) { 2089 if (!vk) {
2049 dasm_put(Dst, 13372, LJ_TISNUM); 2090 dasm_put(Dst, 13689, LJ_TISNUM);
2050 } 2091 }
2051 if (sse) { 2092 if (sse) {
2052 dasm_put(Dst, 13381); 2093 dasm_put(Dst, 13698);
2053 if (vk) { 2094 if (vk) {
2054 dasm_put(Dst, 13393); 2095 dasm_put(Dst, 13710);
2055 } else { 2096 } else {
2056 dasm_put(Dst, 13412); 2097 dasm_put(Dst, 13729);
2057 } 2098 }
2058 dasm_put(Dst, 13417); 2099 dasm_put(Dst, 13734);
2059 } else { 2100 } else {
2060 dasm_put(Dst, 13430); 2101 dasm_put(Dst, 13747);
2061 if (vk) { 2102 if (vk) {
2062 dasm_put(Dst, 13436); 2103 dasm_put(Dst, 13753);
2063 } else { 2104 } else {
2064 dasm_put(Dst, 13452); 2105 dasm_put(Dst, 13769);
2065 } 2106 }
2066 dasm_put(Dst, 13460); 2107 dasm_put(Dst, 13777);
2067 if (cmov) { 2108 if (cmov) {
2068 dasm_put(Dst, 9460); 2109 dasm_put(Dst, 9460);
2069 } else { 2110 } else {
2070 dasm_put(Dst, 9466); 2111 dasm_put(Dst, 9466);
2071 } 2112 }
2072 if (!cmov) { 2113 if (!cmov) {
2073 dasm_put(Dst, 13465); 2114 dasm_put(Dst, 13782);
2074 } 2115 }
2075 } 2116 }
2076 if (op == BC_FORI) { 2117 if (op == BC_FORI) {
2077 dasm_put(Dst, 13471, -BCBIAS_J*4); 2118 dasm_put(Dst, 13788, -BCBIAS_J*4);
2078 } else if (op == BC_JFORI) { 2119 } else if (op == BC_JFORI) {
2079 dasm_put(Dst, 13481, -BCBIAS_J*4, BC_JLOOP); 2120 dasm_put(Dst, 13798, -BCBIAS_J*4, BC_JLOOP);
2080 } else if (op == BC_IFORL) { 2121 } else if (op == BC_IFORL) {
2081 dasm_put(Dst, 13495, -BCBIAS_J*4); 2122 dasm_put(Dst, 13812, -BCBIAS_J*4);
2082 } else { 2123 } else {
2083 dasm_put(Dst, 13491, BC_JLOOP); 2124 dasm_put(Dst, 13808, BC_JLOOP);
2084 } 2125 }
2085 dasm_put(Dst, 9495); 2126 dasm_put(Dst, 9495);
2086 if (sse) { 2127 if (sse) {
2087 dasm_put(Dst, 13505); 2128 dasm_put(Dst, 13822);
2088 } 2129 }
2089 break; 2130 break;
2090 2131
2091 case BC_ITERL: 2132 case BC_ITERL:
2092#if LJ_HASJIT 2133#if LJ_HASJIT
2093 dasm_put(Dst, 13324, HOTCOUNT_PCMASK, GG_DISP2HOT); 2134 dasm_put(Dst, 13641, HOTCOUNT_PCMASK, GG_DISP2HOT);
2094#endif 2135#endif
2095 break; 2136 break;
2096 2137
@@ -2099,18 +2140,18 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2099 break; 2140 break;
2100#endif 2141#endif
2101 case BC_IITERL: 2142 case BC_IITERL:
2102 dasm_put(Dst, 13516, LJ_TNIL); 2143 dasm_put(Dst, 13833, LJ_TNIL);
2103 if (op == BC_JITERL) { 2144 if (op == BC_JITERL) {
2104 dasm_put(Dst, 13531, BC_JLOOP); 2145 dasm_put(Dst, 13848, BC_JLOOP);
2105 } else { 2146 } else {
2106 dasm_put(Dst, 13545, -BCBIAS_J*4); 2147 dasm_put(Dst, 13862, -BCBIAS_J*4);
2107 } 2148 }
2108 dasm_put(Dst, 9799); 2149 dasm_put(Dst, 9799);
2109 break; 2150 break;
2110 2151
2111 case BC_LOOP: 2152 case BC_LOOP:
2112#if LJ_HASJIT 2153#if LJ_HASJIT
2113 dasm_put(Dst, 13324, HOTCOUNT_PCMASK, GG_DISP2HOT); 2154 dasm_put(Dst, 13641, HOTCOUNT_PCMASK, GG_DISP2HOT);
2114#endif 2155#endif
2115 break; 2156 break;
2116 2157
@@ -2120,12 +2161,12 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2120 2161
2121 case BC_JLOOP: 2162 case BC_JLOOP:
2122#if LJ_HASJIT 2163#if LJ_HASJIT
2123 dasm_put(Dst, 13561, DISPATCH_J(trace), DtD(->mcode), DISPATCH_GL(jit_base), DISPATCH_GL(jit_L)); 2164 dasm_put(Dst, 13878, DISPATCH_J(trace), DtD(->mcode), DISPATCH_GL(jit_base), DISPATCH_GL(jit_L));
2124#endif 2165#endif
2125 break; 2166 break;
2126 2167
2127 case BC_JMP: 2168 case BC_JMP:
2128 dasm_put(Dst, 13602, -BCBIAS_J*4); 2169 dasm_put(Dst, 13919, -BCBIAS_J*4);
2129 break; 2170 break;
2130 2171
2131 /* -- Function headers -------------------------------------------------- */ 2172 /* -- Function headers -------------------------------------------------- */
@@ -2139,7 +2180,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2139 2180
2140 case BC_FUNCF: 2181 case BC_FUNCF:
2141#if LJ_HASJIT 2182#if LJ_HASJIT
2142 dasm_put(Dst, 13628, HOTCOUNT_PCMASK, GG_DISP2HOT); 2183 dasm_put(Dst, 13945, HOTCOUNT_PCMASK, GG_DISP2HOT);
2143#endif 2184#endif
2144 case BC_FUNCV: /* NYI: compiled vararg functions. */ 2185 case BC_FUNCV: /* NYI: compiled vararg functions. */
2145 break; 2186 break;
@@ -2149,13 +2190,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2149 break; 2190 break;
2150#endif 2191#endif
2151 case BC_IFUNCF: 2192 case BC_IFUNCF:
2152 dasm_put(Dst, 13649, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams)); 2193 dasm_put(Dst, 13966, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
2153 if (op == BC_JFUNCF) { 2194 if (op == BC_JFUNCF) {
2154 dasm_put(Dst, 13680, BC_JLOOP); 2195 dasm_put(Dst, 13997, BC_JLOOP);
2155 } else { 2196 } else {
2156 dasm_put(Dst, 9497); 2197 dasm_put(Dst, 9497);
2157 } 2198 }
2158 dasm_put(Dst, 13689, LJ_TNIL); 2199 dasm_put(Dst, 14006, LJ_TNIL);
2159 break; 2200 break;
2160 2201
2161 case BC_JFUNCV: 2202 case BC_JFUNCV:
@@ -2166,30 +2207,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2166 break; /* NYI: compiled vararg functions. */ 2207 break; /* NYI: compiled vararg functions. */
2167 2208
2168 case BC_IFUNCV: 2209 case BC_IFUNCV:
2169 dasm_put(Dst, 13711, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL); 2210 dasm_put(Dst, 14028, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
2170 if (op == BC_JFUNCV) { 2211 if (op == BC_JFUNCV) {
2171 dasm_put(Dst, 13680, BC_JLOOP); 2212 dasm_put(Dst, 13997, BC_JLOOP);
2172 } else { 2213 } else {
2173 dasm_put(Dst, 13808, -4+PC2PROTO(k)); 2214 dasm_put(Dst, 14125, -4+PC2PROTO(k));
2174 } 2215 }
2175 dasm_put(Dst, 13833, LJ_TNIL); 2216 dasm_put(Dst, 14150, LJ_TNIL);
2176 break; 2217 break;
2177 2218
2178 case BC_FUNCC: 2219 case BC_FUNCC:
2179 case BC_FUNCCW: 2220 case BC_FUNCCW:
2180 dasm_put(Dst, 13855, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top)); 2221 dasm_put(Dst, 14172, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
2181 if (op == BC_FUNCC) { 2222 if (op == BC_FUNCC) {
2182 dasm_put(Dst, 13885); 2223 dasm_put(Dst, 14202);
2183 } else { 2224 } else {
2184 dasm_put(Dst, 13889); 2225 dasm_put(Dst, 14206);
2185 } 2226 }
2186 dasm_put(Dst, 13897, DISPATCH_GL(vmstate), ~LJ_VMST_C); 2227 dasm_put(Dst, 14214, DISPATCH_GL(vmstate), ~LJ_VMST_C);
2187 if (op == BC_FUNCC) { 2228 if (op == BC_FUNCC) {
2188 dasm_put(Dst, 13907); 2229 dasm_put(Dst, 14224);
2189 } else { 2230 } else {
2190 dasm_put(Dst, 13912, DISPATCH_GL(wrapf)); 2231 dasm_put(Dst, 14229, DISPATCH_GL(wrapf));
2191 } 2232 }
2192 dasm_put(Dst, 13918, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top)); 2233 dasm_put(Dst, 14235, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
2193 break; 2234 break;
2194 2235
2195 /* ---------------------------------------------------------------------- */ 2236 /* ---------------------------------------------------------------------- */
@@ -2217,7 +2258,7 @@ static int build_backend(BuildCtx *ctx)
2217 2258
2218 build_subroutines(ctx, cmov, sse); 2259 build_subroutines(ctx, cmov, sse);
2219 2260
2220 dasm_put(Dst, 13944); 2261 dasm_put(Dst, 14261);
2221 for (op = 0; op < BC__MAX; op++) 2262 for (op = 0; op < BC__MAX; op++)
2222 build_ins(ctx, (BCOp)op, op, cmov, sse); 2263 build_ins(ctx, (BCOp)op, op, cmov, sse);
2223 2264
diff --git a/src/buildvm_x64win.h b/src/buildvm_x64win.h
index dba00741..bc4da564 100644
--- a/src/buildvm_x64win.h
+++ b/src/buildvm_x64win.h
@@ -12,7 +12,7 @@
12#define DASM_SECTION_CODE_OP 0 12#define DASM_SECTION_CODE_OP 0
13#define DASM_SECTION_CODE_SUB 1 13#define DASM_SECTION_CODE_SUB 1
14#define DASM_MAXSECTION 2 14#define DASM_MAXSECTION 2
15static const unsigned char build_actionlist[13907] = { 15static const unsigned char build_actionlist[14208] = {
16 254,1,248,10,252,247,198,237,15,132,244,11,131,230,252,248,41,252,242,72, 16 254,1,248,10,252,247,198,237,15,132,244,11,131,230,252,248,41,252,242,72,
17 141,76,49,252,248,139,114,252,252,199,68,10,4,237,248,12,131,192,1,137,68, 17 141,76,49,252,248,139,114,252,252,199,68,10,4,237,248,12,131,192,1,137,68,
18 36,84,252,247,198,237,15,132,244,13,248,14,129,252,246,239,252,247,198,237, 18 36,84,252,247,198,237,15,132,244,13,248,14,129,252,246,239,252,247,198,237,
@@ -635,60 +635,75 @@ static const unsigned char build_actionlist[13907] = {
635 141,76,202,8,72,139,105,232,72,139,65,252,240,72,137,41,72,137,65,8,139,105, 635 141,76,202,8,72,139,105,232,72,139,65,252,240,72,137,41,72,137,65,8,139,105,
636 224,139,65,228,137,105,252,248,137,65,252,252,129,252,248,239,184,237,15, 636 224,139,65,228,137,105,252,248,137,65,252,252,129,252,248,239,184,237,15,
637 133,244,28,137,202,137,114,252,252,139,181,233,139,14,15,182,252,233,15,182, 637 133,244,28,137,202,137,114,252,252,139,181,233,139,14,15,182,252,233,15,182,
638 205,131,198,4,252,255,36,252,235,255,15,182,252,236,15,182,192,137,124,36, 638 205,131,198,4,252,255,36,252,235,255,137,124,36,80,137,92,36,84,139,108,202,
639 80,141,188,253,194,233,141,12,202,43,122,252,252,133,252,237,15,132,244,251, 639 252,240,139,68,202,252,248,139,157,233,131,198,4,139,189,233,248,1,57,216,
640 141,108,252,233,252,248,57,215,15,131,244,248,248,1,72,139,71,252,248,131, 640 15,131,244,251,129,124,253,199,4,239,15,132,244,250,255,252,242,15,42,192,
641 199,8,72,137,1,131,193,8,57,252,233,15,131,244,249,57,215,15,130,244,1,248, 641 255,219,68,202,252,248,255,72,139,44,199,72,137,108,202,8,131,192,1,255,137,
642 2,199,65,4,237,131,193,8,57,252,233,15,130,244,2,248,3,139,124,36,80,139, 642 68,202,252,248,248,2,15,183,70,252,254,141,180,253,134,233,248,3,139,92,36,
643 6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,252,235,248,5,199, 643 84,139,124,36,80,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,
644 68,36,84,1,0,0,0,137,208,41,252,248,15,134,244,3,137,197,193,252,237,3,131, 644 36,252,235,248,4,131,192,1,255,137,68,202,252,248,255,252,233,244,1,248,5,
645 197,1,137,108,36,84,139,108,36,96,1,200,59,133,233,15,135,244,253,248,6,255, 645 41,216,248,6,59,133,233,15,135,244,3,105,252,248,239,3,189,233,129,191,233,
646 72,139,71,252,248,131,199,8,72,137,1,131,193,8,57,215,15,130,244,6,252,233, 646 239,15,132,244,253,141,92,24,1,72,139,175,233,72,139,135,233,72,137,44,202,
647 244,3,248,7,137,149,233,137,141,233,137,116,36,100,41,215,139,84,36,84,131, 647 72,137,68,202,8,137,92,202,252,248,252,233,244,2,248,7,131,192,1,252,233,
648 252,234,1,137,252,233,232,251,1,0,139,149,233,139,141,233,1,215,252,233,244, 648 244,6,255,129,124,253,202,252,236,239,15,133,244,251,139,108,202,232,129,
649 6,255,193,225,3,255,248,1,139,114,252,252,137,68,36,84,252,247,198,237,15, 649 124,253,202,252,244,239,15,133,244,251,129,124,253,202,252,252,239,15,133,
650 133,244,253,255,248,13,137,215,131,232,1,15,132,244,249,248,2,72,139,44,15, 650 244,251,128,189,233,235,15,133,244,251,141,180,253,134,233,199,68,202,252,
651 72,137,111,252,248,131,199,8,131,232,1,15,133,244,2,248,3,139,68,36,84,15, 651 248,0,0,0,0,248,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,
652 182,110,252,255,248,5,57,197,15,135,244,252,255,72,139,44,10,72,137,106,252, 652 36,252,235,248,5,198,70,252,252,235,141,180,253,134,233,198,6,235,252,233,
653 248,255,248,5,56,70,252,255,15,135,244,252,255,15,182,78,252,253,72,252,247, 653 244,1,255,15,182,252,236,15,182,192,137,124,36,80,141,188,253,194,233,141,
654 209,141,20,202,139,122,252,248,139,191,233,139,191,233,139,6,15,182,204,15, 654 12,202,43,122,252,252,133,252,237,15,132,244,251,141,108,252,233,252,248,
655 182,232,131,198,4,193,232,16,252,255,36,252,235,248,6,255,199,71,252,252, 655 57,215,15,131,244,248,248,1,72,139,71,252,248,131,199,8,72,137,1,131,193,
656 237,131,199,8,255,199,68,194,252,244,237,255,131,192,1,252,233,244,5,248, 656 8,57,252,233,15,131,244,249,57,215,15,130,244,1,248,2,199,65,4,237,131,193,
657 7,141,174,233,252,247,197,237,15,133,244,14,41,252,234,255,1,252,233,255, 657 8,57,252,233,15,130,244,2,248,3,139,124,36,80,139,6,15,182,204,15,182,232,
658 137,252,245,209,252,237,129,229,239,102,131,172,253,43,233,1,15,132,244,140, 658 131,198,4,193,232,16,252,255,36,252,235,248,5,199,68,36,84,1,0,0,0,137,208,
659 255,141,12,202,255,129,121,253,4,239,15,135,244,53,129,121,253,12,239,15, 659 41,252,248,15,134,244,3,137,197,193,252,237,3,131,197,1,137,108,36,84,139,
660 135,244,53,255,139,105,20,255,129,252,253,239,15,135,244,53,255,252,242,15, 660 108,36,96,1,200,59,133,233,15,135,244,253,248,6,255,72,139,71,252,248,131,
661 16,1,252,242,15,16,73,8,255,252,242,15,88,65,16,252,242,15,17,1,133,252,237, 661 199,8,72,137,1,131,193,8,57,215,15,130,244,6,252,233,244,3,248,7,137,149,
662 15,136,244,249,255,15,140,244,249,255,102,15,46,200,248,1,252,242,15,17,65, 662 233,137,141,233,137,116,36,100,41,215,139,84,36,84,131,252,234,1,137,252,
663 24,255,221,65,8,221,1,255,220,65,16,221,17,221,81,24,133,252,237,15,136,244, 663 233,232,251,1,0,139,149,233,139,141,233,1,215,252,233,244,6,255,193,225,3,
664 247,255,221,81,24,15,140,244,247,255,217,201,248,1,255,15,183,70,252,254, 664 255,248,1,139,114,252,252,137,68,36,84,252,247,198,237,15,133,244,253,255,
665 255,15,131,244,248,141,180,253,134,233,255,141,180,253,134,233,15,183,70, 665 248,13,137,215,131,232,1,15,132,244,249,248,2,72,139,44,15,72,137,111,252,
666 252,254,15,131,245,255,15,130,244,248,141,180,253,134,233,255,248,3,102,15, 666 248,131,199,8,131,232,1,15,133,244,2,248,3,139,68,36,84,15,182,110,252,255,
667 46,193,252,233,244,1,255,141,12,202,139,105,4,129,252,253,239,15,132,244, 667 248,5,57,197,15,135,244,252,255,72,139,44,10,72,137,106,252,248,255,248,5,
668 247,255,137,105,252,252,139,41,137,105,252,248,252,233,245,255,141,180,253, 668 56,70,252,255,15,135,244,252,255,15,182,78,252,253,72,252,247,209,141,20,
669 134,233,139,1,137,105,252,252,137,65,252,248,255,139,139,233,139,4,129,72, 669 202,139,122,252,248,139,191,233,139,191,233,139,6,15,182,204,15,182,232,131,
670 139,128,233,139,108,36,96,137,147,233,137,171,233,76,137,100,36,80,76,137, 670 198,4,193,232,16,252,255,36,252,235,248,6,255,199,71,252,252,237,131,199,
671 108,36,32,76,137,116,36,24,76,137,124,36,16,72,137,225,72,129,252,236,239, 671 8,255,199,68,194,252,244,237,255,131,192,1,252,233,244,5,248,7,141,174,233,
672 102,15,127,49,102,15,127,185,233,102,68,15,127,129,233,102,68,15,127,137, 672 252,247,197,237,15,133,244,14,41,252,234,255,1,252,233,255,137,252,245,209,
673 233,102,68,15,127,145,233,102,68,15,127,153,233,102,68,15,127,161,233,102, 673 252,237,129,229,239,102,131,172,253,43,233,1,15,132,244,140,255,141,12,202,
674 68,15,127,169,233,102,68,15,127,177,233,102,68,15,127,185,233,252,255,224, 674 255,129,121,253,4,239,15,135,244,53,129,121,253,12,239,15,135,244,53,255,
675 255,141,180,253,134,233,139,6,15,182,204,15,182,232,131,198,4,193,232,16, 675 139,105,20,255,129,252,253,239,15,135,244,53,255,252,242,15,16,1,252,242,
676 252,255,36,252,235,255,137,252,245,209,252,237,129,229,239,102,131,172,253, 676 15,16,73,8,255,252,242,15,88,65,16,252,242,15,17,1,133,252,237,15,136,244,
677 43,233,1,15,132,244,142,255,139,190,233,139,108,36,96,141,12,202,59,141,233, 677 249,255,15,140,244,249,255,102,15,46,200,248,1,252,242,15,17,65,24,255,221,
678 15,135,244,23,15,182,142,233,57,200,15,134,244,249,248,2,255,15,183,70,252, 678 65,8,221,1,255,220,65,16,221,17,221,81,24,133,252,237,15,136,244,247,255,
679 254,252,233,245,255,248,3,199,68,194,252,252,237,131,192,1,57,200,15,134, 679 221,81,24,15,140,244,247,255,217,201,248,1,255,15,183,70,252,254,255,15,131,
680 244,3,252,233,244,2,255,141,44,197,237,141,4,194,139,122,252,248,137,104, 680 244,248,141,180,253,134,233,255,141,180,253,134,233,15,183,70,252,254,15,
681 252,252,137,120,252,248,139,108,36,96,141,12,200,59,141,233,15,135,244,22, 681 131,245,255,15,130,244,248,141,180,253,134,233,255,248,3,102,15,46,193,252,
682 137,209,137,194,15,182,174,233,133,252,237,15,132,244,248,248,1,131,193,8, 682 233,244,1,255,141,12,202,139,105,4,129,252,253,239,15,132,244,247,255,137,
683 57,209,15,131,244,249,139,121,252,248,137,56,139,121,252,252,137,120,4,131, 683 105,252,252,139,41,137,105,252,248,252,233,245,255,141,180,253,134,233,139,
684 192,8,199,65,252,252,237,131,252,237,1,15,133,244,1,248,2,255,139,190,233, 684 1,137,105,252,252,137,65,252,248,255,139,139,233,139,4,129,72,139,128,233,
685 139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,252,235,255,248, 685 139,108,36,96,137,147,233,137,171,233,76,137,100,36,80,76,137,108,36,32,76,
686 3,199,64,4,237,131,192,8,131,252,237,1,15,133,244,3,252,233,244,2,255,139, 686 137,116,36,24,76,137,124,36,16,72,137,225,72,129,252,236,239,102,15,127,49,
687 106,252,248,72,139,189,233,139,108,36,96,141,68,194,252,248,137,149,233,141, 687 102,15,127,185,233,102,68,15,127,129,233,102,68,15,127,137,233,102,68,15,
688 136,233,59,141,233,137,133,233,255,137,252,233,255,72,137,252,250,137,252, 688 127,145,233,102,68,15,127,153,233,102,68,15,127,161,233,102,68,15,127,169,
689 233,255,15,135,244,21,199,131,233,237,255,252,255,215,255,252,255,147,233, 689 233,102,68,15,127,177,233,102,68,15,127,185,233,252,255,224,255,141,180,253,
690 255,199,131,233,237,139,149,233,141,12,194,252,247,217,3,141,233,139,114, 690 134,233,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,252,235,
691 252,252,252,233,244,12,255,254,0 691 255,137,252,245,209,252,237,129,229,239,102,131,172,253,43,233,1,15,132,244,
692 142,255,139,190,233,139,108,36,96,141,12,202,59,141,233,15,135,244,23,15,
693 182,142,233,57,200,15,134,244,249,248,2,255,15,183,70,252,254,252,233,245,
694 255,248,3,199,68,194,252,252,237,131,192,1,57,200,15,134,244,3,252,233,244,
695 2,255,141,44,197,237,141,4,194,139,122,252,248,137,104,252,252,137,120,252,
696 248,139,108,36,96,141,12,200,59,141,233,15,135,244,22,137,209,137,194,15,
697 182,174,233,133,252,237,15,132,244,248,248,1,131,193,8,57,209,15,131,244,
698 249,139,121,252,248,137,56,139,121,252,252,137,120,4,131,192,8,199,65,252,
699 252,237,131,252,237,1,15,133,244,1,248,2,255,139,190,233,139,6,15,182,204,
700 15,182,232,131,198,4,193,232,16,252,255,36,252,235,255,248,3,199,64,4,237,
701 131,192,8,131,252,237,1,15,133,244,3,252,233,244,2,255,139,106,252,248,72,
702 139,189,233,139,108,36,96,141,68,194,252,248,137,149,233,141,136,233,59,141,
703 233,137,133,233,255,137,252,233,255,72,137,252,250,137,252,233,255,15,135,
704 244,21,199,131,233,237,255,252,255,215,255,252,255,147,233,255,199,131,233,
705 237,139,149,233,141,12,194,252,247,217,3,141,233,139,114,252,252,252,233,
706 244,12,255,254,0
692}; 707};
693 708
694enum { 709enum {
@@ -1984,9 +1999,35 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
1984 dasm_put(Dst, 12750, LJ_TFUNC, 2+1, Dt7(->pc)); 1999 dasm_put(Dst, 12750, LJ_TFUNC, 2+1, Dt7(->pc));
1985 break; 2000 break;
1986 2001
2002 case BC_ITERN:
2003#if LJ_HASJIT
2004#endif
2005 dasm_put(Dst, 12821, Dt6(->asize), Dt6(->array), LJ_TNIL);
2006 if (sse) {
2007 dasm_put(Dst, 12867);
2008 } else {
2009 dasm_put(Dst, 12873);
2010 }
2011 dasm_put(Dst, 12879);
2012 if (sse) {
2013 dasm_put(Dst, 9920);
2014 } else {
2015 dasm_put(Dst, 9932);
2016 }
2017 dasm_put(Dst, 12892, -BCBIAS_J*4);
2018 if (!sse) {
2019 dasm_put(Dst, 12944);
2020 }
2021 dasm_put(Dst, 12950, Dt6(->hmask), sizeof(Node), Dt6(->node), DtB(->val.it), LJ_TNIL, DtB(->key), DtB(->val));
2022 break;
2023
2024 case BC_ISNEXT:
2025 dasm_put(Dst, 13022, LJ_TFUNC, LJ_TTAB, LJ_TNIL, Dt8(->ffid), FF_next_N, -BCBIAS_J*4, BC_JMP, -BCBIAS_J*4, BC_ITERC);
2026 break;
2027
1987 case BC_VARG: 2028 case BC_VARG:
1988 dasm_put(Dst, 12821, (8+FRAME_VARG), LJ_TNIL, Dt1(->maxstack)); 2029 dasm_put(Dst, 13122, (8+FRAME_VARG), LJ_TNIL, Dt1(->maxstack));
1989 dasm_put(Dst, 12981, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top)); 2030 dasm_put(Dst, 13282, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top));
1990 break; 2031 break;
1991 2032
1992 /* -- Returns ----------------------------------------------------------- */ 2033 /* -- Returns ----------------------------------------------------------- */
@@ -1997,30 +2038,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
1997 2038
1998 case BC_RET: case BC_RET0: case BC_RET1: 2039 case BC_RET: case BC_RET0: case BC_RET1:
1999 if (op != BC_RET0) { 2040 if (op != BC_RET0) {
2000 dasm_put(Dst, 13047); 2041 dasm_put(Dst, 13348);
2001 } 2042 }
2002 dasm_put(Dst, 13051, FRAME_TYPE); 2043 dasm_put(Dst, 13352, FRAME_TYPE);
2003 switch (op) { 2044 switch (op) {
2004 case BC_RET: 2045 case BC_RET:
2005 dasm_put(Dst, 13070); 2046 dasm_put(Dst, 13371);
2006 break; 2047 break;
2007 case BC_RET1: 2048 case BC_RET1:
2008 dasm_put(Dst, 13122); 2049 dasm_put(Dst, 13423);
2009 /* fallthrough */ 2050 /* fallthrough */
2010 case BC_RET0: 2051 case BC_RET0:
2011 dasm_put(Dst, 13132); 2052 dasm_put(Dst, 13433);
2012 default: 2053 default:
2013 break; 2054 break;
2014 } 2055 }
2015 dasm_put(Dst, 13143, Dt7(->pc), PC2PROTO(k)); 2056 dasm_put(Dst, 13444, Dt7(->pc), PC2PROTO(k));
2016 if (op == BC_RET) { 2057 if (op == BC_RET) {
2017 dasm_put(Dst, 13187, LJ_TNIL); 2058 dasm_put(Dst, 13488, LJ_TNIL);
2018 } else { 2059 } else {
2019 dasm_put(Dst, 13196, LJ_TNIL); 2060 dasm_put(Dst, 13497, LJ_TNIL);
2020 } 2061 }
2021 dasm_put(Dst, 13203, -FRAME_VARG, FRAME_TYPEP); 2062 dasm_put(Dst, 13504, -FRAME_VARG, FRAME_TYPEP);
2022 if (op != BC_RET0) { 2063 if (op != BC_RET0) {
2023 dasm_put(Dst, 13227); 2064 dasm_put(Dst, 13528);
2024 } 2065 }
2025 dasm_put(Dst, 4507); 2066 dasm_put(Dst, 4507);
2026 break; 2067 break;
@@ -2030,7 +2071,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2030 2071
2031 case BC_FORL: 2072 case BC_FORL:
2032#if LJ_HASJIT 2073#if LJ_HASJIT
2033 dasm_put(Dst, 13231, HOTCOUNT_PCMASK, GG_DISP2HOT); 2074 dasm_put(Dst, 13532, HOTCOUNT_PCMASK, GG_DISP2HOT);
2034#endif 2075#endif
2035 break; 2076 break;
2036 2077
@@ -2042,57 +2083,57 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2042 case BC_FORI: 2083 case BC_FORI:
2043 case BC_IFORL: 2084 case BC_IFORL:
2044 vk = (op == BC_IFORL || op == BC_JFORL); 2085 vk = (op == BC_IFORL || op == BC_JFORL);
2045 dasm_put(Dst, 13252); 2086 dasm_put(Dst, 13553);
2046 if (!vk) { 2087 if (!vk) {
2047 dasm_put(Dst, 13256, LJ_TISNUM, LJ_TISNUM); 2088 dasm_put(Dst, 13557, LJ_TISNUM, LJ_TISNUM);
2048 } 2089 }
2049 dasm_put(Dst, 13275); 2090 dasm_put(Dst, 13576);
2050 if (!vk) { 2091 if (!vk) {
2051 dasm_put(Dst, 13279, LJ_TISNUM); 2092 dasm_put(Dst, 13580, LJ_TISNUM);
2052 } 2093 }
2053 if (sse) { 2094 if (sse) {
2054 dasm_put(Dst, 13288); 2095 dasm_put(Dst, 13589);
2055 if (vk) { 2096 if (vk) {
2056 dasm_put(Dst, 13300); 2097 dasm_put(Dst, 13601);
2057 } else { 2098 } else {
2058 dasm_put(Dst, 13319); 2099 dasm_put(Dst, 13620);
2059 } 2100 }
2060 dasm_put(Dst, 13324); 2101 dasm_put(Dst, 13625);
2061 } else { 2102 } else {
2062 dasm_put(Dst, 13337); 2103 dasm_put(Dst, 13638);
2063 if (vk) { 2104 if (vk) {
2064 dasm_put(Dst, 13343); 2105 dasm_put(Dst, 13644);
2065 } else { 2106 } else {
2066 dasm_put(Dst, 13359); 2107 dasm_put(Dst, 13660);
2067 } 2108 }
2068 dasm_put(Dst, 13367); 2109 dasm_put(Dst, 13668);
2069 if (cmov) { 2110 if (cmov) {
2070 dasm_put(Dst, 9470); 2111 dasm_put(Dst, 9470);
2071 } else { 2112 } else {
2072 dasm_put(Dst, 9476); 2113 dasm_put(Dst, 9476);
2073 } 2114 }
2074 if (!cmov) { 2115 if (!cmov) {
2075 dasm_put(Dst, 13372); 2116 dasm_put(Dst, 13673);
2076 } 2117 }
2077 } 2118 }
2078 if (op == BC_FORI) { 2119 if (op == BC_FORI) {
2079 dasm_put(Dst, 13378, -BCBIAS_J*4); 2120 dasm_put(Dst, 13679, -BCBIAS_J*4);
2080 } else if (op == BC_JFORI) { 2121 } else if (op == BC_JFORI) {
2081 dasm_put(Dst, 13388, -BCBIAS_J*4, BC_JLOOP); 2122 dasm_put(Dst, 13689, -BCBIAS_J*4, BC_JLOOP);
2082 } else if (op == BC_IFORL) { 2123 } else if (op == BC_IFORL) {
2083 dasm_put(Dst, 13402, -BCBIAS_J*4); 2124 dasm_put(Dst, 13703, -BCBIAS_J*4);
2084 } else { 2125 } else {
2085 dasm_put(Dst, 13398, BC_JLOOP); 2126 dasm_put(Dst, 13699, BC_JLOOP);
2086 } 2127 }
2087 dasm_put(Dst, 9505); 2128 dasm_put(Dst, 9505);
2088 if (sse) { 2129 if (sse) {
2089 dasm_put(Dst, 13412); 2130 dasm_put(Dst, 13713);
2090 } 2131 }
2091 break; 2132 break;
2092 2133
2093 case BC_ITERL: 2134 case BC_ITERL:
2094#if LJ_HASJIT 2135#if LJ_HASJIT
2095 dasm_put(Dst, 13231, HOTCOUNT_PCMASK, GG_DISP2HOT); 2136 dasm_put(Dst, 13532, HOTCOUNT_PCMASK, GG_DISP2HOT);
2096#endif 2137#endif
2097 break; 2138 break;
2098 2139
@@ -2101,18 +2142,18 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2101 break; 2142 break;
2102#endif 2143#endif
2103 case BC_IITERL: 2144 case BC_IITERL:
2104 dasm_put(Dst, 13423, LJ_TNIL); 2145 dasm_put(Dst, 13724, LJ_TNIL);
2105 if (op == BC_JITERL) { 2146 if (op == BC_JITERL) {
2106 dasm_put(Dst, 13438, BC_JLOOP); 2147 dasm_put(Dst, 13739, BC_JLOOP);
2107 } else { 2148 } else {
2108 dasm_put(Dst, 13452, -BCBIAS_J*4); 2149 dasm_put(Dst, 13753, -BCBIAS_J*4);
2109 } 2150 }
2110 dasm_put(Dst, 9805); 2151 dasm_put(Dst, 9805);
2111 break; 2152 break;
2112 2153
2113 case BC_LOOP: 2154 case BC_LOOP:
2114#if LJ_HASJIT 2155#if LJ_HASJIT
2115 dasm_put(Dst, 13231, HOTCOUNT_PCMASK, GG_DISP2HOT); 2156 dasm_put(Dst, 13532, HOTCOUNT_PCMASK, GG_DISP2HOT);
2116#endif 2157#endif
2117 break; 2158 break;
2118 2159
@@ -2122,12 +2163,12 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2122 2163
2123 case BC_JLOOP: 2164 case BC_JLOOP:
2124#if LJ_HASJIT 2165#if LJ_HASJIT
2125 dasm_put(Dst, 13468, DISPATCH_J(trace), DtD(->mcode), DISPATCH_GL(jit_base), DISPATCH_GL(jit_L), 9*16+4*8, -1*16, -2*16, -3*16, -4*16, -5*16, -6*16, -7*16, -8*16, -9*16); 2166 dasm_put(Dst, 13769, DISPATCH_J(trace), DtD(->mcode), DISPATCH_GL(jit_base), DISPATCH_GL(jit_L), 9*16+4*8, -1*16, -2*16, -3*16, -4*16, -5*16, -6*16, -7*16, -8*16, -9*16);
2126#endif 2167#endif
2127 break; 2168 break;
2128 2169
2129 case BC_JMP: 2170 case BC_JMP:
2130 dasm_put(Dst, 13577, -BCBIAS_J*4); 2171 dasm_put(Dst, 13878, -BCBIAS_J*4);
2131 break; 2172 break;
2132 2173
2133 /* -- Function headers -------------------------------------------------- */ 2174 /* -- Function headers -------------------------------------------------- */
@@ -2141,7 +2182,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2141 2182
2142 case BC_FUNCF: 2183 case BC_FUNCF:
2143#if LJ_HASJIT 2184#if LJ_HASJIT
2144 dasm_put(Dst, 13602, HOTCOUNT_PCMASK, GG_DISP2HOT); 2185 dasm_put(Dst, 13903, HOTCOUNT_PCMASK, GG_DISP2HOT);
2145#endif 2186#endif
2146 case BC_FUNCV: /* NYI: compiled vararg functions. */ 2187 case BC_FUNCV: /* NYI: compiled vararg functions. */
2147 break; 2188 break;
@@ -2151,13 +2192,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2151 break; 2192 break;
2152#endif 2193#endif
2153 case BC_IFUNCF: 2194 case BC_IFUNCF:
2154 dasm_put(Dst, 13623, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams)); 2195 dasm_put(Dst, 13924, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
2155 if (op == BC_JFUNCF) { 2196 if (op == BC_JFUNCF) {
2156 dasm_put(Dst, 13653, BC_JLOOP); 2197 dasm_put(Dst, 13954, BC_JLOOP);
2157 } else { 2198 } else {
2158 dasm_put(Dst, 9507); 2199 dasm_put(Dst, 9507);
2159 } 2200 }
2160 dasm_put(Dst, 13662, LJ_TNIL); 2201 dasm_put(Dst, 13963, LJ_TNIL);
2161 break; 2202 break;
2162 2203
2163 case BC_JFUNCV: 2204 case BC_JFUNCV:
@@ -2168,30 +2209,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2168 break; /* NYI: compiled vararg functions. */ 2209 break; /* NYI: compiled vararg functions. */
2169 2210
2170 case BC_IFUNCV: 2211 case BC_IFUNCV:
2171 dasm_put(Dst, 13684, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL); 2212 dasm_put(Dst, 13985, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
2172 if (op == BC_JFUNCV) { 2213 if (op == BC_JFUNCV) {
2173 dasm_put(Dst, 13653, BC_JLOOP); 2214 dasm_put(Dst, 13954, BC_JLOOP);
2174 } else { 2215 } else {
2175 dasm_put(Dst, 13775, -4+PC2PROTO(k)); 2216 dasm_put(Dst, 14076, -4+PC2PROTO(k));
2176 } 2217 }
2177 dasm_put(Dst, 13798, LJ_TNIL); 2218 dasm_put(Dst, 14099, LJ_TNIL);
2178 break; 2219 break;
2179 2220
2180 case BC_FUNCC: 2221 case BC_FUNCC:
2181 case BC_FUNCCW: 2222 case BC_FUNCCW:
2182 dasm_put(Dst, 13820, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top)); 2223 dasm_put(Dst, 14121, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
2183 if (op == BC_FUNCC) { 2224 if (op == BC_FUNCC) {
2184 dasm_put(Dst, 13850); 2225 dasm_put(Dst, 14151);
2185 } else { 2226 } else {
2186 dasm_put(Dst, 13854); 2227 dasm_put(Dst, 14155);
2187 } 2228 }
2188 dasm_put(Dst, 13862, DISPATCH_GL(vmstate), ~LJ_VMST_C); 2229 dasm_put(Dst, 14163, DISPATCH_GL(vmstate), ~LJ_VMST_C);
2189 if (op == BC_FUNCC) { 2230 if (op == BC_FUNCC) {
2190 dasm_put(Dst, 13871); 2231 dasm_put(Dst, 14172);
2191 } else { 2232 } else {
2192 dasm_put(Dst, 13875, DISPATCH_GL(wrapf)); 2233 dasm_put(Dst, 14176, DISPATCH_GL(wrapf));
2193 } 2234 }
2194 dasm_put(Dst, 13880, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top)); 2235 dasm_put(Dst, 14181, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
2195 break; 2236 break;
2196 2237
2197 /* ---------------------------------------------------------------------- */ 2238 /* ---------------------------------------------------------------------- */
@@ -2219,7 +2260,7 @@ static int build_backend(BuildCtx *ctx)
2219 2260
2220 build_subroutines(ctx, cmov, sse); 2261 build_subroutines(ctx, cmov, sse);
2221 2262
2222 dasm_put(Dst, 13905); 2263 dasm_put(Dst, 14206);
2223 for (op = 0; op < BC__MAX; op++) 2264 for (op = 0; op < BC__MAX; op++)
2224 build_ins(ctx, (BCOp)op, op, cmov, sse); 2265 build_ins(ctx, (BCOp)op, op, cmov, sse);
2225 2266
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc
index 6ac2646c..e9ecc2c2 100644
--- a/src/buildvm_x86.dasc
+++ b/src/buildvm_x86.dasc
@@ -4576,6 +4576,109 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
4576 | ins_call 4576 | ins_call
4577 break; 4577 break;
4578 4578
4579 case BC_ITERN:
4580 | ins_A // RA = base, (RB = nresults+1 (2+1), RC = nargs+1 (2+1))
4581#if LJ_HASJIT
4582 | // NYI: add hotloop, record BC_ITERN.
4583#endif
4584 | mov TMP1, KBASE // Need two more free registers.
4585 | mov TMP2, DISPATCH
4586 | mov TAB:RB, [BASE+RA*8-16]
4587 | mov RC, [BASE+RA*8-8] // Get index from control var.
4588 | mov DISPATCH, TAB:RB->asize
4589 | add PC, 4
4590 | mov KBASE, TAB:RB->array
4591 |1: // Traverse array part.
4592 | cmp RC, DISPATCH; jae >5 // Index points after array part?
4593 | cmp dword [KBASE+RC*8+4], LJ_TNIL; je >4
4594 if (sse) {
4595 | cvtsi2sd xmm0, RC
4596 } else {
4597 | fild dword [BASE+RA*8-8]
4598 }
4599 | // Copy array slot to returned value.
4600 |.if X64
4601 | mov RBa, [KBASE+RC*8]
4602 | mov [BASE+RA*8+8], RBa
4603 |.else
4604 | mov RB, [KBASE+RC*8+4]
4605 | mov [BASE+RA*8+12], RB
4606 | mov RB, [KBASE+RC*8]
4607 | mov [BASE+RA*8+8], RB
4608 |.endif
4609 | add RC, 1
4610 | // Return array index as a numeric key.
4611 if (sse) {
4612 | movsd qword [BASE+RA*8], xmm0
4613 } else {
4614 | fstp qword [BASE+RA*8]
4615 }
4616 | mov [BASE+RA*8-8], RC // Update control var.
4617 |2:
4618 | movzx RD, PC_RD // Get target from ITERL.
4619 | branchPC RD
4620 |3:
4621 | mov DISPATCH, TMP2
4622 | mov KBASE, TMP1
4623 | ins_next
4624 |
4625 |4: // Skip holes in array part.
4626 | add RC, 1
4627 if (!sse) {
4628 | mov [BASE+RA*8-8], RC
4629 }
4630 | jmp <1
4631 |
4632 |5: // Traverse hash part.
4633 | sub RC, DISPATCH
4634 |6:
4635 | cmp RC, TAB:RB->hmask; ja <3 // End of iteration? Branch to ITERL+1.
4636 | imul KBASE, RC, #NODE
4637 | add NODE:KBASE, TAB:RB->node
4638 | cmp dword NODE:KBASE->val.it, LJ_TNIL; je >7
4639 | lea DISPATCH, [RC+DISPATCH+1]
4640 | // Copy key and value from hash slot.
4641 |.if X64
4642 | mov RBa, NODE:KBASE->key
4643 | mov RCa, NODE:KBASE->val
4644 | mov [BASE+RA*8], RBa
4645 | mov [BASE+RA*8+8], RCa
4646 |.else
4647 | mov RB, NODE:KBASE->key.gcr
4648 | mov RC, NODE:KBASE->key.it
4649 | mov [BASE+RA*8], RB
4650 | mov [BASE+RA*8+4], RC
4651 | mov RB, NODE:KBASE->val.gcr
4652 | mov RC, NODE:KBASE->val.it
4653 | mov [BASE+RA*8+8], RB
4654 | mov [BASE+RA*8+12], RC
4655 |.endif
4656 | mov [BASE+RA*8-8], DISPATCH
4657 | jmp <2
4658 |
4659 |7: // Skip holes in hash part.
4660 | add RC, 1
4661 | jmp <6
4662 break;
4663
4664 case BC_ISNEXT:
4665 | ins_AD // RA = base, RD = target (points to ITERN)
4666 | cmp dword [BASE+RA*8-20], LJ_TFUNC; jne >5
4667 | mov CFUNC:RB, [BASE+RA*8-24]
4668 | cmp dword [BASE+RA*8-12], LJ_TTAB; jne >5
4669 | cmp dword [BASE+RA*8-4], LJ_TNIL; jne >5
4670 | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5
4671 | branchPC RD
4672 | mov dword [BASE+RA*8-8], 0 // Initialize control var.
4673 |1:
4674 | ins_next
4675 |5: // Despecialize bytecode if any of the checks fail.
4676 | mov PC_OP, BC_JMP
4677 | branchPC RD
4678 | mov byte [PC], BC_ITERC
4679 | jmp <1
4680 break;
4681
4579 case BC_VARG: 4682 case BC_VARG:
4580 | ins_ABC // RA = base, RB = nresults+1, RC = numparams 4683 | ins_ABC // RA = base, RB = nresults+1, RC = numparams
4581 | mov TMP1, KBASE // Need one more free register. 4684 | mov TMP1, KBASE // Need one more free register.
diff --git a/src/buildvm_x86.h b/src/buildvm_x86.h
index 6b8f4af4..8d30b4ef 100644
--- a/src/buildvm_x86.h
+++ b/src/buildvm_x86.h
@@ -12,7 +12,7 @@
12#define DASM_SECTION_CODE_OP 0 12#define DASM_SECTION_CODE_OP 0
13#define DASM_SECTION_CODE_SUB 1 13#define DASM_SECTION_CODE_SUB 1
14#define DASM_MAXSECTION 2 14#define DASM_MAXSECTION 2
15static const unsigned char build_actionlist[15260] = { 15static const unsigned char build_actionlist[15576] = {
16 254,1,248,10,252,247,198,237,15,132,244,11,131,230,252,248,41,252,242,141, 16 254,1,248,10,252,247,198,237,15,132,244,11,131,230,252,248,41,252,242,141,
17 76,49,252,248,139,114,252,252,199,68,10,4,237,248,12,131,192,1,137,68,36, 17 76,49,252,248,139,114,252,252,199,68,10,4,237,248,12,131,192,1,137,68,36,
18 20,252,247,198,237,15,132,244,13,248,14,129,252,246,239,252,247,198,237,15, 18 20,252,247,198,237,15,132,244,13,248,14,129,252,246,239,252,247,198,237,15,
@@ -699,56 +699,72 @@ static const unsigned char build_actionlist[15260] = {
699 139,65,252,236,137,41,137,65,4,139,105,252,240,139,65,252,244,137,105,8,137, 699 139,65,252,236,137,41,137,65,4,139,105,252,240,139,65,252,244,137,105,8,137,
700 65,12,139,105,224,139,65,228,137,105,252,248,137,65,252,252,129,252,248,239, 700 65,12,139,105,224,139,65,228,137,105,252,248,137,65,252,252,129,252,248,239,
701 184,237,15,133,244,28,137,202,137,114,252,252,139,181,233,139,14,15,182,252, 701 184,237,15,133,244,28,137,202,137,114,252,252,139,181,233,139,14,15,182,252,
702 233,15,182,205,131,198,4,252,255,36,171,255,15,182,252,236,15,182,192,137, 702 233,15,182,205,131,198,4,252,255,36,171,255,137,124,36,16,137,92,36,20,139,
703 124,36,16,141,188,253,194,233,141,12,202,43,122,252,252,133,252,237,15,132, 703 108,202,252,240,139,68,202,252,248,139,157,233,131,198,4,139,189,233,248,
704 244,251,141,108,252,233,252,248,57,215,15,131,244,248,248,1,139,71,252,248, 704 1,57,216,15,131,244,251,129,124,253,199,4,239,15,132,244,250,255,252,242,
705 137,1,139,71,252,252,131,199,8,137,65,4,131,193,8,57,252,233,15,131,244,249, 705 15,42,192,255,219,68,202,252,248,255,139,108,199,4,137,108,202,12,139,44,
706 57,215,15,130,244,1,248,2,199,65,4,237,131,193,8,57,252,233,15,130,244,2, 706 199,137,108,202,8,131,192,1,255,137,68,202,252,248,248,2,15,183,70,252,254,
707 248,3,139,124,36,16,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252, 707 141,180,253,134,233,248,3,139,92,36,20,139,124,36,16,139,6,15,182,204,15,
708 255,36,171,248,5,199,68,36,20,1,0,0,0,137,208,41,252,248,15,134,244,3,137, 708 182,232,131,198,4,193,232,16,252,255,36,171,248,4,131,192,1,255,137,68,202,
709 197,193,252,237,3,131,197,1,137,108,36,20,139,108,36,48,1,200,59,133,233, 709 252,248,255,252,233,244,1,248,5,41,216,248,6,59,133,233,15,135,244,3,105,
710 15,135,244,253,248,6,255,139,71,252,248,137,1,139,71,252,252,131,199,8,137, 710 252,248,239,3,189,233,129,191,233,239,15,132,244,253,141,92,24,1,139,175,
711 65,4,131,193,8,57,215,15,130,244,6,252,233,244,3,248,7,137,149,233,137,141, 711 233,139,135,233,137,44,202,137,68,202,4,139,175,233,139,135,233,137,108,202,
712 233,137,116,36,24,41,215,139,84,36,20,131,252,234,1,137,252,233,232,251,1, 712 8,137,68,202,12,137,92,202,252,248,252,233,244,2,248,7,255,131,192,1,252,
713 0,139,149,233,139,141,233,1,215,252,233,244,6,255,193,225,3,255,248,1,139, 713 233,244,6,255,129,124,253,202,252,236,239,15,133,244,251,139,108,202,232,
714 114,252,252,137,68,36,20,252,247,198,237,15,133,244,253,255,248,13,137,215, 714 129,124,253,202,252,244,239,15,133,244,251,129,124,253,202,252,252,239,15,
715 131,232,1,15,132,244,249,248,2,139,44,15,137,111,252,248,139,108,15,4,137, 715 133,244,251,128,189,233,235,15,133,244,251,141,180,253,134,233,199,68,202,
716 111,252,252,131,199,8,131,232,1,15,133,244,2,248,3,139,68,36,20,15,182,110, 716 252,248,0,0,0,0,248,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,
717 252,255,248,5,57,197,15,135,244,252,255,139,108,10,4,137,106,252,252,139, 717 255,36,171,248,5,198,70,252,252,235,141,180,253,134,233,198,6,235,252,233,
718 44,10,137,106,252,248,255,248,5,56,70,252,255,15,135,244,252,255,15,182,78, 718 244,1,255,15,182,252,236,15,182,192,137,124,36,16,141,188,253,194,233,141,
719 252,253,252,247,209,141,20,202,139,122,252,248,139,191,233,139,191,233,139, 719 12,202,43,122,252,252,133,252,237,15,132,244,251,141,108,252,233,252,248,
720 6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,6,255,199, 720 57,215,15,131,244,248,248,1,139,71,252,248,137,1,139,71,252,252,131,199,8,
721 71,252,252,237,131,199,8,255,199,68,194,252,244,237,255,131,192,1,252,233, 721 137,65,4,131,193,8,57,252,233,15,131,244,249,57,215,15,130,244,1,248,2,199,
722 244,5,248,7,141,174,233,252,247,197,237,15,133,244,14,41,252,234,255,1,252, 722 65,4,237,131,193,8,57,252,233,15,130,244,2,248,3,139,124,36,16,139,6,15,182,
723 233,255,137,252,245,209,252,237,129,229,239,102,131,172,253,43,233,1,15,132, 723 204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,5,199,68,36,20,1,0,
724 244,140,255,141,12,202,255,129,121,253,4,239,15,135,244,53,129,121,253,12, 724 0,0,137,208,41,252,248,15,134,244,3,137,197,193,252,237,3,131,197,1,137,108,
725 239,15,135,244,53,255,139,105,20,255,129,252,253,239,15,135,244,53,255,252, 725 36,20,139,108,36,48,1,200,59,133,233,15,135,244,253,248,6,255,139,71,252,
726 242,15,16,1,252,242,15,16,73,8,255,252,242,15,88,65,16,252,242,15,17,1,133, 726 248,137,1,139,71,252,252,131,199,8,137,65,4,131,193,8,57,215,15,130,244,6,
727 252,237,15,136,244,249,255,15,140,244,249,255,102,15,46,200,248,1,252,242, 727 252,233,244,3,248,7,137,149,233,137,141,233,137,116,36,24,41,215,139,84,36,
728 15,17,65,24,255,221,65,8,221,1,255,220,65,16,221,17,221,81,24,133,252,237, 728 20,131,252,234,1,137,252,233,232,251,1,0,139,149,233,139,141,233,1,215,252,
729 15,136,244,247,255,221,81,24,15,140,244,247,255,217,201,248,1,255,15,183, 729 233,244,6,255,193,225,3,255,248,1,139,114,252,252,137,68,36,20,252,247,198,
730 70,252,254,255,15,131,244,248,141,180,253,134,233,255,141,180,253,134,233, 730 237,15,133,244,253,255,248,13,137,215,131,232,1,15,132,244,249,248,2,139,
731 15,183,70,252,254,15,131,245,255,15,130,244,248,141,180,253,134,233,255,248, 731 44,15,137,111,252,248,139,108,15,4,137,111,252,252,131,199,8,131,232,1,15,
732 3,102,15,46,193,252,233,244,1,255,141,12,202,139,105,4,129,252,253,239,15, 732 133,244,2,248,3,139,68,36,20,15,182,110,252,255,248,5,57,197,15,135,244,252,
733 132,244,247,255,137,105,252,252,139,41,137,105,252,248,252,233,245,255,141, 733 255,139,108,10,4,137,106,252,252,139,44,10,137,106,252,248,255,248,5,56,70,
734 180,253,134,233,139,1,137,105,252,252,137,65,252,248,255,139,139,233,139, 734 252,255,15,135,244,252,255,15,182,78,252,253,252,247,209,141,20,202,139,122,
735 4,129,139,128,233,139,108,36,48,137,147,233,137,171,233,252,255,224,255,141, 735 252,248,139,191,233,139,191,233,139,6,15,182,204,15,182,232,131,198,4,193,
736 180,253,134,233,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255, 736 232,16,252,255,36,171,248,6,255,199,71,252,252,237,131,199,8,255,199,68,194,
737 36,171,255,137,252,245,209,252,237,129,229,239,102,131,172,253,43,233,1,15, 737 252,244,237,255,131,192,1,252,233,244,5,248,7,141,174,233,252,247,197,237,
738 132,244,142,255,139,190,233,139,108,36,48,141,12,202,59,141,233,15,135,244, 738 15,133,244,14,41,252,234,255,1,252,233,255,137,252,245,209,252,237,129,229,
739 23,15,182,142,233,57,200,15,134,244,249,248,2,255,15,183,70,252,254,252,233, 739 239,102,131,172,253,43,233,1,15,132,244,140,255,141,12,202,255,129,121,253,
740 245,255,248,3,199,68,194,252,252,237,131,192,1,57,200,15,134,244,3,252,233, 740 4,239,15,135,244,53,129,121,253,12,239,15,135,244,53,255,139,105,20,255,129,
741 244,2,255,141,44,197,237,141,4,194,139,122,252,248,137,104,252,252,137,120, 741 252,253,239,15,135,244,53,255,252,242,15,16,1,252,242,15,16,73,8,255,252,
742 252,248,139,108,36,48,141,12,200,59,141,233,15,135,244,22,137,209,137,194, 742 242,15,88,65,16,252,242,15,17,1,133,252,237,15,136,244,249,255,15,140,244,
743 15,182,174,233,133,252,237,15,132,244,248,248,1,131,193,8,57,209,15,131,244, 743 249,255,102,15,46,200,248,1,252,242,15,17,65,24,255,221,65,8,221,1,255,220,
744 249,139,121,252,248,137,56,139,121,252,252,137,120,4,131,192,8,199,65,252, 744 65,16,221,17,221,81,24,133,252,237,15,136,244,247,255,221,81,24,15,140,244,
745 252,237,131,252,237,1,15,133,244,1,248,2,255,139,190,233,139,6,15,182,204, 745 247,255,217,201,248,1,255,15,183,70,252,254,255,15,131,244,248,141,180,253,
746 15,182,232,131,198,4,193,232,16,252,255,36,171,255,248,3,199,64,4,237,131, 746 134,233,255,141,180,253,134,233,15,183,70,252,254,15,131,245,255,15,130,244,
747 192,8,131,252,237,1,15,133,244,3,252,233,244,2,255,139,106,252,248,139,189, 747 248,141,180,253,134,233,255,248,3,102,15,46,193,252,233,244,1,255,141,12,
748 233,139,108,36,48,141,68,194,252,248,137,149,233,141,136,233,59,141,233,137, 748 202,139,105,4,129,252,253,239,15,132,244,247,255,137,105,252,252,139,41,137,
749 133,233,255,137,44,36,255,137,124,36,4,137,44,36,255,15,135,244,21,199,131, 749 105,252,248,252,233,245,255,141,180,253,134,233,139,1,137,105,252,252,137,
750 233,237,255,252,255,215,255,252,255,147,233,255,199,131,233,237,139,149,233, 750 65,252,248,255,139,139,233,139,4,129,139,128,233,139,108,36,48,137,147,233,
751 141,12,194,252,247,217,3,141,233,139,114,252,252,252,233,244,12,255,254,0 751 137,171,233,252,255,224,255,141,180,253,134,233,139,6,15,182,204,15,182,232,
752 131,198,4,193,232,16,252,255,36,171,255,137,252,245,209,252,237,129,229,239,
753 102,131,172,253,43,233,1,15,132,244,142,255,139,190,233,139,108,36,48,141,
754 12,202,59,141,233,15,135,244,23,15,182,142,233,57,200,15,134,244,249,248,
755 2,255,15,183,70,252,254,252,233,245,255,248,3,199,68,194,252,252,237,131,
756 192,1,57,200,15,134,244,3,252,233,244,2,255,141,44,197,237,141,4,194,139,
757 122,252,248,137,104,252,252,137,120,252,248,139,108,36,48,141,12,200,59,141,
758 233,15,135,244,22,137,209,137,194,15,182,174,233,133,252,237,15,132,244,248,
759 248,1,131,193,8,57,209,15,131,244,249,139,121,252,248,137,56,139,121,252,
760 252,137,120,4,131,192,8,199,65,252,252,237,131,252,237,1,15,133,244,1,248,
761 2,255,139,190,233,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,
762 36,171,255,248,3,199,64,4,237,131,192,8,131,252,237,1,15,133,244,3,252,233,
763 244,2,255,139,106,252,248,139,189,233,139,108,36,48,141,68,194,252,248,137,
764 149,233,141,136,233,59,141,233,137,133,233,255,137,44,36,255,137,124,36,4,
765 137,44,36,255,15,135,244,21,199,131,233,237,255,252,255,215,255,252,255,147,
766 233,255,199,131,233,237,139,149,233,141,12,194,252,247,217,3,141,233,139,
767 114,252,252,252,233,244,12,255,254,0
752}; 768};
753 769
754enum { 770enum {
@@ -2115,9 +2131,36 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2115 dasm_put(Dst, 14164, LJ_TFUNC, 2+1, Dt7(->pc)); 2131 dasm_put(Dst, 14164, LJ_TFUNC, 2+1, Dt7(->pc));
2116 break; 2132 break;
2117 2133
2134 case BC_ITERN:
2135#if LJ_HASJIT
2136#endif
2137 dasm_put(Dst, 14244, Dt6(->asize), Dt6(->array), LJ_TNIL);
2138 if (sse) {
2139 dasm_put(Dst, 14290);
2140 } else {
2141 dasm_put(Dst, 14296);
2142 }
2143 dasm_put(Dst, 14302);
2144 if (sse) {
2145 dasm_put(Dst, 11273);
2146 } else {
2147 dasm_put(Dst, 11285);
2148 }
2149 dasm_put(Dst, 14321, -BCBIAS_J*4);
2150 if (!sse) {
2151 dasm_put(Dst, 14372);
2152 }
2153 dasm_put(Dst, 14378, Dt6(->hmask), sizeof(Node), Dt6(->node), DtB(->val.it), LJ_TNIL, DtB(->key.gcr), DtB(->key.it), DtB(->val.gcr), DtB(->val.it));
2154 dasm_put(Dst, 14453);
2155 break;
2156
2157 case BC_ISNEXT:
2158 dasm_put(Dst, 14461, LJ_TFUNC, LJ_TTAB, LJ_TNIL, Dt8(->ffid), FF_next_N, -BCBIAS_J*4, BC_JMP, -BCBIAS_J*4, BC_ITERC);
2159 break;
2160
2118 case BC_VARG: 2161 case BC_VARG:
2119 dasm_put(Dst, 14244, (8+FRAME_VARG), LJ_TNIL, Dt1(->maxstack)); 2162 dasm_put(Dst, 14560, (8+FRAME_VARG), LJ_TNIL, Dt1(->maxstack));
2120 dasm_put(Dst, 14408, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top)); 2163 dasm_put(Dst, 14724, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top));
2121 break; 2164 break;
2122 2165
2123 /* -- Returns ----------------------------------------------------------- */ 2166 /* -- Returns ----------------------------------------------------------- */
@@ -2128,30 +2171,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2128 2171
2129 case BC_RET: case BC_RET0: case BC_RET1: 2172 case BC_RET: case BC_RET0: case BC_RET1:
2130 if (op != BC_RET0) { 2173 if (op != BC_RET0) {
2131 dasm_put(Dst, 14479); 2174 dasm_put(Dst, 14795);
2132 } 2175 }
2133 dasm_put(Dst, 14483, FRAME_TYPE); 2176 dasm_put(Dst, 14799, FRAME_TYPE);
2134 switch (op) { 2177 switch (op) {
2135 case BC_RET: 2178 case BC_RET:
2136 dasm_put(Dst, 14502); 2179 dasm_put(Dst, 14818);
2137 break; 2180 break;
2138 case BC_RET1: 2181 case BC_RET1:
2139 dasm_put(Dst, 14560); 2182 dasm_put(Dst, 14876);
2140 /* fallthrough */ 2183 /* fallthrough */
2141 case BC_RET0: 2184 case BC_RET0:
2142 dasm_put(Dst, 14576); 2185 dasm_put(Dst, 14892);
2143 default: 2186 default:
2144 break; 2187 break;
2145 } 2188 }
2146 dasm_put(Dst, 14587, Dt7(->pc), PC2PROTO(k)); 2189 dasm_put(Dst, 14903, Dt7(->pc), PC2PROTO(k));
2147 if (op == BC_RET) { 2190 if (op == BC_RET) {
2148 dasm_put(Dst, 14629, LJ_TNIL); 2191 dasm_put(Dst, 14945, LJ_TNIL);
2149 } else { 2192 } else {
2150 dasm_put(Dst, 14638, LJ_TNIL); 2193 dasm_put(Dst, 14954, LJ_TNIL);
2151 } 2194 }
2152 dasm_put(Dst, 14645, -FRAME_VARG, FRAME_TYPEP); 2195 dasm_put(Dst, 14961, -FRAME_VARG, FRAME_TYPEP);
2153 if (op != BC_RET0) { 2196 if (op != BC_RET0) {
2154 dasm_put(Dst, 14669); 2197 dasm_put(Dst, 14985);
2155 } 2198 }
2156 dasm_put(Dst, 4689); 2199 dasm_put(Dst, 4689);
2157 break; 2200 break;
@@ -2161,7 +2204,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2161 2204
2162 case BC_FORL: 2205 case BC_FORL:
2163#if LJ_HASJIT 2206#if LJ_HASJIT
2164 dasm_put(Dst, 14673, HOTCOUNT_PCMASK, GG_DISP2HOT); 2207 dasm_put(Dst, 14989, HOTCOUNT_PCMASK, GG_DISP2HOT);
2165#endif 2208#endif
2166 break; 2209 break;
2167 2210
@@ -2173,57 +2216,57 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2173 case BC_FORI: 2216 case BC_FORI:
2174 case BC_IFORL: 2217 case BC_IFORL:
2175 vk = (op == BC_IFORL || op == BC_JFORL); 2218 vk = (op == BC_IFORL || op == BC_JFORL);
2176 dasm_put(Dst, 14694); 2219 dasm_put(Dst, 15010);
2177 if (!vk) { 2220 if (!vk) {
2178 dasm_put(Dst, 14698, LJ_TISNUM, LJ_TISNUM); 2221 dasm_put(Dst, 15014, LJ_TISNUM, LJ_TISNUM);
2179 } 2222 }
2180 dasm_put(Dst, 14717); 2223 dasm_put(Dst, 15033);
2181 if (!vk) { 2224 if (!vk) {
2182 dasm_put(Dst, 14721, LJ_TISNUM); 2225 dasm_put(Dst, 15037, LJ_TISNUM);
2183 } 2226 }
2184 if (sse) { 2227 if (sse) {
2185 dasm_put(Dst, 14730); 2228 dasm_put(Dst, 15046);
2186 if (vk) { 2229 if (vk) {
2187 dasm_put(Dst, 14742); 2230 dasm_put(Dst, 15058);
2188 } else { 2231 } else {
2189 dasm_put(Dst, 14761); 2232 dasm_put(Dst, 15077);
2190 } 2233 }
2191 dasm_put(Dst, 14766); 2234 dasm_put(Dst, 15082);
2192 } else { 2235 } else {
2193 dasm_put(Dst, 14779); 2236 dasm_put(Dst, 15095);
2194 if (vk) { 2237 if (vk) {
2195 dasm_put(Dst, 14785); 2238 dasm_put(Dst, 15101);
2196 } else { 2239 } else {
2197 dasm_put(Dst, 14801); 2240 dasm_put(Dst, 15117);
2198 } 2241 }
2199 dasm_put(Dst, 14809); 2242 dasm_put(Dst, 15125);
2200 if (cmov) { 2243 if (cmov) {
2201 dasm_put(Dst, 10818); 2244 dasm_put(Dst, 10818);
2202 } else { 2245 } else {
2203 dasm_put(Dst, 10824); 2246 dasm_put(Dst, 10824);
2204 } 2247 }
2205 if (!cmov) { 2248 if (!cmov) {
2206 dasm_put(Dst, 14814); 2249 dasm_put(Dst, 15130);
2207 } 2250 }
2208 } 2251 }
2209 if (op == BC_FORI) { 2252 if (op == BC_FORI) {
2210 dasm_put(Dst, 14820, -BCBIAS_J*4); 2253 dasm_put(Dst, 15136, -BCBIAS_J*4);
2211 } else if (op == BC_JFORI) { 2254 } else if (op == BC_JFORI) {
2212 dasm_put(Dst, 14830, -BCBIAS_J*4, BC_JLOOP); 2255 dasm_put(Dst, 15146, -BCBIAS_J*4, BC_JLOOP);
2213 } else if (op == BC_IFORL) { 2256 } else if (op == BC_IFORL) {
2214 dasm_put(Dst, 14844, -BCBIAS_J*4); 2257 dasm_put(Dst, 15160, -BCBIAS_J*4);
2215 } else { 2258 } else {
2216 dasm_put(Dst, 14840, BC_JLOOP); 2259 dasm_put(Dst, 15156, BC_JLOOP);
2217 } 2260 }
2218 dasm_put(Dst, 10853); 2261 dasm_put(Dst, 10853);
2219 if (sse) { 2262 if (sse) {
2220 dasm_put(Dst, 14854); 2263 dasm_put(Dst, 15170);
2221 } 2264 }
2222 break; 2265 break;
2223 2266
2224 case BC_ITERL: 2267 case BC_ITERL:
2225#if LJ_HASJIT 2268#if LJ_HASJIT
2226 dasm_put(Dst, 14673, HOTCOUNT_PCMASK, GG_DISP2HOT); 2269 dasm_put(Dst, 14989, HOTCOUNT_PCMASK, GG_DISP2HOT);
2227#endif 2270#endif
2228 break; 2271 break;
2229 2272
@@ -2232,18 +2275,18 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2232 break; 2275 break;
2233#endif 2276#endif
2234 case BC_IITERL: 2277 case BC_IITERL:
2235 dasm_put(Dst, 14865, LJ_TNIL); 2278 dasm_put(Dst, 15181, LJ_TNIL);
2236 if (op == BC_JITERL) { 2279 if (op == BC_JITERL) {
2237 dasm_put(Dst, 14880, BC_JLOOP); 2280 dasm_put(Dst, 15196, BC_JLOOP);
2238 } else { 2281 } else {
2239 dasm_put(Dst, 14894, -BCBIAS_J*4); 2282 dasm_put(Dst, 15210, -BCBIAS_J*4);
2240 } 2283 }
2241 dasm_put(Dst, 11150); 2284 dasm_put(Dst, 11150);
2242 break; 2285 break;
2243 2286
2244 case BC_LOOP: 2287 case BC_LOOP:
2245#if LJ_HASJIT 2288#if LJ_HASJIT
2246 dasm_put(Dst, 14673, HOTCOUNT_PCMASK, GG_DISP2HOT); 2289 dasm_put(Dst, 14989, HOTCOUNT_PCMASK, GG_DISP2HOT);
2247#endif 2290#endif
2248 break; 2291 break;
2249 2292
@@ -2253,12 +2296,12 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2253 2296
2254 case BC_JLOOP: 2297 case BC_JLOOP:
2255#if LJ_HASJIT 2298#if LJ_HASJIT
2256 dasm_put(Dst, 14910, DISPATCH_J(trace), DtD(->mcode), DISPATCH_GL(jit_base), DISPATCH_GL(jit_L)); 2299 dasm_put(Dst, 15226, DISPATCH_J(trace), DtD(->mcode), DISPATCH_GL(jit_base), DISPATCH_GL(jit_L));
2257#endif 2300#endif
2258 break; 2301 break;
2259 2302
2260 case BC_JMP: 2303 case BC_JMP:
2261 dasm_put(Dst, 14933, -BCBIAS_J*4); 2304 dasm_put(Dst, 15249, -BCBIAS_J*4);
2262 break; 2305 break;
2263 2306
2264 /* -- Function headers -------------------------------------------------- */ 2307 /* -- Function headers -------------------------------------------------- */
@@ -2272,7 +2315,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2272 2315
2273 case BC_FUNCF: 2316 case BC_FUNCF:
2274#if LJ_HASJIT 2317#if LJ_HASJIT
2275 dasm_put(Dst, 14957, HOTCOUNT_PCMASK, GG_DISP2HOT); 2318 dasm_put(Dst, 15273, HOTCOUNT_PCMASK, GG_DISP2HOT);
2276#endif 2319#endif
2277 case BC_FUNCV: /* NYI: compiled vararg functions. */ 2320 case BC_FUNCV: /* NYI: compiled vararg functions. */
2278 break; 2321 break;
@@ -2282,13 +2325,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2282 break; 2325 break;
2283#endif 2326#endif
2284 case BC_IFUNCF: 2327 case BC_IFUNCF:
2285 dasm_put(Dst, 14978, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams)); 2328 dasm_put(Dst, 15294, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
2286 if (op == BC_JFUNCF) { 2329 if (op == BC_JFUNCF) {
2287 dasm_put(Dst, 15008, BC_JLOOP); 2330 dasm_put(Dst, 15324, BC_JLOOP);
2288 } else { 2331 } else {
2289 dasm_put(Dst, 10855); 2332 dasm_put(Dst, 10855);
2290 } 2333 }
2291 dasm_put(Dst, 15017, LJ_TNIL); 2334 dasm_put(Dst, 15333, LJ_TNIL);
2292 break; 2335 break;
2293 2336
2294 case BC_JFUNCV: 2337 case BC_JFUNCV:
@@ -2299,30 +2342,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
2299 break; /* NYI: compiled vararg functions. */ 2342 break; /* NYI: compiled vararg functions. */
2300 2343
2301 case BC_IFUNCV: 2344 case BC_IFUNCV:
2302 dasm_put(Dst, 15039, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL); 2345 dasm_put(Dst, 15355, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
2303 if (op == BC_JFUNCV) { 2346 if (op == BC_JFUNCV) {
2304 dasm_put(Dst, 15008, BC_JLOOP); 2347 dasm_put(Dst, 15324, BC_JLOOP);
2305 } else { 2348 } else {
2306 dasm_put(Dst, 15130, -4+PC2PROTO(k)); 2349 dasm_put(Dst, 15446, -4+PC2PROTO(k));
2307 } 2350 }
2308 dasm_put(Dst, 15152, LJ_TNIL); 2351 dasm_put(Dst, 15468, LJ_TNIL);
2309 break; 2352 break;
2310 2353
2311 case BC_FUNCC: 2354 case BC_FUNCC:
2312 case BC_FUNCCW: 2355 case BC_FUNCCW:
2313 dasm_put(Dst, 15174, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top)); 2356 dasm_put(Dst, 15490, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
2314 if (op == BC_FUNCC) { 2357 if (op == BC_FUNCC) {
2315 dasm_put(Dst, 15203); 2358 dasm_put(Dst, 15519);
2316 } else { 2359 } else {
2317 dasm_put(Dst, 15207); 2360 dasm_put(Dst, 15523);
2318 } 2361 }
2319 dasm_put(Dst, 15215, DISPATCH_GL(vmstate), ~LJ_VMST_C); 2362 dasm_put(Dst, 15531, DISPATCH_GL(vmstate), ~LJ_VMST_C);
2320 if (op == BC_FUNCC) { 2363 if (op == BC_FUNCC) {
2321 dasm_put(Dst, 15224); 2364 dasm_put(Dst, 15540);
2322 } else { 2365 } else {
2323 dasm_put(Dst, 15228, DISPATCH_GL(wrapf)); 2366 dasm_put(Dst, 15544, DISPATCH_GL(wrapf));
2324 } 2367 }
2325 dasm_put(Dst, 15233, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top)); 2368 dasm_put(Dst, 15549, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
2326 break; 2369 break;
2327 2370
2328 /* ---------------------------------------------------------------------- */ 2371 /* ---------------------------------------------------------------------- */
@@ -2350,7 +2393,7 @@ static int build_backend(BuildCtx *ctx)
2350 2393
2351 build_subroutines(ctx, cmov, sse); 2394 build_subroutines(ctx, cmov, sse);
2352 2395
2353 dasm_put(Dst, 15258); 2396 dasm_put(Dst, 15574);
2354 for (op = 0; op < BC__MAX; op++) 2397 for (op = 0; op < BC__MAX; op++)
2355 build_ins(ctx, (BCOp)op, op, cmov, sse); 2398 build_ins(ctx, (BCOp)op, op, cmov, sse);
2356 2399
diff --git a/src/lib_base.c b/src/lib_base.c
index 5f7b059b..8f63effc 100644
--- a/src/lib_base.c
+++ b/src/lib_base.c
@@ -240,6 +240,9 @@ LJLIB_ASM(tostring) LJLIB_REC(.)
240 240
241/* -- Base library: iterators --------------------------------------------- */ 241/* -- Base library: iterators --------------------------------------------- */
242 242
243/* This solves a circular dependency problem -- change FF_next_N as needed. */
244LJ_STATIC_ASSERT((int)FF_next == FF_next_N);
245
243LJLIB_ASM(next) 246LJLIB_ASM(next)
244{ 247{
245 lj_lib_checktab(L, 1); 248 lj_lib_checktab(L, 1);
diff --git a/src/lj_bc.h b/src/lj_bc.h
index ba868283..837316d5 100644
--- a/src/lj_bc.h
+++ b/src/lj_bc.h
@@ -154,6 +154,8 @@
154 _(CALLMT, base, ___, lit, call) \ 154 _(CALLMT, base, ___, lit, call) \
155 _(CALLT, base, ___, lit, call) \ 155 _(CALLT, base, ___, lit, call) \
156 _(ITERC, base, lit, lit, call) \ 156 _(ITERC, base, lit, lit, call) \
157 _(ITERN, base, lit, lit, call) \
158 _(ISNEXT, base, ___, jump, ___) \
157 _(VARG, base, lit, lit, ___) \ 159 _(VARG, base, lit, lit, ___) \
158 \ 160 \
159 /* Returns. */ \ 161 /* Returns. */ \
@@ -221,6 +223,9 @@ LJ_STATIC_ASSERT((int)BC_FUNCF + 2 == (int)BC_JFUNCF);
221LJ_STATIC_ASSERT((int)BC_FUNCV + 1 == (int)BC_IFUNCV); 223LJ_STATIC_ASSERT((int)BC_FUNCV + 1 == (int)BC_IFUNCV);
222LJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV); 224LJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV);
223 225
226/* This solves a circular dependency problem, change as needed. */
227#define FF_next_N 15
228
224/* Stack slots used by FORI/FORL, relative to operand A. */ 229/* Stack slots used by FORI/FORL, relative to operand A. */
225enum { 230enum {
226 FORL_IDX, FORL_STOP, FORL_STEP, FORL_EXT 231 FORL_IDX, FORL_STOP, FORL_STEP, FORL_EXT
diff --git a/src/lj_parse.c b/src/lj_parse.c
index 1570f833..b063da25 100644
--- a/src/lj_parse.c
+++ b/src/lj_parse.c
@@ -2030,41 +2030,13 @@ static void parse_repeat(LexState *ls, BCLine line)
2030 scope_end(fs); /* End loop scope. */ 2030 scope_end(fs); /* End loop scope. */
2031} 2031}
2032 2032
2033/* Parse body of a 'for' statement. */
2034static void parse_for_body(LexState *ls, BCReg base, BCLine line,
2035 BCReg nvars, int isnum)
2036{
2037 FuncScope bl;
2038 FuncState *fs = ls->fs;
2039 BCPos loop, loopend;
2040 var_add(ls, 3); /* Hidden control variables. */
2041 lex_check(ls, TK_do);
2042 loop = isnum ? bcemit_AJ(fs, BC_FORI, base, NO_JMP) :
2043 bcemit_AJ(fs, BC_JMP, fs->freereg, NO_JMP);
2044 scope_begin(fs, &bl, 0); /* Scope for visible variables. */
2045 var_add(ls, nvars);
2046 bcreg_reserve(fs, nvars);
2047 parse_block(ls);
2048 scope_end(fs);
2049 /* Perform loop inversion. Loop control instructions are at the end. */
2050 if (isnum) {
2051 loopend = bcemit_AJ(fs, BC_FORL, base, NO_JMP);
2052 jmp_patchins(fs, loop, fs->pc);
2053 } else {
2054 jmp_patchins(fs, loop, fs->pc);
2055 bcemit_ABC(fs, BC_ITERC, base+3, nvars+1, 2+1);
2056 loopend = bcemit_AJ(fs, BC_ITERL, base+3, NO_JMP);
2057 fs->bcbase[loopend-1].line = line;
2058 }
2059 fs->bcbase[loopend].line = line; /* Fix line for control ins. */
2060 jmp_patchins(fs, loopend, loop+1);
2061}
2062
2063/* Parse numeric 'for'. */ 2033/* Parse numeric 'for'. */
2064static void parse_for_num(LexState *ls, GCstr *varname, BCLine line) 2034static void parse_for_num(LexState *ls, GCstr *varname, BCLine line)
2065{ 2035{
2066 FuncState *fs = ls->fs; 2036 FuncState *fs = ls->fs;
2067 BCReg base = fs->freereg; 2037 BCReg base = fs->freereg;
2038 FuncScope bl;
2039 BCPos loop, loopend;
2068 /* Hidden control variables. */ 2040 /* Hidden control variables. */
2069 var_new_lit(ls, FORL_IDX, "(for index)"); 2041 var_new_lit(ls, FORL_IDX, "(for index)");
2070 var_new_lit(ls, FORL_STOP, "(for limit)"); 2042 var_new_lit(ls, FORL_STOP, "(for limit)");
@@ -2081,7 +2053,51 @@ static void parse_for_num(LexState *ls, GCstr *varname, BCLine line)
2081 bcemit_AD(fs, BC_KSHORT, fs->freereg, 1); /* Default step is 1. */ 2053 bcemit_AD(fs, BC_KSHORT, fs->freereg, 1); /* Default step is 1. */
2082 bcreg_reserve(fs, 1); 2054 bcreg_reserve(fs, 1);
2083 } 2055 }
2084 parse_for_body(ls, base, line, 1, 1); 2056 var_add(ls, 3); /* Hidden control variables. */
2057 lex_check(ls, TK_do);
2058 loop = bcemit_AJ(fs, BC_FORI, base, NO_JMP);
2059 scope_begin(fs, &bl, 0); /* Scope for visible variables. */
2060 var_add(ls, 1);
2061 bcreg_reserve(fs, 1);
2062 parse_block(ls);
2063 scope_end(fs);
2064 /* Perform loop inversion. Loop control instructions are at the end. */
2065 loopend = bcemit_AJ(fs, BC_FORL, base, NO_JMP);
2066 fs->bcbase[loopend].line = line; /* Fix line for control ins. */
2067 jmp_patchins(fs, loopend, loop+1);
2068 jmp_patchins(fs, loop, fs->pc);
2069}
2070
2071/* Try to predict whether the iterator is next() and specialize the bytecode.
2072** Detecting next() and pairs() by name is simplistic, but quite effective.
2073** The interpreter backs off if the check for the closure fails at runtime.
2074*/
2075static int predict_next(LexState *ls, FuncState *fs, BCPos pc)
2076{
2077 BCIns ins = fs->bcbase[pc].ins;
2078 GCstr *name;
2079 cTValue *o;
2080 switch (bc_op(ins)) {
2081 case BC_MOV:
2082 name = gco2str(gcref(var_get(ls, fs, bc_d(ins)).name));
2083 break;
2084 case BC_UGET:
2085 name = gco2str(gcref(ls->vstack[fs->uvloc[bc_d(ins)].vidx].name));
2086 break;
2087 case BC_GGET:
2088 /* There's no inverse index (yet), so lookup the strings. */
2089 o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, "pairs"));
2090 if (o && tvisnum(o) && o->u32.lo == bc_d(ins))
2091 return 1;
2092 o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, "next"));
2093 if (o && tvisnum(o) && o->u32.lo == bc_d(ins))
2094 return 1;
2095 return 0;
2096 default:
2097 return 0;
2098 }
2099 return (name->len == 5 && !strcmp(strdata(name), "pairs")) ||
2100 (name->len == 4 && !strcmp(strdata(name), "next"));
2085} 2101}
2086 2102
2087/* Parse 'for' iterator. */ 2103/* Parse 'for' iterator. */
@@ -2091,7 +2107,10 @@ static void parse_for_iter(LexState *ls, GCstr *indexname)
2091 ExpDesc e; 2107 ExpDesc e;
2092 BCReg nvars = 0; 2108 BCReg nvars = 0;
2093 BCLine line; 2109 BCLine line;
2094 BCReg base = fs->freereg; 2110 BCReg base = fs->freereg + 3;
2111 BCPos loop, loopend, exprpc = fs->pc;
2112 FuncScope bl;
2113 int isnext;
2095 /* Hidden control variables. */ 2114 /* Hidden control variables. */
2096 var_new_lit(ls, nvars++, "(for generator)"); 2115 var_new_lit(ls, nvars++, "(for generator)");
2097 var_new_lit(ls, nvars++, "(for state)"); 2116 var_new_lit(ls, nvars++, "(for state)");
@@ -2104,7 +2123,22 @@ static void parse_for_iter(LexState *ls, GCstr *indexname)
2104 line = ls->linenumber; 2123 line = ls->linenumber;
2105 assign_adjust(ls, 3, expr_list(ls, &e), &e); 2124 assign_adjust(ls, 3, expr_list(ls, &e), &e);
2106 bcreg_bump(fs, 3); /* The iterator needs another 3 slots (func + 2 args). */ 2125 bcreg_bump(fs, 3); /* The iterator needs another 3 slots (func + 2 args). */
2107 parse_for_body(ls, base, line, nvars - 3, 0); 2126 isnext = (nvars <= 5 && predict_next(ls, fs, exprpc));
2127 var_add(ls, 3); /* Hidden control variables. */
2128 lex_check(ls, TK_do);
2129 loop = bcemit_AJ(fs, isnext ? BC_ISNEXT : BC_JMP, base, NO_JMP);
2130 scope_begin(fs, &bl, 0); /* Scope for visible variables. */
2131 var_add(ls, nvars-3);
2132 bcreg_reserve(fs, nvars-3);
2133 parse_block(ls);
2134 scope_end(fs);
2135 /* Perform loop inversion. Loop control instructions are at the end. */
2136 jmp_patchins(fs, loop, fs->pc);
2137 bcemit_ABC(fs, isnext ? BC_ITERN : BC_ITERC, base, nvars-3+1, 2+1);
2138 loopend = bcemit_AJ(fs, BC_ITERL, base, NO_JMP);
2139 fs->bcbase[loopend-1].line = line; /* Fix line for control ins. */
2140 fs->bcbase[loopend].line = line;
2141 jmp_patchins(fs, loopend, loop+1);
2108} 2142}
2109 2143
2110/* Parse 'for' statement. */ 2144/* Parse 'for' statement. */
diff --git a/src/lj_record.c b/src/lj_record.c
index 6e396729..4845eeac 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -2477,6 +2477,8 @@ void lj_record_ins(jit_State *J)
2477 break; 2477 break;
2478 } 2478 }
2479 /* fallthrough */ 2479 /* fallthrough */
2480 case BC_ITERN:
2481 case BC_ISNEXT:
2480 case BC_CAT: 2482 case BC_CAT:
2481 case BC_UCLO: 2483 case BC_UCLO:
2482 case BC_FNEW: 2484 case BC_FNEW: