Eliminate InfoVars::rval (bug 5844 part 6, r=ds).
authorDavid Anderson <dvander@alliedmods.net>
Mon Aug 12 00:22:41 2013 +0100 (2013-08-12)
changeset 3989b73dae36a0da
parent 3988 f947f2955ae0
child 3990 c7fb79059d7a
Eliminate InfoVars::rval (bug 5844 part 6, r=ds).
sourcepawn/jit/jit_shared.h
sourcepawn/jit/opcodes.cpp
sourcepawn/jit/x86/jit_x86.cpp
sourcepawn/jit/x86/jit_x86.h
     1.1 --- a/sourcepawn/jit/jit_shared.h	Sun Aug 11 11:33:47 2013 -0700
     1.2 +++ b/sourcepawn/jit/jit_shared.h	Mon Aug 12 00:22:41 2013 +0100
     1.3 @@ -1,3 +1,4 @@
     1.4 +// vim: set ts=4 sw=4 tw=99 noet: 
     1.5  #ifndef _INCLUDE_SOURCEPAWN_JIT_SHARED_H_
     1.6  #define _INCLUDE_SOURCEPAWN_JIT_SHARED_H_
     1.7  
     1.8 @@ -71,6 +72,7 @@
     1.9  	cell_t			hp;				/**< Heap pointer */
    1.10  	cell_t			sp;				/**< Stack pointer */
    1.11  	cell_t			frm;			/**< Frame pointer */
    1.12 +	cell_t			rval;			/**< Return value from InvokeFunction() */
    1.13  	int32_t			err_cip;		/**< Code pointer last error occurred in */
    1.14  	int32_t			n_err;			/**< Error code set by a native */
    1.15  	uint32_t		n_idx;			/**< Current native index being executed */
     2.1 --- a/sourcepawn/jit/opcodes.cpp	Sun Aug 11 11:33:47 2013 -0700
     2.2 +++ b/sourcepawn/jit/opcodes.cpp	Mon Aug 12 00:22:41 2013 +0100
     2.3 @@ -70,6 +70,8 @@
     2.4      case OP_HEAP:
     2.5      case OP_GENARRAY:
     2.6      case OP_GENARRAY_Z:
     2.7 +    case OP_CONST_PRI:
     2.8 +    case OP_CONST_ALT:
     2.9        fprintf(stdout, "%d", cip[1]);
    2.10        break;
    2.11  
     3.1 --- a/sourcepawn/jit/x86/jit_x86.cpp	Sun Aug 11 11:33:47 2013 -0700
     3.2 +++ b/sourcepawn/jit/x86/jit_x86.cpp	Mon Aug 12 00:22:41 2013 +0100
     3.3 @@ -1304,8 +1304,8 @@
     3.4  
     3.5      case OP_HALT:
     3.6        __ align(16);
     3.7 -      __ movl(tmp, Operand(info, AMX_INFO_RETVAL));
     3.8 -      __ movl(Operand(ecx, 0), pri);
     3.9 +      __ movl(tmp, intptr_t(rt_->GetBaseContext()->GetCtx()));
    3.10 +      __ movl(Operand(tmp, offsetof(sp_context_t, rval)), pri);
    3.11        __ movl(pri, readCell());
    3.12        __ jmp(&extern_error_);
    3.13        break;
    3.14 @@ -1755,13 +1755,15 @@
    3.15    }
    3.16  }
    3.17  
    3.18 +typedef int (*JIT_EXECUTE)(InfoVars *vars, void *addr, uint8_t *memory, sp_context_t *ctx);
    3.19 +
    3.20  static void *
    3.21  GenerateEntry(void **retp)
    3.22  {
    3.23    AssemblerX86 masm;
    3.24  
    3.25    // Variables we're passed in:
    3.26 -  //  InfoVars *vars, void *entry, uint8_t *memory
    3.27 +  //  InfoVars *vars, void *entry, uint8_t *memory, sp_context_t *
    3.28  
    3.29    __ push(ebp);
    3.30    __ movl(ebp, esp);
    3.31 @@ -1787,23 +1789,36 @@
    3.32    // Call into plugin (align the stack first).
    3.33    __ call(ecx);
    3.34  
    3.35 -  __ movl(ecx, Operand(info, AMX_INFO_RETVAL));
    3.36 -  __ movl(Operand(ecx, 0), pri);
    3.37 +  // Restore stack.
    3.38 +  __ movl(esp, Operand(info, AMX_INFO_NSTACK));
    3.39 +
    3.40 +  // Get input context.
    3.41 +  __ movl(ecx, Operand(esp, 32));
    3.42 +  __ movl(Operand(ecx, offsetof(sp_context_t, rval)), pri);
    3.43 +
    3.44 +  // Set no error.
    3.45    __ movl(eax, SP_ERROR_NONE);
    3.46  
    3.47 -  // If stuff goes wrong, it'll jump directly to here.
    3.48 -  Label error;
    3.49 -  __ bind(&error);
    3.50 -  __ movl(esp, Operand(info, AMX_INFO_NSTACK));
    3.51 +  // Store latest stk. If we have an error code, we'll jump directly to here,
    3.52 +  // so eax will already be set.
    3.53 +  Label ret;
    3.54 +  __ bind(&ret);
    3.55    __ subl(stk, dat);
    3.56    __ movl(Operand(esi, AMX_INFO_FRAME), stk);
    3.57  
    3.58 +  // Restore registers and gtfo.
    3.59    __ pop(ebx);
    3.60    __ pop(edi);
    3.61    __ pop(esi);
    3.62    __ pop(ebp);
    3.63    __ ret();
    3.64  
    3.65 +  // The universal emergency return will jump to here.
    3.66 +  Label error;
    3.67 +  __ bind(&error);
    3.68 +  __ movl(esp, Operand(info, AMX_INFO_NSTACK));
    3.69 +  __ jmp(&ret);
    3.70 +
    3.71    void *code = LinkCode(masm);
    3.72    if (!code)
    3.73      return NULL;
    3.74 @@ -1953,29 +1968,24 @@
    3.75    return false;
    3.76  }
    3.77  
    3.78 -typedef int (*JIT_EXECUTE)(InfoVars *vars, void *addr, uint8_t *memory);
    3.79  int JITX86::InvokeFunction(BaseRuntime *runtime, JitFunction *fn, cell_t *result)
    3.80  {
    3.81 -  int err;
    3.82 -  JIT_EXECUTE pfn;
    3.83 -  sp_context_t *ctx;
    3.84 +  sp_context_t *ctx = runtime->GetBaseContext()->GetCtx();
    3.85 +
    3.86    InfoVars vars;
    3.87 -
    3.88 -  ctx = runtime->GetBaseContext()->GetCtx();
    3.89 -
    3.90    vars.frm = ctx->sp;
    3.91    vars.hp = ctx->hp;
    3.92 -  vars.rval = result;
    3.93    vars.cip = fn->GetPCodeAddress();
    3.94    /* vars.esp will be set in the entry code */
    3.95  
    3.96 -  pfn = (JIT_EXECUTE)m_pJitEntry;
    3.97 -  err = pfn(&vars, fn->GetEntryAddress(), runtime->plugin()->memory);
    3.98 +  JIT_EXECUTE pfn = (JIT_EXECUTE)m_pJitEntry;
    3.99 +  int err = pfn(&vars, fn->GetEntryAddress(), runtime->plugin()->memory, ctx);
   3.100  
   3.101    ctx->sp = vars.frm;
   3.102    ctx->hp = vars.hp;
   3.103    ctx->err_cip = vars.cip;
   3.104  
   3.105 +  *result = ctx->rval;
   3.106    return err;
   3.107  }
   3.108  
     4.1 --- a/sourcepawn/jit/x86/jit_x86.h	Sun Aug 11 11:33:47 2013 -0700
     4.2 +++ b/sourcepawn/jit/x86/jit_x86.h	Mon Aug 12 00:22:41 2013 +0100
     4.3 @@ -197,14 +197,12 @@
     4.4  struct InfoVars {
     4.5      ucell_t frm;
     4.6      ucell_t hp;
     4.7 -    cell_t *rval;
     4.8      ucell_t cip;
     4.9      void *esp;
    4.10  };
    4.11  
    4.12  #define AMX_INFO_FRAME          offsetof(InfoVars, frm)
    4.13  #define AMX_INFO_HEAP           offsetof(InfoVars, hp)
    4.14 -#define AMX_INFO_RETVAL         offsetof(InfoVars, rval)
    4.15  #define AMX_INFO_CIP            offsetof(InfoVars, cip)
    4.16  #define AMX_INFO_NSTACK         offsetof(InfoVars, esp)
    4.17