Eliminate InfoVars::hp (bug 5844 part 8, r=ds).
authorDavid Anderson <dvander@alliedmods.net>
Mon Aug 12 00:23:00 2013 +0100 (2013-08-12)
changeset 3991a93a52306572
parent 3990 c7fb79059d7a
child 3992 f1e8cad30a64
Eliminate InfoVars::hp (bug 5844 part 8, r=ds).
sourcepawn/jit/x86/jit_x86.cpp
sourcepawn/jit/x86/jit_x86.h
     1.1 --- a/sourcepawn/jit/x86/jit_x86.cpp	Mon Aug 12 00:22:54 2013 +0100
     1.2 +++ b/sourcepawn/jit/x86/jit_x86.cpp	Mon Aug 12 00:23:00 2013 +0100
     1.3 @@ -166,9 +166,10 @@
     1.4  }
     1.5  
     1.6  static int
     1.7 -PopTrackerAndSetHeap(BaseRuntime *rt, InfoVars &vars)
     1.8 +PopTrackerAndSetHeap(BaseRuntime *rt)
     1.9  {
    1.10 -  tracker_t *trk = (tracker_t *)(rt->GetBaseContext()->GetCtx()->vm[JITVARS_TRACKER]);
    1.11 +  sp_context_t *ctx = rt->GetBaseContext()->GetCtx();
    1.12 +  tracker_t *trk = (tracker_t *)(ctx->vm[JITVARS_TRACKER]);
    1.13    assert(trk->pCur > trk->pBase);
    1.14  
    1.15    trk->pCur--;
    1.16 @@ -176,10 +177,10 @@
    1.17      return SP_ERROR_TRACKER_BOUNDS;
    1.18  
    1.19    ucell_t amt = *trk->pCur;
    1.20 -  if (amt > (vars.hp - rt->plugin()->data_size))
    1.21 +  if (amt > (ctx->hp - rt->plugin()->data_size))
    1.22      return SP_ERROR_HEAPMIN;
    1.23  
    1.24 -  vars.hp -= amt;
    1.25 +  ctx->hp -= amt;
    1.26    return SP_ERROR_NONE;
    1.27  }
    1.28  
    1.29 @@ -209,6 +210,8 @@
    1.30  static int
    1.31  GenerateArray(BaseRuntime *rt, InfoVars &vars, uint32_t argc, cell_t *argv, int autozero)
    1.32  {
    1.33 +  sp_context_t *ctx = rt->GetBaseContext()->GetCtx();
    1.34 +
    1.35    // Calculate how many cells are needed.
    1.36    if (argv[0] <= 0)
    1.37      return SP_ERROR_ARRAY_TOO_BIG;
    1.38 @@ -232,10 +235,10 @@
    1.39      return SP_ERROR_ARRAY_TOO_BIG;
    1.40  
    1.41    uint32_t bytes = cells * 4;
    1.42 -  if (!ke::IsUint32AddSafe(vars.hp, bytes))
    1.43 +  if (!ke::IsUint32AddSafe(ctx->hp, bytes))
    1.44      return SP_ERROR_ARRAY_TOO_BIG;
    1.45  
    1.46 -  uint32_t new_hp = vars.hp + bytes;
    1.47 +  uint32_t new_hp = ctx->hp + bytes;
    1.48    cell_t *dat_hp = reinterpret_cast<cell_t *>(rt->plugin()->memory + new_hp);
    1.49  
    1.50    // argv, coincidentally, is STK.
    1.51 @@ -245,12 +248,12 @@
    1.52    if (int err = PushTracker(rt->GetBaseContext()->GetCtx(), bytes))
    1.53      return err;
    1.54  
    1.55 -  cell_t *base = reinterpret_cast<cell_t *>(rt->plugin()->memory + vars.hp);
    1.56 +  cell_t *base = reinterpret_cast<cell_t *>(rt->plugin()->memory + ctx->hp);
    1.57    cell_t offs = GenerateArrayIndirectionVectors(base, argv, argc, autozero);
    1.58    assert(size_t(offs) == cells);
    1.59  
    1.60 -  argv[argc - 1] = vars.hp;
    1.61 -  vars.hp = new_hp;
    1.62 +  argv[argc - 1] = ctx->hp;
    1.63 +  ctx->hp = new_hp;
    1.64    return SP_ERROR_NONE;
    1.65  }
    1.66  
    1.67 @@ -1194,7 +1197,7 @@
    1.68         __ j(not_below, &error_stack_min_);
    1.69       } else {
    1.70         // Check if the stack is going to collide with the heap.
    1.71 -       __ movl(tmp, Operand(info, AMX_INFO_HEAP));
    1.72 +       __ movl(tmp, Operand(hpAddr()));
    1.73         __ lea(tmp, Operand(dat, ecx, NoScale, STACK_MARGIN));
    1.74         __ cmpl(stk, tmp);
    1.75         __ j(below, &error_stack_low_);
    1.76 @@ -1205,14 +1208,14 @@
    1.77      case OP_HEAP:
    1.78      {
    1.79        cell_t amount = readCell();
    1.80 -      __ movl(alt, Operand(info, AMX_INFO_HEAP));
    1.81 -      __ addl(Operand(info, AMX_INFO_HEAP), amount);
    1.82 +      __ movl(alt, Operand(hpAddr()));
    1.83 +      __ addl(Operand(hpAddr()), amount);
    1.84  
    1.85        if (amount > 0) {
    1.86 -        __ cmpl(Operand(info, AMX_INFO_HEAP), plugin_->data_size);
    1.87 +        __ cmpl(Operand(hpAddr()), plugin_->data_size);
    1.88          __ j(below, &error_heap_min_);
    1.89        } else {
    1.90 -        __ movl(tmp, Operand(info, AMX_INFO_HEAP));
    1.91 +        __ movl(tmp, Operand(hpAddr()));
    1.92          __ lea(tmp, Operand(dat, ecx, NoScale, STACK_MARGIN));
    1.93          __ cmpl(tmp, stk);
    1.94          __ j(above, &error_heap_low_);
    1.95 @@ -1283,10 +1286,9 @@
    1.96        __ push(alt);
    1.97  
    1.98        // Get the context pointer and call the sanity checker.
    1.99 -      __ push(info);
   1.100        __ push(intptr_t(rt_));
   1.101        __ call(ExternalAddress((void *)PopTrackerAndSetHeap));
   1.102 -      __ addl(esp, 8);
   1.103 +      __ addl(esp, 4);
   1.104        __ testl(eax, eax);
   1.105        __ j(not_zero, &extern_error_);
   1.106  
   1.107 @@ -1386,7 +1388,7 @@
   1.108  
   1.109    // Check if we're in the invalid region between hp and sp.
   1.110    Label done;
   1.111 -  __ cmpl(reg, Operand(info, AMX_INFO_HEAP));
   1.112 +  __ cmpl(reg, Operand(hpAddr()));
   1.113    __ j(below, &done);
   1.114    __ lea(tmp, Operand(dat, reg, NoScale));
   1.115    __ cmpl(tmp, stk);
   1.116 @@ -1402,11 +1404,11 @@
   1.117    {
   1.118      // flat array; we can generate this without indirection tables.
   1.119      // Note that we can overwrite ALT because technically STACK should be destroying ALT
   1.120 -    __ movl(alt, Operand(info, AMX_INFO_HEAP));
   1.121 +    __ movl(alt, Operand(hpAddr()));
   1.122      __ movl(tmp, Operand(stk, 0));
   1.123      __ movl(Operand(stk, 0), alt);    // store base of the array into the stack.
   1.124      __ lea(alt, Operand(alt, tmp, ScaleFour));
   1.125 -    __ movl(Operand(info, AMX_INFO_HEAP), alt);
   1.126 +    __ movl(Operand(hpAddr()), alt);
   1.127      __ addl(alt, dat);
   1.128      __ cmpl(alt, stk);
   1.129      __ j(not_below, &error_heap_low_);
   1.130 @@ -1595,8 +1597,6 @@
   1.131    // Relocate all our absolute junk to be dat-relative, and store it all back
   1.132    // into the context.
   1.133    __ movl(eax, intptr_t(rt_->GetBaseContext()->GetCtx()));
   1.134 -  __ movl(ecx, Operand(info, AMX_INFO_HEAP));
   1.135 -  __ movl(Operand(eax, offsetof(sp_context_t, hp)), ecx);
   1.136    __ subl(stk, dat);
   1.137    __ movl(Operand(eax, offsetof(sp_context_t, sp)), stk);
   1.138    __ movl(ecx, Operand(info, AMX_INFO_FRAME));
   1.139 @@ -1972,18 +1972,17 @@
   1.140  {
   1.141    sp_context_t *ctx = runtime->GetBaseContext()->GetCtx();
   1.142  
   1.143 +  // Note that cip, hp, sp are saved and restored by Execute2().
   1.144    ctx->cip = fn->GetPCodeAddress();
   1.145  
   1.146    InfoVars vars;
   1.147    vars.frm = ctx->sp;
   1.148 -  vars.hp = ctx->hp;
   1.149    /* vars.esp will be set in the entry code */
   1.150  
   1.151    JIT_EXECUTE pfn = (JIT_EXECUTE)m_pJitEntry;
   1.152    int err = pfn(&vars, fn->GetEntryAddress(), runtime->plugin()->memory, ctx);
   1.153  
   1.154    ctx->sp = vars.frm;
   1.155 -  ctx->hp = vars.hp;
   1.156  
   1.157    *result = ctx->rval;
   1.158    return err;
     2.1 --- a/sourcepawn/jit/x86/jit_x86.h	Mon Aug 12 00:22:54 2013 +0100
     2.2 +++ b/sourcepawn/jit/x86/jit_x86.h	Mon Aug 12 00:23:00 2013 +0100
     2.3 @@ -136,6 +136,10 @@
     2.4      sp_context_t *ctx = rt_->GetBaseContext()->GetCtx();
     2.5      return ExternalAddress(&ctx->cip);
     2.6    }
     2.7 +  ExternalAddress hpAddr() {
     2.8 +    sp_context_t *ctx = rt_->GetBaseContext()->GetCtx();
     2.9 +    return ExternalAddress(&ctx->hp);
    2.10 +  }
    2.11  
    2.12   private:
    2.13    AssemblerX86 masm;
    2.14 @@ -202,12 +206,10 @@
    2.15  
    2.16  struct InfoVars {
    2.17      ucell_t frm;
    2.18 -    ucell_t hp;
    2.19      void *esp;
    2.20  };
    2.21  
    2.22  #define AMX_INFO_FRAME          offsetof(InfoVars, frm)
    2.23 -#define AMX_INFO_HEAP           offsetof(InfoVars, hp)
    2.24  #define AMX_INFO_NSTACK         offsetof(InfoVars, esp)
    2.25  
    2.26  extern Knight::KeCodeCache *g_pCodeCache;