summaryrefslogtreecommitdiff
path: root/libguile/vm-expand.h
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2009-02-03 22:36:02 +0100
committerAndy Wingo <wingo@pobox.com>2009-02-03 22:36:02 +0100
commitf775e51bceb7399893b01380c5b56a7b665b782a (patch)
treeecaa0bf864d531d19a90e67895486af0b0e593b7 /libguile/vm-expand.h
parentef7e18683c06a3a1524787becd29b8c11dbc5674 (diff)
downloadguile-f775e51bceb7399893b01380c5b56a7b665b782a.tar.gz
make symbol -> opcode lookup faster
* libguile/instructions.c (fetch_instruction_table) (scm_lookup_instruction_by_name): Rework so we lazily load instructions into an array keyed by opcode, and a hash table keyed by symbolic name. Much faster, in this hot spot of compilation. * libguile/vm-engine.c (vm_run): Use malloc instead of scm_gc_malloc, given that we aren't ever going to free this thing. * libguile/vm-expand.h (VM_DEFINE_FUNCTION, VM_DEFINE_LOADER): Rework to always be aliases to VM_DEFINE_INSTRUCTION. (VM_DEFINE_INSTRUCTION): In the table case, update to work with fetch_instruction_table().
Diffstat (limited to 'libguile/vm-expand.h')
-rw-r--r--libguile/vm-expand.h27
1 files changed, 13 insertions, 14 deletions
diff --git a/libguile/vm-expand.h b/libguile/vm-expand.h
index d750a73d8..ef69352c3 100644
--- a/libguile/vm-expand.h
+++ b/libguile/vm-expand.h
@@ -52,19 +52,24 @@
#endif /* not HAVE_LABELS_AS_VALUES */
#endif /* VM_LABEL */
-#undef VM_DEFINE_INSTRUCTION
#undef VM_DEFINE_FUNCTION
#undef VM_DEFINE_LOADER
-#ifdef VM_INSTRUCTION_TO_TABLE
+#define VM_DEFINE_FUNCTION(code,tag,name,nargs) \
+ VM_DEFINE_INSTRUCTION(code,tag,name,0,nargs,1)
+#define VM_DEFINE_LOADER(code,tag,name) \
+ VM_DEFINE_INSTRUCTION(code,tag,name,-1,0,1)
+
+#undef VM_DEFINE_INSTRUCTION
/*
* These will go to scm_instruction_table in instructions.c
*/
-#define VM_DEFINE_INSTRUCTION(code,tag,name,len,npop,npush) \
- {VM_OPCODE (tag), name, len, npop, npush},
-#define VM_DEFINE_FUNCTION(code,tag,name,nargs) \
- {VM_OPCODE (tag), name, 0, nargs, 1},
-#define VM_DEFINE_LOADER(code,tag,name) \
- {VM_OPCODE (tag), name, -1, 0, 1},
+#ifdef VM_INSTRUCTION_TO_TABLE
+#define VM_DEFINE_INSTRUCTION(code_,tag_,name_,len_,npop_,npush_) \
+ table[VM_OPCODE (tag_)].opcode = VM_OPCODE (tag_); \
+ table[VM_OPCODE (tag_)].name = name_; \
+ table[VM_OPCODE (tag_)].len = len_; \
+ table[VM_OPCODE (tag_)].npop = npop_; \
+ table[VM_OPCODE (tag_)].npush = npush_;
#else
#ifdef VM_INSTRUCTION_TO_LABEL
@@ -72,8 +77,6 @@
* These will go to jump_table in vm_engine.c
*/
#define VM_DEFINE_INSTRUCTION(code,tag,name,len,npop,npush) jump_table[VM_OPCODE (tag)] = VM_ADDR (tag);
-#define VM_DEFINE_FUNCTION(code,tag,name,nargs) jump_table[VM_OPCODE (tag)] = VM_ADDR (tag);
-#define VM_DEFINE_LOADER(code,tag,name) jump_table[VM_OPCODE (tag)] = VM_ADDR (tag);
#else
#ifdef VM_INSTRUCTION_TO_OPCODE
@@ -81,16 +84,12 @@
* These will go to scm_opcode in instructions.h
*/
#define VM_DEFINE_INSTRUCTION(code,tag,name,len,npop,npush) VM_OPCODE (tag) = code,
-#define VM_DEFINE_FUNCTION(code,tag,name,nargs) VM_OPCODE (tag) = code,
-#define VM_DEFINE_LOADER(code,tag,name) VM_OPCODE (tag) = code,
#else /* Otherwise */
/*
* These are directly included in vm_engine.c
*/
#define VM_DEFINE_INSTRUCTION(code,tag,name,len,npop,npush) VM_TAG (tag)
-#define VM_DEFINE_FUNCTION(code,tag,name,nargs) VM_TAG (tag)
-#define VM_DEFINE_LOADER(code,tag,name) VM_TAG (tag)
#endif /* VM_INSTRUCTION_TO_OPCODE */
#endif /* VM_INSTRUCTION_TO_LABEL */