Replace GCproto reference with bytecode PC in GCfuncL.

This commit is contained in:
Mike Pall 2010-02-10 21:45:57 +01:00
parent d5a46621f9
commit bb0384c366
3 changed files with 32 additions and 30 deletions

View File

@ -305,6 +305,8 @@
#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) #define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) #define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
| |
#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
|
|// Decrement hashed hotcount and trigger trace recorder if zero. |// Decrement hashed hotcount and trigger trace recorder if zero.
|.macro hotloop, reg |.macro hotloop, reg
| mov reg, PC | mov reg, PC
@ -406,11 +408,10 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| // RA = new base, RB = LFUNC, RC = nargs+1, (BASE = old base), PC = return | // RA = new base, RB = LFUNC, RC = nargs+1, (BASE = old base), PC = return
| // DISPATCH initialized | // DISPATCH initialized
| mov BASE, RA | mov BASE, RA
| mov PROTO:RB, LFUNC:RB->pt
| mov [BASE-4], PC // Store caller PC. | mov [BASE-4], PC // Store caller PC.
| movzx RA, byte PROTO:RB->framesize | mov PC, LFUNC:RB->pc
| lea PC, [PROTO:RB+sizeof(GCproto)] | movzx RA, byte [PC+PC2PROTO(framesize)]
| mov KBASE, PROTO:RB->k | mov KBASE, [PC+PC2PROTO(k)]
| mov L:RB, SAVE_L | mov L:RB, SAVE_L
| lea RA, [BASE+RA*8] // Top of frame. | lea RA, [BASE+RA*8] // Top of frame.
| lea RC, [BASE+NARGS:RC*8-4] // Points to tag of 1st free slot. | lea RC, [BASE+NARGS:RC*8-4] // Points to tag of 1st free slot.
@ -437,16 +438,16 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| lea PC, [NARGS:RC*8+FRAME_VARG] | lea PC, [NARGS:RC*8+FRAME_VARG]
| lea BASE, [RA+PC-FRAME_VARG] | lea BASE, [RA+PC-FRAME_VARG]
| mov [BASE-8], LFUNC:RB // Store copy of LFUNC. | mov [BASE-8], LFUNC:RB // Store copy of LFUNC.
| mov PROTO:RB, LFUNC:RB->pt
| mov [BASE-4], PC // Store delta + FRAME_VARG. | mov [BASE-4], PC // Store delta + FRAME_VARG.
| movzx PC, byte PROTO:RB->framesize | mov PC, LFUNC:RB->pc
| lea KBASE, [BASE+PC*8] | movzx RB, byte [PC+PC2PROTO(framesize)]
| mov L:PC, SAVE_L | lea KBASE, [BASE+RB*8]
| mov L:RB, SAVE_L
| lea RC, [BASE+4] | lea RC, [BASE+4]
| cmp KBASE, L:PC->maxstack | cmp KBASE, L:RB->maxstack
| ja ->gate_lv_growstack // Need to grow stack. | ja ->gate_lv_growstack // Need to grow stack.
| movzx PC, byte PROTO:RB->numparams | movzx RB, byte [PC+PC2PROTO(numparams)]
| test PC, PC | test RB, RB
| jz >2 | jz >2
|1: // Copy fixarg slots up. |1: // Copy fixarg slots up.
| add RA, 8 | add RA, 8
@ -458,12 +459,11 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| mov [RC], KBASE | mov [RC], KBASE
| add RC, 8 | add RC, 8
| mov dword [RA-4], LJ_TNIL // Clear old fixarg slot (help the GC). | mov dword [RA-4], LJ_TNIL // Clear old fixarg slot (help the GC).
| sub PC, 1 | sub RB, 1
| jnz <1 | jnz <1
|2: |2:
| movzx RA, byte PROTO:RB->framesize | movzx RA, byte [PC+PC2PROTO(framesize)]
| lea PC, [PROTO:RB+sizeof(GCproto)] | mov KBASE, [PC+PC2PROTO(k)]
| mov KBASE, PROTO:RB->k
| lea RA, [BASE+RA*8] | lea RA, [BASE+RA*8]
| jmp <9 | jmp <9
| |
@ -663,6 +663,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| jmp >1 | jmp >1
| |
|->gate_lv_growstack: // Grow stack for vararg Lua function. |->gate_lv_growstack: // Grow stack for vararg Lua function.
//XXX
| sub RC, 8 | sub RC, 8
| mov BASE, RA | mov BASE, RA
| mov RA, KBASE | mov RA, KBASE
@ -863,8 +864,8 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
| mov RA, dword [RB-16] | mov RA, dword [RB-16]
|.endif |.endif
| mov LFUNC:KBASE, [BASE-8] | mov LFUNC:KBASE, [BASE-8]
| mov PROTO:KBASE, LFUNC:KBASE->pt | mov KBASE, LFUNC:KBASE->pc
| mov KBASE, PROTO:KBASE->k | mov KBASE, [KBASE+PC2PROTO(k)]
| // BASE = base, RC = result, RB = meta base | // BASE = base, RC = result, RB = meta base
| jmp RAa // Jump to continuation. | jmp RAa // Jump to continuation.
| |
@ -2719,8 +2720,8 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
|->vm_exit_interp: |->vm_exit_interp:
#if LJ_HASJIT #if LJ_HASJIT
| mov LFUNC:KBASE, [BASE-8] | mov LFUNC:KBASE, [BASE-8]
| mov PROTO:KBASE, LFUNC:KBASE->pt | mov KBASE, LFUNC:KBASE->pc
| mov KBASE, PROTO:KBASE->k | mov KBASE, [KBASE+PC2PROTO(k)]
| mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0 | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0
| set_vmstate INTERP | set_vmstate INTERP
| ins_next | ins_next
@ -4454,8 +4455,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
| not RDa | not RDa
| lea BASE, [BASE+RD*8] | lea BASE, [BASE+RD*8]
| mov LFUNC:KBASE, [BASE-8] | mov LFUNC:KBASE, [BASE-8]
| mov PROTO:KBASE, LFUNC:KBASE->pt | mov KBASE, LFUNC:KBASE->pc
| mov KBASE, PROTO:KBASE->k | mov KBASE, [KBASE+PC2PROTO(k)]
| jmp <4 | jmp <4
| |
|7: // Tailcall from a vararg function. |7: // Tailcall from a vararg function.
@ -4492,8 +4493,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
| ins_AB_ // RA = base, RB = nresults+1, (RC = 1) | ins_AB_ // RA = base, RB = nresults+1, (RC = 1)
| mov LFUNC:RC, [BASE-8] | mov LFUNC:RC, [BASE-8]
| lea RA, [BASE+RA*8] | lea RA, [BASE+RA*8]
| mov PROTO:RC, LFUNC:RC->pt | mov RC, LFUNC:RC->pc
| movzx RC, byte PROTO:RC->numparams | movzx RC, byte [RC+PC2PROTO(numparams)]
| mov TMP1, KBASE // Need one more free register. | mov TMP1, KBASE // Need one more free register.
| lea KBASE, [BASE+RC*8+(8+FRAME_VARG)] | lea KBASE, [BASE+RC*8+(8+FRAME_VARG)]
| sub KBASE, [BASE-4] | sub KBASE, [BASE-4]
@ -4618,8 +4619,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
| not RAa // Note: ~RA = -(RA+1) | not RAa // Note: ~RA = -(RA+1)
| lea BASE, [BASE+RA*8] // base = base - (RA+1)*8 | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8
| mov LFUNC:KBASE, [BASE-8] | mov LFUNC:KBASE, [BASE-8]
| mov PROTO:KBASE, LFUNC:KBASE->pt | mov KBASE, LFUNC:KBASE->pc
| mov KBASE, PROTO:KBASE->k | mov KBASE, [KBASE+PC2PROTO(k)]
| ins_next | ins_next
| |
|6: // Fill up results with nil. |6: // Fill up results with nil.

