[Quipu-dev] quipu/quipu: Use threaded jumps in the bytecode interpreter

Back to archive index

scmno****@osdn***** scmno****@osdn*****
Sun Jan 21 09:23:49 JST 2018


changeset ad2fc49e9980 in quipu/quipu
details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=ad2fc49e9980
user: Agustina Arzille <avarz****@riseu*****>
date: Sun Jan 21 00:23:30 2018 +0000
description: Use threaded jumps in the bytecode interpreter

diffstat:

 compiler.cpp |  43 +++++++++++++++++++++++++++++++++----------
 1 files changed, 33 insertions(+), 10 deletions(-)

diffs (82 lines):

diff -r 89330d84cbd7 -r ad2fc49e9980 compiler.cpp
--- a/compiler.cpp	Sat Jan 20 23:10:13 2018 +0000
+++ b/compiler.cpp	Sun Jan 21 00:23:30 2018 +0000
@@ -2090,12 +2090,33 @@
   bool captured;
   object fn;
 
-#if defined (__GNUC__) && 0
+#if defined (__GNUC__) && !defined (QP_NO_THREADED_GOTO)
 #  define GOTO_LABELS
 #endif
 
 #ifndef GOTO_LABELS
   uint32_t op;
+#else
+  static const void* LABELS[] =
+    {
+#define P_(opc)   [OP_##opc] = &&OP_LBL_##opc
+      P_(NOP), P_(DUP), P_(POP), P_(RET), P_(IS), P_(NOT), P_(CONS),
+      P_(LIST), P_(CAR), P_(CDR), P_(CADR), P_(NPUTCAR), P_(NPUTCDR),
+      P_(APPLY), P_(TAPPLY), P_(LOADT), P_(LOADNIL), P_(LOAD0), P_(LOAD1),
+      P_(LOADI8), P_(LOADA0), P_(LOADA1), P_(LOADC00), P_(LOADC01),
+      P_(OPTARGS), P_(BRBOUND), P_(KWARGS), P_(MKCONT), P_(CAPTENV),
+      P_(CLOSURE), P_(TRYEND), P_(ARGC), P_(ARGCL), P_(VARGC), P_(VARGCL),
+      P_(JMP), P_(JMPL), P_(BRT), P_(BRTL), P_(BRN), P_(BRNL), P_(BRNEQ),
+      P_(BRNEQL), P_(TCALL), P_(TCALLL), P_(CALL), P_(CALLL), P_(SETC),
+      P_(SETCL), P_(SETA), P_(SETAL), P_(SETAP), P_(SETAPL), P_(SETG),
+      P_(SETGL), P_(LOADC), P_(LOADCL), P_(LOADA), P_(LOADAL), P_(LOADAP),
+      P_(LOADAPL), P_(LOADG), P_(LOADGL), P_(LOADV), P_(LOADVL), P_(LOADX),
+      P_(LOADXL), P_(BIND), P_(BINDL), P_(RECUR), P_(RECURL), P_(TRECUR),
+      P_(TRECURL), P_(MKFRAME), P_(MKFRAMEL), P_(UNWIND), P_(UNWINDL),
+      P_(TRYBEGIN), P_(TRYBEGINL)
+    };
+
+#  undef P_
 #endif
 
   if (cdp != 0)
@@ -2121,6 +2142,8 @@
     }
 
 #ifdef GOTO_LABELS
+#  define OP_(code)   OP_LBL_##code
+#  define NEXT_OP     goto *LABELS[*ip++]
   NEXT_OP;
 #else
 
@@ -2249,25 +2272,25 @@
       ip += (int16_t)get16 (ip);
       NEXT_OP;
 
+    OP_(JMPL):
+      ip += (int32_t)get32 (ip);
+      NEXT_OP;
+
     OP_(BRN):
       interp->pop ();
       ip += retval == NIL ? (int16_t)get16 (ip) : sizeof (int16_t);
       NEXT_OP;
 
+    OP_(BRNL):
+      interp->pop ();
+      ip += retval == NIL ? (int32_t)get32 (ip) : sizeof (int32_t);
+      NEXT_OP;
+
     OP_(BRT):
       interp->pop ();
       ip += retval != NIL ? (int16_t)get16 (ip) : sizeof (int16_t);
       NEXT_OP;
 
-    OP_(JMPL):
-      ip += (int32_t)get32 (ip);
-      NEXT_OP;
-
-    OP_(BRNL):
-      interp->pop ();
-      ip += retval == NIL ? (int32_t)get32 (ip) : sizeof (int32_t);
-      NEXT_OP;
-
     OP_(BRTL):
       interp->pop ();
       ip += retval != NIL ? (int32_t)get32 (ip) : sizeof (int32_t);




More information about the Quipu-dev mailing list
Back to archive index