Skip to content

Commit

Permalink
Increased regBx size from 16 to 24 bits to increase jump range in the VM
Browse files Browse the repository at this point in the history
from 32K to 8M instructions. Fixes #12727
  • Loading branch information
zevv committed Dec 8, 2019
1 parent 23fc93f commit 76228e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/vmdef.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

import ast, idents, options, modulegraphs, lineinfos

type TInstrType* = uint32
type TInstrType* = uint64

const
regOBits = 8 # Opcode
regABits = 8
regBBits = 8
regCBits = 8
regBxBits = 16
regBxBits = 24

byteExcess* = 128 # we use excess-K for immediates

Expand Down
14 changes: 14 additions & 0 deletions tests/vm/tfarjump.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Test a VM relative jump with an offset larger then 32767 instructions.

import macros

static:
var a = 0
macro foo(): untyped =
let s = newStmtList()
for i in 1..6554:
s.add nnkCommand.newTree(ident("inc"), ident("a"))
quote do:
if true:
`s`
foo()

0 comments on commit 76228e6

Please sign in to comment.