forked from nim-works/nimskull
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm: use contiguous register storage (nim-works#1179)
## Summary This is an internal-only change. The VM implementation now uses a register sequence per *thread* rather than per *stack frame*, reducing the overhead of entering and exiting a procedure for code running in the VM. ## Details ### VM interface * allocating the initial stack frame and registers is part of `initVmThread` now * `compilerbridge` is adjusted accordingly; `execute` now takes a `VmThread`, instead of a `TStackFrame`, as input so that the callsites can still initialize the parameter registers ### VM architecture * `VmThread` stores the `seq[TFullReg]` with all registers * instead of their own `seq[TFullReg]`, each stack frame (`TStackFrame`) remembers the index where its register slice begins * the register sequence is a stack: invoking a procedure grows it, while leaving a procedure shrinks it again * the `.cursor`-based mechanism for keeping a low-overhead reference to the current frame's register slice is replaced with `Registers`, which is a length + `ptr UncheckedArray` pair (an unsafe first-class `openArray`, effectively) * instead of by an `IndexDefect` being raised, out-of-bounds register access is reported via the `VmEvent` facility. This means that out- of-bounds register access resulting from ill-formed bytecode no longer crashes the VM Using a single sequence per thread means that there's no more `seq` allocation/destruction overhead per procedure call, which also means less pressure on the host's allocator. ### Misc * a leftover `debugEcho` from some earlier change in `packed_env` is removed --------- Co-authored-by: Saem Ghani <[email protected]>
- Loading branch information
Showing
5 changed files
with
92 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters