summaryrefslogtreecommitdiff
path: root/libguile/vm-engine.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2020-07-23 12:05:14 +0200
committerAndy Wingo <wingo@pobox.com>2020-07-23 12:24:11 +0200
commitbb7fa5bdc24e35927d3450343ee23879dc556745 (patch)
tree682b098eee947bee2bee4e66d6969d76d1b37532 /libguile/vm-engine.c
parent5e1748f75128107e3a0707b66df5adb95d98437e (diff)
downloadguile-bb7fa5bdc24e35927d3450343ee23879dc556745.tar.gz
Add jtable instruction
* doc/ref/vm.texi (Instruction Set): Document new v32-x8-l24 instruction kind. (Branch Instructions): Document jtable. * libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add V32_X8_L24. * libguile/jit.c (compile_jtable, compile_jtable_slow): (COMPILE_X8_S24__V32_X8_L24, analyze): Add stub JIT compiler implementation. * libguile/vm-engine.c (jtable): New instruction. * module/language/bytecode.scm (instruction-arity): Deprecate. * module/system/vm/assembler.scm (encoder, assembler): Add V32_X8_L24 case. * module/system/vm/disassembler.scm (u32-ref, s32-ref): Move definitions to expansion-time only. (define-op-handlers): New definition, replacing visit-opcodes. (disassemblers, jump-parsers, stack-effect-parsers, clobber-parsers): Rework in terms of define-op-handlers. Default case becomes #f, and add support for jtable. (disassemble-one, instruction-relative-jump-targets) (instruction-stack-size-after, instruction-slot-clobbers): Inline default case in the lookup procedure, not copied in the handler vector. (compute-labels): Add jtable case. (instruction-lengths-vector, instruction-length): Rework to allow variable-length instructions, and mark jtable as being variable-length. (instruction-has-fallthrough?): Add jtable to the no-fallthrough set.
Diffstat (limited to 'libguile/vm-engine.c')
-rw-r--r--libguile/vm-engine.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c
index 19d35f113..74825818d 100644
--- a/libguile/vm-engine.c
+++ b/libguile/vm-engine.c
@@ -3376,7 +3376,31 @@ VM_NAME (scm_thread *thread)
NEXT (2);
}
- VM_DEFINE_OP (163, unused_163, NULL, NOP)
+ /* jtable idx:24 len:32 (_:8 offset:24)...
+ *
+ * Branch to an entry in a table, as in C's switch statement. IDX is
+ * a u64 local, and the immediate LEN indicates the number of entries
+ * in the table, and should be greater than or equal to 1. The last
+ * entry in the table is the "catch-all" entry. The OFFSET... values
+ * are in the usual L24 encoding, indicating a memory address as a
+ * number of 32-bit words away from the current instruction pointer.
+ */
+ VM_DEFINE_OP (163, jtable, "jtable", OP2 (X8_S24, V32_X8_L24))
+ {
+ uint32_t idx, len;
+ const uint32_t *offsets;
+
+ UNPACK_24 (op, idx);
+ len = ip[1];
+ offsets = ip + 2;
+
+ uint64_t i = SP_REF_U64 (idx);
+ VM_ASSERT (len > 0, abort());
+ int32_t offset = offsets[i < len ? i : len - 1];
+ offset >>= 8; /* Sign-extending shift. */
+ NEXT (offset);
+ }
+
VM_DEFINE_OP (164, unused_164, NULL, NOP)
VM_DEFINE_OP (165, unused_165, NULL, NOP)
VM_DEFINE_OP (166, unused_166, NULL, NOP)