From: fennecdjay Date: Thu, 13 Oct 2022 16:13:49 +0000 (+0200) Subject: :art: optimize RegPushMem + Dotmember X-Git-Tag: nightly~216 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=9a97c0308025c8874882f0ce254a25962cc7fd81;p=gwion.git :art: optimize RegPushMem + Dotmember --- diff --git a/include/opcode.h b/include/opcode.h index 812785bf..7daf9908 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -185,6 +185,9 @@ enum { eObjectRelease2, eGWOP_EXCEPT, eAllocMember4, + eDotMemberMem, + eDotMemberMem2, + eDotMemberMem4, eDotMember, eDotMember2, eDotMember3, @@ -400,6 +403,9 @@ enum { #define ObjectRelease2 (f_instr)eObjectRelease2 #define GWOP_EXCEPT (f_instr)eGWOP_EXCEPT #define AllocMember4 (f_instr)eAllocMember4 +#define DotMemberMem (f_instr)eDotMemberMem +#define DotMemberMem2 (f_instr)eDotMemberMem2 +#define DotMemberMem4 (f_instr)eDotMemberMem4 #define DotMember (f_instr)eDotMember #define DotMember2 (f_instr)eDotMember2 #define DotMember3 (f_instr)eDotMember3 @@ -1280,6 +1286,21 @@ ANN static inline void dump_opcodes(const VM_Code code) { gw_out(" {-R}%-14"UINT_F"{0}", instr->m_val); gw_out("\n"); break; + case eDotMemberMem: + gw_out("{Y}┃{0}{-}% 4lu{0}: DotMemberMem", j); + gw_out(" {-R}%-14"UINT_F"{0}", instr->m_val); + gw_out("\n"); + break; + case eDotMemberMem2: + gw_out("{Y}┃{0}{-}% 4lu{0}: DotMemberMem2", j); + gw_out(" {-R}%-14"UINT_F"{0}", instr->m_val); + gw_out("\n"); + break; + case eDotMemberMem4: + gw_out("{Y}┃{0}{-}% 4lu{0}: DotMemberMem4", j); + gw_out(" {-R}%-14"UINT_F"{0}", instr->m_val); + gw_out("\n"); + break; case eDotMember: gw_out("{Y}┃{0}{-}% 4lu{0}: DotMember ", j); gw_out(" {-R}%-14"UINT_F"{0}", instr->m_val); diff --git a/opcode.txt b/opcode.txt index 6040d9a0..9cbb9db3 100644 --- a/opcode.txt +++ b/opcode.txt @@ -182,6 +182,9 @@ ObjectRelease~u ObjectRelease2~p GWOP_EXCEPT~u AllocMember4~u +DotMemberMem~u +DotMemberMem2~u +DotMemberMem4~u DotMember~u DotMember2~u DotMember3~u~u diff --git a/src/emit/emit.c b/src/emit/emit.c index 71d08789..3da44aa0 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1659,7 +1659,8 @@ ANN static void call_finish(const Emitter emit, const Func f, const m_uint offset = emit_code_offset(emit); if (f != emit->env->func || !is_static || strcmp(s_name(f->def->base->xid), "new")) regseti(emit, offset); - const Instr instr = emit_call(emit, f, is_static); + const bool _is_static = !strcmp(s_name(f->def->base->xid), "new") ? true : is_static; + const Instr instr = emit_call(emit, f, _is_static); instr->m_val = f->def->base->ret_type->size; instr->m_val2 = offset; } @@ -2958,9 +2959,20 @@ ANN static m_bool _emit_class_def(const Emitter emit, const Class_Def cdef) { CHECK_BB(cdef_parent(emit, c)); if (c->body) { emit_class_code(emit, t->name); +// if (scanx_body(emit->env, c, (_exp_func)emit_section, emit) > 0 && vector_size(&emit->code->instr) > 1) if (scanx_body(emit->env, c, (_exp_func)emit_section, emit) > 0) +{ +// if (vector_size(&emit->code->instr)) +// if (tflag(t, tflag_ctor)) t->nspc->pre_ctor = finalyze(emit, FuncReturn); - else { +/* +else{ +puts("hehe"); +free_code(emit->gwion->mp, emit->code); + emit_pop_code(emit); +} +*/ +} else { free_code(emit->gwion->mp, emit->code); emit_pop_code(emit); return GW_ERROR; diff --git a/src/gwion.c b/src/gwion.c index 4dfb87ad..f01ae9c7 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -121,10 +121,11 @@ ANN m_bool gwion_ini(const Gwion gwion, CliArg *arg) { tcol_override_color_checks(isatty(1)); else if (arg->color == COLOR_ALWAYS) tcol_override_color_checks(1); - if (!gwion->data->cdoc) + if(!vector_size(&gwion->data->passes->vec)) { + if (!gwion->data->cdoc) pass_default(gwion); - else - doc_mode(gwion); + else doc_mode(gwion); + } return !arg->quit ? gwion_ok(gwion, arg) : GW_ERROR; } diff --git a/src/import/import_prim.c b/src/import/import_prim.c index 3a2dc480..4a984f0a 100644 --- a/src/import/import_prim.c +++ b/src/import/import_prim.c @@ -90,7 +90,6 @@ static OP_EMIT(opem_bit_access) { instr->udata.two = (m_int)((offset / CHAR_BIT) - SZ_INT); } else { const Instr instr = emit_add_instr(emit, bit_set_fast); - const m_uint offset = info->array.exp->d.prim.d.num; instr->m_val2 = offset % CHAR_BIT; instr->m_val = (offset / CHAR_BIT); } diff --git a/src/vm/vm.c b/src/vm/vm.c index 2da96167..94925406 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -459,8 +459,10 @@ vm_prepare(const VM *vm, m_bit *prepare_code) { // lgtm [cpp/use-of-goto] &&branchnefloat, &&unroll, &&arrayappend, &&autounrollinit, &&autoloop, &&arraytop, &&arrayaccess, &&arrayget, &&arrayaddr, &&newobj, &&addref, &&addrefaddr, &&structaddref, &&structaddrefaddr, &&objassign, &&assign, - &&remref, &&remref2, &&except, &&allocmemberaddr, &&dotmember, &&dotfloat, - &&dotother, &&dotaddr, &&unioncheck, &&unionint, &&unionfloat, + &&remref, &&remref2, &&except, &&allocmemberaddr, + &&dotmembermem, &&dotmembermem2, /*&&dotmembermem3, */&&dotmembermem4, + &&dotmember, &&dotfloat, &&dotother, &&dotaddr, + &&unioncheck, &&unionint, &&unionfloat, &&unionother, &&unionaddr, &&staticint, &&staticfloat, &&staticother, &&dotfunc, &&gacktype, &&gackend, &&gack, &&try_ini, &&try_end, &&handleeffect, &&performeffect, &&noop, &&debugline, @@ -1103,6 +1105,22 @@ vm_prepare(const VM *vm, m_bit *prepare_code) { // lgtm [cpp/use-of-goto] *(m_bit **)reg = (*(M_Object *)mem)->data + VAL; reg += SZ_INT; DISPATCH() + dotmembermem: + reg += SZ_INT; + *(m_uint *)(reg - SZ_INT) = + *(m_uint *)((*(M_Object *)(mem + VAL2))->data + VAL); + DISPATCH() + dotmembermem2: + reg += SZ_INT - SZ_FLOAT; + *(m_float *)(reg - SZ_FLOAT) = + *(m_float *)((*(M_Object *)(mem + VAL2))->data + VAL); + DISPATCH() +// dotmembermem3: + dotmembermem4: + reg += SZ_INT; + *(m_bit **)(reg - SZ_INT) = + ((*(M_Object *)(mem + VAL2))->data + VAL); + DISPATCH() dotmember: *(m_uint *)(reg - SZ_INT) = *(m_uint *)((*(M_Object *)(reg - SZ_INT))->data + VAL); @@ -1297,8 +1315,10 @@ static void *_dispatch[] = { &&_branchnefloat, &&_unroll, &&_arrayappend, &&_autounrollinit, &&_autoloop, &&_arraytop, &&_arrayaccess, &&_arrayget, &&_arrayaddr, &&_newobj, &&_addref, &&_addrefaddr, &&_structaddref, &&_structaddrefaddr, &&_objassign, &&_assign, - &&_remref, &&_remref2, &&_except, &&_allocmemberaddr, &&_dotmember, &&_dotfloat, - &&_dotother, &&_dotaddr, &&_unioncheck, &&_unionint, &&_unionfloat, + &&_remref, &&_remref2, &&_except, &&_allocmemberaddr, + &&_dotmembermem, &&_dotmembermem2, /*&&_dotmembermem3, */&&_dotmembermem4, + &&_dotmember, &&_dotfloat, &&_dotother, &&_dotaddr, + &&_unioncheck, &&_unionint, &&_unionfloat, &&_unionother, &&_unionaddr, &&_staticint, &&_staticfloat, &&_staticother, &&_dotfunc, &&_gacktype, &&_gackend, &&_gack, &&_try_ini, &&_try_end, &&_handleeffect, &&_performeffect, &&_noop, &&_debugline, @@ -1521,6 +1541,10 @@ return; PREPARE(remref2); PREPARE(except); PREPARE(allocmemberaddr); + PREPARE(dotmembermem); + PREPARE(dotmembermem2); + //PREPARE(dotmembermem3); + PREPARE(dotmembermem4); PREPARE(dotmember); PREPARE(dotfloat); PREPARE(dotother); diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index 4474f898..e8602b8c 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -85,6 +85,24 @@ ANN static m_bit *tobytecode(MemPool p, const VM_Code code) { } i += j; continue; + } else if (instr->opcode == eRegPushMem) { + const Instr next = (Instr)vector_at(v, i+1); + if(next->opcode == eDotMember) { + instr->opcode = eDotMemberMem; + instr->m_val2 = instr->m_val; + instr->m_val = next->m_val; + next->opcode = eNoOp; + } else if(next->opcode == eDotMember2) { + instr->opcode = eDotMemberMem2; + instr->m_val2 = instr->m_val; + instr->m_val = next->m_val; + next->opcode = eNoOp; + } else if(next->opcode == eDotMember4) { + instr->opcode = eDotMemberMem4; + instr->m_val2 = instr->m_val; + instr->m_val = next->m_val; + next->opcode = eNoOp; + } } else if (instr->opcode == eUnroll2) { const Instr unroll = (Instr)instr->m_val; const m_uint pc = vector_find(v, (m_uint)unroll);