From eacc55a8188c91c746f00e3e9a99484297556b00 Mon Sep 17 00:00:00 2001 From: Thomas Cort Date: Sun, 20 Aug 2006 15:47:54 +0000 Subject: [PATCH] Remove unnecessary code from the prolog, epilog, redirector, and closure. Implement > and >= opcodes for signed and unsigned values. --- ChangeLog | 7 ++++ jit/jit-apply-alpha.c | 77 ++++++++--------------------------------- jit/jit-apply-alpha.h | 4 +-- jit/jit-gen-alpha.h | 13 +++++++ jit/jit-rules-alpha.c | 38 +------------------- jit/jit-rules-alpha.h | 2 +- jit/jit-rules-alpha.ins | 36 +++++++++++++++++-- 7 files changed, 73 insertions(+), 104 deletions(-) diff --git a/ChangeLog b/ChangeLog index d12e494..e8149ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-08-20 Thomas Cort + + * jit/jit-apply-alpha.c jit/jit-apply-alpha.h jit/jit-rules-alpha.h + jit/jit-rules-alpha.ins jit/jit-rules-alpha.c jit/jit-gen-alpha.h: + Remove unnecessary code from the prolog, epilog, redirector, and + closure. Implement > and >= opcodes for signed and unsigned values. + 2006-08-19 Aleksey Demakov * jit/jit-reg-alloc.c (set_regdesc_flags): fix a problem with the diff --git a/jit/jit-apply-alpha.c b/jit/jit-apply-alpha.c index 66c79bb..9c07a20 100644 --- a/jit/jit-apply-alpha.c +++ b/jit/jit-apply-alpha.c @@ -27,17 +27,17 @@ void _jit_create_closure(unsigned char *buf, void *func, void *closure, void *_type) { alpha_inst inst = (alpha_inst) buf; - /* Compute and load the global pointer */ + /* Compute and load the global pointer (2 instructions) */ alpha_ldah(inst,ALPHA_GP,ALPHA_PV,0); alpha_lda( inst,ALPHA_GP,ALPHA_GP,0); - /* Allocate space for a new stack frame. */ + /* Allocate space for a new stack frame. (1 instruction) */ alpha_lda(inst,ALPHA_SP,ALPHA_SP,-(13*8)); - /* Save the return address. */ + /* Save the return address. (1 instruction) */ alpha_stq(inst,ALPHA_RA,ALPHA_SP,0*8); - /* Save integer register arguments as local variables */ + /* Save integer register arguments as local variables (6 instructions) */ alpha_stq(inst,ALPHA_A0,ALPHA_SP,1*8); alpha_stq(inst,ALPHA_A1,ALPHA_SP,2*8); alpha_stq(inst,ALPHA_A2,ALPHA_SP,3*8); @@ -45,7 +45,7 @@ void _jit_create_closure(unsigned char *buf, void *func, void *closure, void *_t alpha_stq(inst,ALPHA_A4,ALPHA_SP,5*8); alpha_stq(inst,ALPHA_A5,ALPHA_SP,6*8); - /* Save floating-point register arguments as local variables */ + /* Save floating-point register arguments as local variables (8 instructions) */ alpha_stt(inst,ALPHA_FA0,ALPHA_SP, 7*8); alpha_stt(inst,ALPHA_FA1,ALPHA_SP, 8*8); alpha_stt(inst,ALPHA_FA2,ALPHA_SP, 9*8); @@ -53,13 +53,13 @@ void _jit_create_closure(unsigned char *buf, void *func, void *closure, void *_t alpha_stt(inst,ALPHA_FA4,ALPHA_SP,11*8); alpha_stt(inst,ALPHA_FA5,ALPHA_SP,12*8); - /* Call the closure handling function */ + /* Call the closure handling function (1 instruction) */ alpha_call(inst,func); - /* Restore the return address */ + /* Restore the return address (1 instruction) */ alpha_ldq(inst,ALPHA_RA,ALPHA_SP,0*8); - /* Restore integer register arguments */ + /* Restore integer register arguments (6 instructions) */ alpha_ldq(inst,ALPHA_A0,ALPHA_SP,1*8); alpha_ldq(inst,ALPHA_A1,ALPHA_SP,2*8); alpha_ldq(inst,ALPHA_A2,ALPHA_SP,3*8); @@ -67,7 +67,7 @@ void _jit_create_closure(unsigned char *buf, void *func, void *closure, void *_t alpha_ldq(inst,ALPHA_A4,ALPHA_SP,5*8); alpha_ldq(inst,ALPHA_A5,ALPHA_SP,6*8); - /* Restore floating-point register arguments */ + /* Restore floating-point register arguments (8 instructions) */ alpha_ldt(inst,ALPHA_FA0,ALPHA_SP, 7*8); alpha_ldt(inst,ALPHA_FA1,ALPHA_SP, 8*8); alpha_ldt(inst,ALPHA_FA2,ALPHA_SP, 9*8); @@ -75,7 +75,7 @@ void _jit_create_closure(unsigned char *buf, void *func, void *closure, void *_t alpha_ldt(inst,ALPHA_FA4,ALPHA_SP,11*8); alpha_ldt(inst,ALPHA_FA5,ALPHA_SP,12*8); - /* restore the stack pointer */ + /* restore the stack pointer (1 instruction) */ alpha_lda(inst,ALPHA_SP,ALPHA_SP,(13*8)); } @@ -112,63 +112,16 @@ void *_jit_create_redirector(unsigned char *buf, void *func, void *user_data, in /* Set the frame pointer (1 instruction) */ alpha_mov(inst,ALPHA_SP,ALPHA_FP); - /* Force any pending hardware exceptions to be raised. (1 instruction) */ - alpha_trapb(inst); - - /* Compute and load the global pointer */ + /* Compute and load the global pointer (2 instructions) */ alpha_ldah(inst,ALPHA_GP,ALPHA_PV,0); alpha_lda( inst,ALPHA_GP,ALPHA_GP,0); - /* Allocate space for a new stack frame. */ - alpha_lda(inst,ALPHA_SP,ALPHA_SP,-(13*8)); - - /* Save the return address. */ - alpha_stq(inst,ALPHA_RA,ALPHA_SP,0*8); - - /* Save integer register arguments as local variables */ - alpha_stq(inst,ALPHA_A0,ALPHA_SP,1*8); - alpha_stq(inst,ALPHA_A1,ALPHA_SP,2*8); - alpha_stq(inst,ALPHA_A2,ALPHA_SP,3*8); - alpha_stq(inst,ALPHA_A3,ALPHA_SP,4*8); - alpha_stq(inst,ALPHA_A4,ALPHA_SP,5*8); - alpha_stq(inst,ALPHA_A5,ALPHA_SP,6*8); - - /* Save floating-point register arguments as local variables */ - alpha_stt(inst,ALPHA_FA0,ALPHA_SP, 7*8); - alpha_stt(inst,ALPHA_FA1,ALPHA_SP, 8*8); - alpha_stt(inst,ALPHA_FA2,ALPHA_SP, 9*8); - alpha_stt(inst,ALPHA_FA3,ALPHA_SP,10*8); - alpha_stt(inst,ALPHA_FA4,ALPHA_SP,11*8); - alpha_stt(inst,ALPHA_FA5,ALPHA_SP,12*8); + /* Force any pending hardware exceptions to be raised. (1 instruction) */ + alpha_trapb(inst); - /* Call the redirector handling function */ + /* Call the redirector handling function (1 instruction) */ alpha_call(inst, func); - /* Restore the return address */ - alpha_ldq(inst,ALPHA_RA,ALPHA_SP,0*8); - - /* Restore integer register arguments */ - alpha_ldq(inst,ALPHA_A0,ALPHA_SP,1*8); - alpha_ldq(inst,ALPHA_A1,ALPHA_SP,2*8); - alpha_ldq(inst,ALPHA_A2,ALPHA_SP,3*8); - alpha_ldq(inst,ALPHA_A3,ALPHA_SP,4*8); - alpha_ldq(inst,ALPHA_A4,ALPHA_SP,5*8); - alpha_ldq(inst,ALPHA_A5,ALPHA_SP,6*8); - - /* Restore floating-point register arguments */ - alpha_ldt(inst,ALPHA_FA0,ALPHA_SP, 7*8); - alpha_ldt(inst,ALPHA_FA1,ALPHA_SP, 8*8); - alpha_ldt(inst,ALPHA_FA2,ALPHA_SP, 9*8); - alpha_ldt(inst,ALPHA_FA3,ALPHA_SP,10*8); - alpha_ldt(inst,ALPHA_FA4,ALPHA_SP,11*8); - alpha_ldt(inst,ALPHA_FA5,ALPHA_SP,12*8); - - /* restore the stack pointer */ - alpha_lda(inst,ALPHA_SP,ALPHA_SP,(13*8)); - - /* Set the stack pointer */ - alpha_mov(inst,ALPHA_FP,ALPHA_SP); - /* Restore the return address. (1 instruction) */ alpha_ldq(inst,ALPHA_RA,ALPHA_SP,0*8); @@ -199,7 +152,7 @@ void *_jit_create_redirector(unsigned char *buf, void *func, void *user_data, in /* Force any pending hardware exceptions to be raised. (1 instruction) */ alpha_trapb(inst); - /* Jump to the function that the redirector indicated */ + /* Jump to the function that the redirector indicated (1 instruction) */ alpha_jsr(inst,ALPHA_RA,ALPHA_V0,1); /* Return the start of the buffer as the redirector entry point */ diff --git a/jit/jit-apply-alpha.h b/jit/jit-apply-alpha.h index 01fc109..63d5e4c 100644 --- a/jit/jit-apply-alpha.h +++ b/jit/jit-apply-alpha.h @@ -25,14 +25,14 @@ * The maximum number of bytes that are needed to represent a closure, * and the alignment to use for the closure. */ -#define jit_closure_size (32 /* instructions */ * 4 /* bytes per instruction */) +#define jit_closure_size (35 /* instructions */ * 4 /* bytes per instruction */) #define jit_closure_align 32 /* * The number of bytes that are needed for a redirector stub. * This includes any extra bytes that are needed for alignment. */ -#define jit_redirector_size (100 /* instructions */ * 4 /* bytes per instruction */) +#define jit_redirector_size (41 /* instructions */ * 4 /* bytes per instruction */) /* * We should pad unused code space with NOP's. diff --git a/jit/jit-gen-alpha.h b/jit/jit-gen-alpha.h index f32511e..3662b16 100644 --- a/jit/jit-gen-alpha.h +++ b/jit/jit-gen-alpha.h @@ -500,6 +500,19 @@ void jump_to_epilog(jit_gencode_t, alpha_inst, jit_block_t); #define alpha_subqv(inst,sreg0,sreg1,dreg) alpha_encode_regops(inst,ALPHA_OP_SUBQV,ALPHA_FUNC_SUBQV,sreg0,sreg1,dreg) #define alpha_cmple(inst,sreg0,sreg1,dreg) alpha_encode_regops(inst,ALPHA_OP_CMPLE,ALPHA_FUNC_CMPLE,sreg0,sreg1,dreg) +/* + * pseudo comparison operations + * + * Alpha doesn't have all possible comparison opcodes. For example, we + * have cmple for A <= B, but no cmpge for A >= B. So we make cmpge by + * using cmple with the operands switched. Example, A >= B becomes B <= A + */ +#define alpha_cmpble(inst,sreg0,sreg1,dreg) alpha_encode_regops(inst,ALPHA_OP_CMPBGE,ALPHA_FUNC_CMPBGE,sreg1,sreg0,dreg) +#define alpha_cmpugt(inst,sreg0,sreg1,dreg) alpha_encode_regops(inst,ALPHA_OP_CMPULT,ALPHA_FUNC_CMPULT,sreg1,sreg0,dreg) +#define alpha_cmpuge(inst,sreg0,sreg1,dreg) alpha_encode_regops(inst,ALPHA_OP_CMPULE,ALPHA_FUNC_CMPULE,sreg1,sreg0,dreg) +#define alpha_cmpgt(inst,sreg0,sreg1,dreg) alpha_encode_regops(inst,ALPHA_OP_CMPLT,ALPHA_FUNC_CMPLT,sreg1,sreg0,dreg) +#define alpha_cmpge(inst,sreg0,sreg1,dreg) alpha_encode_regops(inst,ALPHA_OP_CMPLE,ALPHA_FUNC_CMPLE,sreg1,sreg0,dreg) + /* bitwise / move operations */ #define alpha_and(inst,sreg0,sreg1,dreg) alpha_encode_regops(inst,ALPHA_OP_AND,ALPHA_FUNC_AND,sreg0,sreg1,dreg) #define alpha_bic(inst,sreg0,sreg1,dreg) alpha_encode_regops(inst,ALPHA_OP_BIC,ALPHA_FUNC_BIC,sreg0,sreg1,dreg) diff --git a/jit/jit-rules-alpha.c b/jit/jit-rules-alpha.c index c4b621f..1d77464 100644 --- a/jit/jit-rules-alpha.c +++ b/jit/jit-rules-alpha.c @@ -147,7 +147,7 @@ void *_jit_gen_prolog(jit_gencode_t gen, jit_function_t func, void *buf) { alpha_lda( inst,ALPHA_GP,ALPHA_GP,0); /* Allocate space for a new stack frame. (1 instruction) */ - alpha_lda(inst,ALPHA_SP,ALPHA_SP,-(16*8)); + alpha_lda(inst,ALPHA_SP,ALPHA_SP,-(2*8)); /* Save the return address. (1 instruction) */ alpha_stq(inst,ALPHA_RA,ALPHA_SP,0*8); @@ -155,24 +155,6 @@ void *_jit_gen_prolog(jit_gencode_t gen, jit_function_t func, void *buf) { /* Save the frame pointer. (1 instruction) */ alpha_stq(inst,ALPHA_FP,ALPHA_SP,1*8); - /* Save the integer save registers (6 instructions) */ - alpha_stq(inst,ALPHA_S0,ALPHA_SP,2*8); - alpha_stq(inst,ALPHA_S1,ALPHA_SP,3*8); - alpha_stq(inst,ALPHA_S2,ALPHA_SP,4*8); - alpha_stq(inst,ALPHA_S3,ALPHA_SP,5*8); - alpha_stq(inst,ALPHA_S4,ALPHA_SP,6*8); - alpha_stq(inst,ALPHA_S5,ALPHA_SP,7*8); - - /* Save the floating point save registers (8 instructions) */ - alpha_stt(inst,ALPHA_FS0,ALPHA_SP, 8*8); - alpha_stt(inst,ALPHA_FS1,ALPHA_SP, 9*8); - alpha_stt(inst,ALPHA_FS2,ALPHA_SP,10*8); - alpha_stt(inst,ALPHA_FS3,ALPHA_SP,11*8); - alpha_stt(inst,ALPHA_FS4,ALPHA_SP,12*8); - alpha_stt(inst,ALPHA_FS5,ALPHA_SP,13*8); - alpha_stt(inst,ALPHA_FS6,ALPHA_SP,14*8); - alpha_stt(inst,ALPHA_FS7,ALPHA_SP,15*8); - /* Set the frame pointer (1 instruction) */ alpha_mov(inst,ALPHA_SP,ALPHA_FP); @@ -219,24 +201,6 @@ void _jit_gen_epilog(jit_gencode_t gen, jit_function_t func) { /* Restore the frame pointer. (1 instruction) */ alpha_ldq(inst,ALPHA_FP,ALPHA_SP,1*8); - /* Restore the integer save registers (6 instructions) */ - alpha_ldq(inst,ALPHA_S0,ALPHA_SP,2*8); - alpha_ldq(inst,ALPHA_S1,ALPHA_SP,3*8); - alpha_ldq(inst,ALPHA_S2,ALPHA_SP,4*8); - alpha_ldq(inst,ALPHA_S3,ALPHA_SP,5*8); - alpha_ldq(inst,ALPHA_S4,ALPHA_SP,6*8); - alpha_ldq(inst,ALPHA_S5,ALPHA_SP,7*8); - - /* Restore the floating point save registers (8 instructions) */ - alpha_ldt(inst,ALPHA_FS0,ALPHA_SP, 8*8); - alpha_ldt(inst,ALPHA_FS1,ALPHA_SP, 9*8); - alpha_ldt(inst,ALPHA_FS2,ALPHA_SP,10*8); - alpha_ldt(inst,ALPHA_FS3,ALPHA_SP,11*8); - alpha_ldt(inst,ALPHA_FS4,ALPHA_SP,12*8); - alpha_ldt(inst,ALPHA_FS5,ALPHA_SP,13*8); - alpha_ldt(inst,ALPHA_FS6,ALPHA_SP,14*8); - alpha_ldt(inst,ALPHA_FS7,ALPHA_SP,15*8); - /* Restore the stack pointer (1 instruction) */ alpha_lda(inst,ALPHA_SP,ALPHA_SP,16*8); diff --git a/jit/jit-rules-alpha.h b/jit/jit-rules-alpha.h index adb8e03..9f6c978 100644 --- a/jit/jit-rules-alpha.h +++ b/jit/jit-rules-alpha.h @@ -153,7 +153,7 @@ extern "C" { * The maximum number of bytes to allocate for the prolog. * This may be shortened once we know the true prolog size. */ -#define JIT_PROLOG_SIZE (21 /* instructions */ * 4 /* bytes per instruction */) +#define JIT_PROLOG_SIZE (7 /* instructions */ * 4 /* bytes per instruction */) /* * Preferred alignment for the start of functions. diff --git a/jit/jit-rules-alpha.ins b/jit/jit-rules-alpha.ins index 62b40e0..fc7e911 100644 --- a/jit/jit-rules-alpha.ins +++ b/jit/jit-rules-alpha.ins @@ -307,9 +307,41 @@ JIT_OP_BR_ILE_UN: binary_branch alpha_output_branch(func, inst, ALPHA_OP_BEQ, insn, ALPHA_AT); } +JIT_OP_BR_IGT: + [reg, reg] -> { + /* $1 <= $2 -> $at */ + alpha_cmpgt(inst, $1, $2, ALPHA_AT); + + /* branch if $at == 1 */ + alpha_output_branch(func, inst, ALPHA_OP_BEQ, insn, ALPHA_AT); + } + +JIT_OP_BR_IGT_UN: + [reg, reg] -> { + /* $1 > $2 -> $at */ + alpha_cmpugt(inst, $1, $2, ALPHA_AT); + + /* branch if $at == 1 */ + alpha_output_branch(func, inst, ALPHA_OP_BEQ, insn, ALPHA_AT); + } -/* TODO: JIT_OP_BR_IGT JIT_OP_BR_IGT_UN */ -/* TODO: JIT_OP_BR_IGE JIT_OP_BR_IGE_UN */ +JIT_OP_BR_IGE: + [reg, reg] -> { + /* $1 >= $2 -> $at */ + alpha_cmpge(inst, $1, $2, ALPHA_AT); + + /* branch if $at == 1 */ + alpha_output_branch(func, inst, ALPHA_OP_BEQ, insn, ALPHA_AT); + } + +JIT_OP_BR_IGE_UN: + [reg, reg] -> { + /* $1 >= $2 -> $at */ + alpha_cmpuge(inst, $1, $2, ALPHA_AT); + + /* branch if $at == 1 */ + alpha_output_branch(func, inst, ALPHA_OP_BEQ, insn, ALPHA_AT); + } /* -- 2.47.3