From c8b3865338d3399dd983b36e1e0ad17f326bdd86 Mon Sep 17 00:00:00 2001 From: "kr.angelov" Date: Wed, 22 Oct 2014 14:11:41 +0000 Subject: an explicit PUSH_FRAME instruction --- src/runtime/c/pgf/data.h | 13 +++++----- src/runtime/c/pgf/jit.c | 34 ++++++++++----------------- src/runtime/haskell/PGF/Binary.hs | 47 +++++++++++++++++++------------------ src/runtime/haskell/PGF/ByteCode.hs | 2 ++ 4 files changed, 46 insertions(+), 50 deletions(-) (limited to 'src/runtime') diff --git a/src/runtime/c/pgf/data.h b/src/runtime/c/pgf/data.h index 2b11f24da..154679ac8 100644 --- a/src/runtime/c/pgf/data.h +++ b/src/runtime/c/pgf/data.h @@ -133,12 +133,13 @@ typedef enum { PGF_INSTR_PUT_LIT = 6, PGF_INSTR_SET = 7, PGF_INSTR_SET_PAD = 8, - PGF_INSTR_PUSH = 9, - PGF_INSTR_EVAL = 10, - PGF_INSTR_DROP = 13, - PGF_INSTR_JUMP = 14, - PGF_INSTR_FAIL = 15, - PGF_INSTR_ADD = 16 + PGF_INSTR_PUSH_FRAME = 9, + PGF_INSTR_PUSH = 10, + PGF_INSTR_EVAL = 11, + PGF_INSTR_DROP = 14, + PGF_INSTR_JUMP = 15, + PGF_INSTR_FAIL = 16, + PGF_INSTR_ADD = 17, } PgfInstruction; typedef GuSeq PgfConcrs; diff --git a/src/runtime/c/pgf/jit.c b/src/runtime/c/pgf/jit.c index 0b42cc91f..dbb441454 100644 --- a/src/runtime/c/pgf/jit.c +++ b/src/runtime/c/pgf/jit.c @@ -937,6 +937,15 @@ pgf_jit_function(PgfReader* rdr, PgfAbstr* abstr, curr_offset++; break; } + case PGF_INSTR_PUSH_FRAME: { +#ifdef PGF_JIT_DEBUG + gu_printf(out, err, "PUSH_FRAME\n"); +#endif + jit_pushr_p(JIT_VCLOS); + jit_pushr_p(JIT_FP); + jit_movr_p(JIT_FP, JIT_SP); + break; + } case PGF_INSTR_PUSH: { switch (mod) { case 0: { @@ -990,7 +999,6 @@ pgf_jit_function(PgfReader* rdr, PgfAbstr* abstr, } case PGF_INSTR_EVAL+0: case PGF_INSTR_EVAL+2: - jit_movr_p(JIT_R2, JIT_VCLOS); case PGF_INSTR_EVAL+1: { switch (mod) { case 0: { @@ -1039,9 +1047,6 @@ pgf_jit_function(PgfReader* rdr, PgfAbstr* abstr, #ifdef PGF_JIT_DEBUG gu_printf(out, err, "\n"); #endif - jit_pushr_p(JIT_R2); - jit_pushr_p(JIT_FP); - jit_movr_p(JIT_FP, JIT_SP); jit_callr(JIT_R0); jit_popr_p(JIT_FP); jit_popr_p(JIT_VCLOS); @@ -1072,28 +1077,15 @@ pgf_jit_function(PgfReader* rdr, PgfAbstr* abstr, gu_printf(out, err, " update(%d,%d)\n", b, c); #endif - if (b >= 3) { - jit_stxi_p(sizeof(PgfClosure*)*(c-3), JIT_SP, JIT_FP); - jit_stxi_p(sizeof(PgfClosure*)*(c-2), JIT_SP, JIT_R2); + if (b > 1) { for (size_t i = 0; i < c-b; i++) { - jit_ldxi_p(JIT_R1, JIT_SP, sizeof(PgfClosure*)*((c-b-1)-i)); - jit_stxi_p(sizeof(PgfClosure*)*((c-4)-i), JIT_SP, JIT_R1); + jit_ldxi_p(JIT_R1, JIT_SP, sizeof(PgfClosure*)*(c-b-1-i)); + jit_stxi_p(sizeof(PgfClosure*)*(c-2-i), JIT_SP, JIT_R1); } - jit_addi_p(JIT_SP, JIT_SP, (b-3)*sizeof(PgfClosure*)); - } else { - jit_subi_p(JIT_SP, JIT_SP, (3-b)*sizeof(PgfClosure*)); - for (size_t i = 0; i < c-b; i++) { - jit_ldxi_p(JIT_R1, JIT_SP, sizeof(PgfClosure*)*(i+(3-b))); - jit_stxi_p(sizeof(PgfClosure*)*i, JIT_SP, JIT_R1); - } - jit_stxi_p(sizeof(PgfClosure*)*(c-b), JIT_SP, JIT_FP); - jit_stxi_p(sizeof(PgfClosure*)*(c-b+1), JIT_SP, JIT_R2); + jit_addi_p(JIT_SP, JIT_SP, (b-1)*sizeof(PgfClosure*)); } - - jit_addi_p(JIT_FP, JIT_SP, sizeof(PgfClosure*)*(c-b)); jit_movi_p(JIT_R1, abstr->eval_gates->update_closure); jit_pushr_p(JIT_R1); - jit_jmpr(JIT_R0); break; } diff --git a/src/runtime/haskell/PGF/Binary.hs b/src/runtime/haskell/PGF/Binary.hs index 93214038c..3dcf9e163 100644 --- a/src/runtime/haskell/PGF/Binary.hs +++ b/src/runtime/haskell/PGF/Binary.hs @@ -144,34 +144,35 @@ instance Binary Instr where put (ALLOC n) = putWord8 12 >> put n put (PUT_CONSTR id) = putWord8 16 >> put id put (PUT_CLOSURE l) = putWord8 20 >> put l - put (PUT_LIT (LInt n)) = putWord8 24 >> put n - put (PUT_LIT (LStr s)) = putWord8 25 >> put s - put (PUT_LIT (LFlt d)) = putWord8 26 >> put d + put (PUT_LIT (LInt n)) = putWord8 24 >> put n + put (PUT_LIT (LStr s)) = putWord8 25 >> put s + put (PUT_LIT (LFlt d)) = putWord8 26 >> put d put (SET (HEAP n)) = putWord8 28 >> put n put (SET (ARG_VAR n)) = putWord8 29 >> put n put (SET (FREE_VAR n)) = putWord8 30 >> put n put (SET (GLOBAL id)) = putWord8 31 >> put id put (SET_PAD ) = putWord8 32 - put (PUSH (HEAP n)) = putWord8 36 >> put n - put (PUSH (ARG_VAR n)) = putWord8 37 >> put n - put (PUSH (FREE_VAR n)) = putWord8 38 >> put n - put (PUSH (GLOBAL id)) = putWord8 39 >> put id - put (EVAL (HEAP n) (RecCall )) = putWord8 40 >> put n - put (EVAL (ARG_VAR n) (RecCall )) = putWord8 41 >> put n - put (EVAL (FREE_VAR n) (RecCall )) = putWord8 42 >> put n - put (EVAL (GLOBAL id) (RecCall )) = putWord8 43 >> put id - put (EVAL (HEAP n) (TailCall a b c)) = putWord8 44 >> put n >> put (a,b,c) - put (EVAL (ARG_VAR n) (TailCall a b c)) = putWord8 45 >> put n >> put (a,b,c) - put (EVAL (FREE_VAR n) (TailCall a b c)) = putWord8 46 >> put n >> put (a,b,c) - put (EVAL (GLOBAL id) (TailCall a b c)) = putWord8 47 >> put id >> put (a,b,c) - put (EVAL (HEAP n) (UpdateCall b c)) = putWord8 48 >> put n >> put (b,c) - put (EVAL (ARG_VAR n) (UpdateCall b c)) = putWord8 49 >> put n >> put (b,c) - put (EVAL (FREE_VAR n) (UpdateCall b c)) = putWord8 50 >> put n >> put (b,c) - put (EVAL (GLOBAL id) (UpdateCall b c)) = putWord8 51 >> put id >> put (b,c) - put (DROP n ) = putWord8 52 >> put n - put (JUMP l ) = putWord8 56 >> put l - put (FAIL ) = putWord8 60 - put (ADD ) = putWord8 64 + put (PUSH_FRAME ) = putWord8 36 + put (PUSH (HEAP n)) = putWord8 40 >> put n + put (PUSH (ARG_VAR n)) = putWord8 41 >> put n + put (PUSH (FREE_VAR n)) = putWord8 42 >> put n + put (PUSH (GLOBAL id)) = putWord8 43 >> put id + put (EVAL (HEAP n) (RecCall )) = putWord8 44 >> put n + put (EVAL (ARG_VAR n) (RecCall )) = putWord8 45 >> put n + put (EVAL (FREE_VAR n) (RecCall )) = putWord8 46 >> put n + put (EVAL (GLOBAL id) (RecCall )) = putWord8 47 >> put id + put (EVAL (HEAP n) (TailCall a b c)) = putWord8 48 >> put n >> put (a,b,c) + put (EVAL (ARG_VAR n) (TailCall a b c)) = putWord8 49 >> put n >> put (a,b,c) + put (EVAL (FREE_VAR n) (TailCall a b c)) = putWord8 50 >> put n >> put (a,b,c) + put (EVAL (GLOBAL id) (TailCall a b c)) = putWord8 51 >> put id >> put (a,b,c) + put (EVAL (HEAP n) (UpdateCall b c)) = putWord8 52 >> put n >> put (b,c) + put (EVAL (ARG_VAR n) (UpdateCall b c)) = putWord8 53 >> put n >> put (b,c) + put (EVAL (FREE_VAR n) (UpdateCall b c)) = putWord8 54 >> put n >> put (b,c) + put (EVAL (GLOBAL id) (UpdateCall b c)) = putWord8 55 >> put id >> put (b,c) + put (DROP n ) = putWord8 56 >> put n + put (JUMP l ) = putWord8 60 >> put l + put (FAIL ) = putWord8 64 + put (ADD ) = putWord8 68 instance Binary Type where put (DTyp hypos cat exps) = put (hypos,cat,exps) diff --git a/src/runtime/haskell/PGF/ByteCode.hs b/src/runtime/haskell/PGF/ByteCode.hs index 46f81cff9..f4aebfd92 100644 --- a/src/runtime/haskell/PGF/ByteCode.hs +++ b/src/runtime/haskell/PGF/ByteCode.hs @@ -24,6 +24,7 @@ data Instr | PUT_LIT Literal | SET IVal | SET_PAD + | PUSH_FRAME | PUSH IVal | EVAL IVal TailInfo | DROP {-# UNPACK #-} !Int @@ -59,6 +60,7 @@ ppInstr (PUT_CLOSURE l) = text "PUT_CLOSURE" <+> ppLabel l ppInstr (PUT_LIT lit ) = text "PUT_LIT " <+> ppLit lit ppInstr (SET v) = text "SET " <+> ppIVal v ppInstr (SET_PAD ) = text "SET_PAD" +ppInstr (PUSH_FRAME ) = text "PUSH_FRAME" ppInstr (PUSH v) = text "PUSH " <+> ppIVal v ppInstr (EVAL v ti) = text "EVAL " <+> ppIVal v <+> ppTailInfo ti ppInstr (DROP n ) = text "DROP " <+> int n -- cgit v1.2.3