]> Nishi Git Mirror - gwion.git/commitdiff
:art: optimize RegPushMem + Dotmember
authorfennecdjay <fennecdjay@gmail.com>
Thu, 13 Oct 2022 16:13:49 +0000 (18:13 +0200)
committerfennecdjay <fennecdjay@gmail.com>
Thu, 13 Oct 2022 16:13:49 +0000 (18:13 +0200)
include/opcode.h
opcode.txt
src/emit/emit.c
src/gwion.c
src/import/import_prim.c
src/vm/vm.c
src/vm/vm_code.c

index 812785bf6136db83a0af8be33d845e9cda92f829..7daf9908ff2bcb0a18507137e0cea36fe484db87 100644 (file)
@@ -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);
index 6040d9a0b7a0067c27d42c0663421edbd72b9604..9cbb9db3bf1f9fc952d62de9953c3af649fb25ee 100644 (file)
@@ -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
index 71d0878920a0e32e4389a1a8de1cc477bf958eab..3da44aa00b1ec9f04b9097f67f1c52d254b87f7c 100644 (file)
@@ -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;
index 4dfb87adaac2573b3c891212344888bfe78d4c44..f01ae9c7156f9a2dfaeecb4df705d06cc5f69861 100644 (file)
@@ -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;
 }
 
index 3a2dc480c3ac7ca8fc46ff8894c5855bdbcb58fd..4a984f0aca26463c0044e5499443ee1766c6c15b 100644 (file)
@@ -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);
     }
index 2da961671b65a17daec82cbaf9ad7eeee79b0636..949254063ee11e47ac2e34d40d01dc2011ffeee1 100644 (file)
@@ -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);
index 4474f8984fa587a120637609732f3c45389ead6d..e8602b8c333694d97320eef016f780d974426230 100644 (file)
@@ -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);