This is the mail archive of the
guile@sources.redhat.com
mailing list for the Guile project.
Re: debug evaluator is faster than regular one?
cwitty@newtonlabs.com (Carl R. Witty) writes:
> The Hugs implementation of Haskell uses a bytecode interpreter that
> uses "computed goto" when compiled with gcc and "switch" otherwise.
> It does this with a few lines of preprocessor hacks; the main body of
> the bytecode interpreter is shared between the two compilation
> variants. You might want to look how they do it.
Ok, this is how they does:
--- aclocal.m4 ----
dnl check for gcc's "labels as values" feature
AC_DEFUN(AC_C_LABELS_AS_VALUES,
[AC_CACHE_CHECK([labels as values], ac_cv_labels_as_values,
[AC_TRY_COMPILE([
int foo(int);
int foo(i)
int i; {
static void *label[] = { &&l1, &&l2 };
goto *label[i];
l1: return 1;
l2: return 2;
}
],
[int i;],
ac_cv_labels_as_values=yes,
ac_cv_labels_as_values=no)])
if test "$ac_cv_labels_as_values" = yes; then
AC_DEFINE(HAVE_LABELS_AS_VALUES)
fi
])
-----------------------
---- configure.in ----
AC_C_LABELS_AS_VALUES dnl can we use gcc's "labels as values" feature?
----------------------
---- config.h.in ----
/* Define if compiler supports gcc's "labels as values" (aka computed goto)
* feature (which is used to speed up instruction dispatch in the interpreter).
* Here's what typical code looks like:
*
* void *label[] = { &&l1, &&l2 };
* ...
* goto *label[i];
* l1: ...
* l2: ...
* ...
*/
#define HAVE_LABELS_AS_VALUES 0
------------------
---- machine.c ----
#if !DEBUG_CODE && HAVE_LABELS_AS_VALUES
#define Ins(x) &&l##x
static void *labs[] = { INSTRLIST };
#undef Ins
#define Case(x) l##x
#define Continue goto *labs[(pc++)->instr]
#define Dispatch Continue;
#define EndDispatch
#else
#if DEBUG_CODE
#define Dispatch for (;;) { \
if (debugCode) { \
Printf("%*s0x%04X: ", root, "", pc-memory); \
dissInstr(pc-memory); \
} \
switch((pc++)->instr) {
#else
#define Dispatch for (;;) { switch((pc++)->instr) {
#endif
#define Case(x) case x
#define Continue continue
#define EndDispatch default : internal("illegal instruction"); \
break; \
}}
#endif
------------------
I'll copy this configuration test.
Thanks,
Keisuke Nishida