FFI: Compile VLA/VLS and large cdata allocs with default initialization.
This commit is contained in:
@@ -1438,15 +1438,13 @@ static void asm_sload(ASMState *as, IRIns *ir)
|
||||
static void asm_cnew(ASMState *as, IRIns *ir)
|
||||
{
|
||||
CTState *cts = ctype_ctsG(J2G(as->J));
|
||||
CTypeID ctypeid = (CTypeID)IR(ir->op1)->i;
|
||||
CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ?
|
||||
lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i;
|
||||
CTypeID id = (CTypeID)IR(ir->op1)->i;
|
||||
CTSize sz;
|
||||
CTInfo info = lj_ctype_info(cts, id, &sz);
|
||||
const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
|
||||
IRRef args[2];
|
||||
lua_assert(sz != CTSIZE_INVALID);
|
||||
IRRef args[4];
|
||||
lua_assert(sz != CTSIZE_INVALID || (ir->o == IR_CNEW && ir->op2 != REF_NIL));
|
||||
|
||||
args[0] = ASMREF_L; /* lua_State *L */
|
||||
args[1] = ASMREF_TMP1; /* MSize size */
|
||||
as->gcsteps++;
|
||||
asm_setupresult(as, ir, ci); /* GCcdata * */
|
||||
|
||||
@@ -1489,15 +1487,26 @@ static void asm_cnew(ASMState *as, IRIns *ir)
|
||||
} while (1);
|
||||
#endif
|
||||
lua_assert(sz == 4 || sz == 8);
|
||||
} else if (ir->op2 != REF_NIL) { /* Create VLA/VLS/aligned cdata. */
|
||||
ci = &lj_ir_callinfo[IRCALL_lj_cdata_newv];
|
||||
args[0] = ASMREF_L; /* lua_State *L */
|
||||
args[1] = ir->op1; /* CTypeID id */
|
||||
args[2] = ir->op2; /* CTSize sz */
|
||||
args[3] = ASMREF_TMP1; /* CTSize align */
|
||||
asm_gencall(as, ci, args);
|
||||
emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)ctype_align(info));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Combine initialization of marked, gct and ctypeid. */
|
||||
emit_movtomro(as, RID_ECX, RID_RET, offsetof(GCcdata, marked));
|
||||
emit_gri(as, XG_ARITHi(XOg_OR), RID_ECX,
|
||||
(int32_t)((~LJ_TCDATA<<8)+(ctypeid<<16)));
|
||||
(int32_t)((~LJ_TCDATA<<8)+(id<<16)));
|
||||
emit_gri(as, XG_ARITHi(XOg_AND), RID_ECX, LJ_GC_WHITES);
|
||||
emit_opgl(as, XO_MOVZXb, RID_ECX, gc.currentwhite);
|
||||
|
||||
args[0] = ASMREF_L; /* lua_State *L */
|
||||
args[1] = ASMREF_TMP1; /* MSize size */
|
||||
asm_gencall(as, ci, args);
|
||||
emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)(sz+sizeof(GCcdata)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user