View File

@ -112,8 +112,8 @@ GCfunc *lj_func_newL(lua_State *L, GCproto *pt, GCtab *env)
fn->l.gct = ~LJ_TFUNC; fn->l.gct = ~LJ_TFUNC;
fn->l.ffid = FF_LUA; fn->l.ffid = FF_LUA;
fn->l.nupvalues = cast_byte(pt->sizeuv); fn->l.nupvalues = cast_byte(pt->sizeuv);
/* NOBARRIER: The GCfunc is new (marked white). */ /* NOBARRIER: Really a setgcref. But the GCfunc is new (marked white). */
setgcref(fn->l.pt, obj2gco(pt)); setmref(fn->l.pc, proto_bc(pt));
setgcref(fn->l.env, obj2gco(env)); setgcref(fn->l.env, obj2gco(env));
fn->l.gate = (pt->flags & PROTO_IS_VARARG) ? lj_gate_lv : lj_gate_lf; fn->l.gate = (pt->flags & PROTO_IS_VARARG) ? lj_gate_lv : lj_gate_lf;
return fn; return fn;
@ -137,7 +137,7 @@ GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent)
GCupval *uv; GCupval *uv;
if ((v & 0x8000)) { if ((v & 0x8000)) {
uv = func_finduv(L, base + (v & 0xff)); uv = func_finduv(L, base + (v & 0xff));
uv->dhash = (uint32_t)(uintptr_t)gcref(parent->pt) ^ (v << 24); uv->dhash = (uint32_t)(uintptr_t)mref(parent->pc, char) ^ (v << 24);
} else { } else {
uv = &gcref(puv[v])->uv; uv = &gcref(puv[v])->uv;
} }

View File

@ -429,7 +429,7 @@ typedef struct GCfuncC {
typedef struct GCfuncL { typedef struct GCfuncL {
GCfuncHeader; GCfuncHeader;
GCRef pt; /* Link to prototype this function is based on. */ MRef pc; /* Start PC (and GCproto reference). */
GCRef uvptr[1]; /* Array of _pointers_ to upvalue objects (GCupval). */ GCRef uvptr[1]; /* Array of _pointers_ to upvalue objects (GCupval). */
} GCfuncL; } GCfuncL;
@ -443,7 +443,8 @@ typedef union GCfunc {
#define isluafunc(fn) ((fn)->c.ffid == FF_LUA) #define isluafunc(fn) ((fn)->c.ffid == FF_LUA)
#define iscfunc(fn) ((fn)->c.ffid == FF_C) #define iscfunc(fn) ((fn)->c.ffid == FF_C)
#define isffunc(fn) ((fn)->c.ffid > FF_C) #define isffunc(fn) ((fn)->c.ffid > FF_C)
#define funcproto(fn) check_exp(isluafunc(fn), &gcref((fn)->l.pt)->pt) #define funcproto(fn) \
check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto)))
#define sizeCfunc(n) (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n)) #define sizeCfunc(n) (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n))
#define sizeLfunc(n) (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n)) #define sizeLfunc(n) (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n))