lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Lightning] Re: I need your help :-(


From: Paolo Bonzini
Subject: [Lightning] Re: I need your help :-(
Date: Mon, 16 Jun 2008 07:57:48 +0200
User-agent: Thunderbird 2.0.0.14 (Macintosh/20080421)


I'm still too fresh on the low-level instruction encoding to fix that though. (Getting rid of the use of R11 as a temp for the callee address).

This is a way to go, however what about the attached patch instead, or something similar.

Since now we use R12 and R13 for V1 and V2, we can use RSI and RDI for the arguments directly. Only the third and fourth argument have to be saved in R8D/R9D until the call (and shifted to RDX/RCX just before). The patch supports 6 arguments only, but it wouldn't be hard to spill to the stack early.

I figured that we ought to add a macro similar to:
#define CALLQsr(R) (_REXQrr(0, R), _O_Mrm (0xff ,_b11,_b010,_r8(R) ))

This would be "call *(imm)", i.e. an indirect call. I'll check what binutils produce so that we can replicate that in lightning.

Paolo

diff --git a/lightning/i386/core-64.h b/lightning/i386/core-64.h
index e19789b..9b036cd 100644
--- a/lightning/i386/core-64.h
+++ b/lightning/i386/core-64.h
@@ -36,8 +36,7 @@
 
 /* Used to implement ldc, stc, ... */
 #define JIT_CAN_16 0
-#define JIT_CALLTMPSTART 0x48
-#define JIT_REXTMP       0x4B
+#define JIT_REXTMP             _R11D
 
 #define JIT_V_NUM               3
 #define JIT_V(i)                ((i) == 0 ? _EBX : _R11D + (i))
@@ -127,25 +126,20 @@ struct jit_local_state {
 /* Stack isn't used for arguments: */
 #define jit_prepare_i(ni)      (_jitl.argssize = 0)
 
-#define jit_pusharg_i(rs)      (_jitl.argssize++, MOVQrr(rs, JIT_CALLTMPSTART 
+ _jitl.argssize - 1))
-#define jit_finish(sub)         (MOVQir((long) (sub), JIT_REXTMP), \
-                                jit_shift_args(), \
+#define jit_pusharg_i(rs)      (_jitl.argssize++, MOVQrr(rs, 
jit_arg_reg_temp[_jitl.argssize - 1]))
+#define jit_finish(sub)         (jit_shift_args(), \
+                                MOVQir((long) (sub), JIT_REXTMP), \
                                 CALLsr(JIT_REXTMP))
-#define jit_reg_is_arg(reg)     ((reg == _EDI) || (reg ==_ESI) || (reg == 
_EDX))
+#define jit_reg_is_arg(reg)     ((reg) == _ECX || (reg) == _EDX)
 #define jit_finishr(reg)       ((jit_reg_is_arg((reg)) ? MOVQrr(reg, 
JIT_REXTMP) : (void)0), \
                                  jit_shift_args(), \
                                  CALLsr(jit_reg_is_arg((reg)) ? JIT_REXTMP : 
(reg)))
 
 #define jit_shift_args() \
-   (_jitl.argssize--  \
-    ? ((void)MOVQrr(JIT_CALLTMPSTART + _jitl.argssize, jit_arg_reg_order[0]), \
-       (_jitl.argssize--  \
-        ? ((void)MOVQrr(JIT_CALLTMPSTART + _jitl.argssize, 
jit_arg_reg_order[1]), \
-           (_jitl.argssize--  \
-            ? (void)MOVQrr(JIT_CALLTMPSTART, jit_arg_reg_order[2])      \
-            : (void)0)) \
-        : (void)0)) \
-    : (void)0)
+   ((_jitl.argssize >= 2 \ ? (void) (MOVQrr(_R8D, _RDX)) : (void) 0), \
+    (_jitl.argssize >= 3 \ ? (void) (MOVQrr(_R9D, _RCX)) : (void) 0), \
+    (_jitl.argssize >= 4 \ ? (void) (PUSHQr(_R10D)) : (void) 0), \
+    (_jitl.argssize >= 5 \ ? (void) (PUSHQr(_R11D)) : (void) 0))
 
 #define jit_retval_l(rd)       ((void)jit_movr_l ((rd), _EAX))
 #define        jit_arg_c()             
(jit_arg_reg_order[_jitl.nextarg_geti++])
@@ -158,6 +152,8 @@ struct jit_local_state {
 #define        jit_arg_ul()            
(jit_arg_reg_order[_jitl.nextarg_geti++])
 #define        jit_arg_p()             
(jit_arg_reg_order[_jitl.nextarg_geti++])
 #define        jit_arg_up()            
(jit_arg_reg_order[_jitl.nextarg_geti++])
+
+static int jit_arg_reg_temp[] = { _EDI, _ESI, _R8D, _R9D, _R10D, _R11D };
 static int jit_arg_reg_order[] = { _EDI, _ESI, _EDX, _ECX };
 
 #define jit_negr_l(d, rs)      jit_opi_((d), (rs), NEGQr(d), (XORQrr((d), 
(d)), SUBQrr((rs), (d))) )

reply via email to

[Prev in Thread] Current Thread [Next in Thread]