From 7ff876267b22d7918543ceb9aef72edb9e2ea754 Mon Sep 17 00:00:00 2001 From: jackbackrack Date: Mon, 16 Oct 2023 14:54:28 -0700 Subject: [PATCH 1/2] hook up jit dispatch code gen --- compiler/branch-table.stanza | 418 +++++++++++++++++++++++++-------- compiler/cvm-code-table.stanza | 8 +- compiler/cvm-encoder.stanza | 10 +- compiler/jit-code-table.stanza | 5 +- compiler/jit-encoder.stanza | 182 +++++++++++++- compiler/vm-structures.stanza | 3 + compiler/vm.stanza | 25 +- 7 files changed, 526 insertions(+), 125 deletions(-) diff --git a/compiler/branch-table.stanza b/compiler/branch-table.stanza index 81c4eae22..c6b495b5e 100644 --- a/compiler/branch-table.stanza +++ b/compiler/branch-table.stanza @@ -13,7 +13,12 @@ defpackage stz/branch-table : import stz/set-utils import stz/conversion-utils import stz/timing-log-api - + import stz/asmjit + import stz/jit-encoder + import stz/code-table + import clib + import stz/backend + ;============================================================ ;=================== Public Interface ======================= ;============================================================ @@ -21,7 +26,9 @@ public deftype BranchTable public defmulti add (t:BranchTable, f:BranchFormat) -> Int public defmulti get (t:BranchTable, f:Int) -> BranchFormat public defmulti load-package-methods (t:BranchTable, package:Symbol, ms:Seqable) -> False -public defmulti update (t:BranchTable) -> False +public defmulti update (t:BranchTable, resolver:EncodingResolver) -> False +public defmulti dispatchers (t:BranchTable) -> FuncBuffer +public defmulti runtime (t:BranchTable) -> False|JitRuntime ;============================================================ ;======================== Timers ============================ @@ -95,18 +102,26 @@ defmethod equal? (a:MultiFormat, b:MultiFormat) : ;================= Table Implementation ===================== ;============================================================ -public defn BranchTable (ct:ClassTable) : +deftype BranchEntries +defmulti remove (entries:BranchEntries, i:Int) -> False +defmulti compute (entries:BranchEntries, ct:ClassTable, , resolver:EncodingResolver, backend:Backend, i:Int, f:BranchFormat) -> False +defmulti key? (entries:BranchEntries, i:Int) -> True|False + +public defn BranchTable (ct:ClassTable, jit?:True|False, backend:Backend) : ;================================================== ;=============== State of Table =================== ;================================================== ;Store formats in ctable + val rt = jit-runtime-new() + val func-entries = FuncBranchEntries(FuncBuffer(rt, 8), rt) + val trie-entries = TrieBranchEntries(PtrBuffer(8)) + val entries = func-entries when jit? else trie-entries val formats = Vector() val format-table = HashTable() val methods = Vector() ;All compiled tables corresponding to each format - val trie-table = PtrBuffer(8) - val stale-trie-tables = Vector() + val stale-entries = Vector() ;Format dependencies val format-class-dependencies = DynBiTable() @@ -115,35 +130,35 @@ public defn BranchTable (ct:ClassTable) : val method-multi-table = DynBiTable() ;Mapping from method to multis ;================================================== - ;============= Trie Table Invalidation ============ + ;================ Entry Invalidation ============== ;================================================== ;Record a table as invalidated, so that it is updated next cycle. - defn invalidate-table (i:Int) : - remove(trie-table, i) - add(stale-trie-tables, i) + defn invalidate-entry (i:Int) : + remove(entries, i) + add(stale-entries, i) - defn invalidate-tables-of-multi (multi:Int) : - do(invalidate-table, multi-formats[multi]) + defn invalidate-entries-of-multi (multi:Int) : + do(invalidate-entry, multi-formats[multi]) - defn update-trie-table () : - while not empty?(stale-trie-tables) : - val i = pop(stale-trie-tables) - compute-trie-table(i) when not key?(trie-table, i) - ensure-no-stale-tables!() + defn update-entry (resolver:EncodingResolver) : + while not empty?(stale-entries) : + val i = pop(stale-entries) + compute-entry(i, resolver) when not key?(entries, i) + ensure-no-stale-entries!() - defn ensure-no-stale-tables! () : + defn ensure-no-stale-entries! () : #if-not-defined(OPTIMIZE) : for i in 0 to length(formats) do : - if not key?(trie-table, i) : - fatal("Trie table %_ is stale." % [i]) + if not key?(entries, i) : + fatal("Branch Table %_ is stale." % [i]) false ;================================================== - ;========== Computing the Trie Table ============== + ;============= Computing the Entry ================ ;================================================== - defn compute-trie-table (i:Int) : + defn compute-entry (i:Int, resolver:EncodingResolver) : val f* = resolve-format(formats[i]) - compute-trie-table-entry(trie-table, ct, i, f*) + compute(entries, ct, resolver, backend, i, f*) defn resolve-format (f:BranchFormat) : match(f:MultiFormat) : ResolvedMultiFormat(num-header-args(f), methods-of-multi(multi(f))) @@ -159,7 +174,7 @@ public defn BranchTable (ct:ClassTable) : format-table[bf] = i match(bf:MultiFormat) : add(multi-formats, multi(bf), i) - invalidate-table(i) + invalidate-entry(i) i ;================================================== @@ -169,12 +184,12 @@ public defn BranchTable (ct:ClassTable) : add(methods, LoadedMethod(multi(m), types(m), fid(m), package-name, instance?(m))) val id = length(methods) - 1 method-class-dependencies[id] = class-dependencies(m) - invalidate-tables-of-multi(multi(m)) + invalidate-entries-of-multi(multi(m)) method-multi-table[id] = [multi(m)] defn remove-method (i:Int) : val m = methods[i] as LoadedMethod - invalidate-tables-of-multi(multi(m)) + invalidate-entries-of-multi(multi(m)) method-class-dependencies[i] = [] methods[i] = false method-multi-table[i] = [] @@ -211,8 +226,8 @@ public defn BranchTable (ct:ClassTable) : ;class tree changes. new TreeListener : defmethod node-changed (this, c:Int) : - do(invalidate-table, formats-dependent-on-class(c)) - do(invalidate-tables-of-multi, multis-dependent-on-class(c)) + do(invalidate-entry, formats-dependent-on-class(c)) + do(invalidate-entries-of-multi, multis-dependent-on-class(c)) add(ct, class-change-listener()) ;================================================== @@ -225,31 +240,17 @@ public defn BranchTable (ct:ClassTable) : match(get?(format-table, f)) : (i:Int) : i (_:False) : add-format(f) - defmethod update (this) : - update-trie-table() - defmethod trie-table (this) : - trie-table + defmethod update (this, resolver:EncodingResolver) : + update-entry(resolver) defmethod load-package-methods (this, package:Symbol, ms:Seqable) : load-package-methods(package, ms) - -;================================================== -;============ Retrieve Trie Table Data ============ -;================================================== -defmulti trie-table (bt:BranchTable) -> PtrBuffer -public lostanza defn trie-table-data (bt:ref) -> ptr> : - return trie-table(bt).data - -;================================================== -;============ Compute a Trie Table Entry ========== -;================================================== -lostanza defn compute-trie-table-entry (trie-table:ref, - class-table:ref, - i:ref, - f:ref) -> ref : - val p = to-trie-table(class-table, f) - set(trie-table, i.value, p) - return false - + defmethod trie-table (this) : + trie-table(trie-entries) + defmethod dispatchers (this) : + dispatchers(func-entries) + defmethod runtime (this) : + rt + ;============================================================ ;==================== Utilities ============================= ;============================================================ @@ -291,6 +292,158 @@ defn multi-dependencies (f:BranchFormat) : (f:MultiFormat) : [multi(f)] (f:DispatchFormat|MatchFormat) : [] + +;************************************************** +;************** TRIE TABLE BACKEND **************** +;************************************************** + +;================================================== +;============ Retrieve Trie Table Data ============ +;================================================== +defmulti trie-table (bt:BranchTable) -> PtrBuffer +public lostanza defn trie-table-data (bt:ref) -> ptr> : + return trie-table(bt).data +public lostanza defn dispatchers-data (bt:ref) -> ptr : + return dispatchers(bt).data as ptr + +;================================================== +;============ Compute a Trie Table Entry ========== +;================================================== +lostanza defn compute-trie-table-entry (trie-table:ref, + class-table:ref, + i:ref, + f:ref) -> ref : + val p = to-trie-table(class-table, f) + set(trie-table, i.value, p) + return false + +;Conversion of a Vector into a ptr +lostanza defn to-int-ptr (xs:ref>) -> ptr : + val n = length(xs).value + val p:ptr = call-c clib/malloc(n * sizeof(int)) + for (var i:int = 0, i < n, i = i + 1) : + p[i] = get(xs, new Int{i}).value + return p + +;Conversion of a BranchFormat into a ptr +lostanza defn to-trie-table (ct:ref, f:ref) -> ptr : + val ints = encode-branch-format(ct, f) + return to-int-ptr(ints) + +;================================================== +;================ Compute Dispatcher ============== +;================================================== +lostanza defn compute-func-entry (rt:ref, + resolver:ref, + backend:ref, + dispatchers:ref, + class-table:ref, + i:ref, + f:ref) -> ref : + val d = to-func(rt, resolver, backend, class-table, f, i) + set(dispatchers, i.value, d.value) + return false + +;Conversion of a BranchFormat into dispatcher Code +lostanza defn to-func (rt:ref, resolver:ref, backend:ref, ct:ref, f:ref, idx:ref) -> ref : + val code = jit-branch-format(rt, resolver, backend, ct, f, idx) + return code + +;======================================================= +;================ Encoding of Branch Formats ================ +;============================================================ + +# Conversion of a Typeset into an Arg # + +Input: + ct:ClassTable + t:TypeSet +Output: + arg:Arg + +# Conversion of a BranchFormat into an encoded Vector # + +Input: + ct:ClassTable + f:BranchFormat +Output: + table:Vector + +# Conversion of a Vector into a ptr # + +Input: + xs:Vector +Output: + ys:ptr + +# Conversion of a BranchFormat into a ptr # + +Input: + ct:ref + f:ref +Output: + table:ptr + +;============================================================ +;======================================================= + +;Encoding a sequence of TypeSets into a dispatch branch +defn make-branch-table (ct:ClassTable, branches:Seqable>) : + within log-time(MAKE-BRANCH-TABLE) : + DagBranchTable( + to-branches(branches, set-representation{ct, _}), + abstract-classes(ct)) + +;Convert a BranchFormat to a tuple of IBranch +defn encode-branch-format (ct:ClassTable, f:BranchFormat) -> Vector : + match(f) : + (f:MatchFormat) : + val dag = within log-time(BRANCH-TABLE-DISPATCH-DAG) : + val branch-table = make-branch-table(ct, branches(f)) + compute-dispatch-dag(branch-table, false) + defn soln-id (s:Soln) : + match(s) : + (s:NoSoln) : 0 + (s:UniqueSoln) : index(s) + 1 + encode-dag(dag, 0, soln-id) + (f:DispatchFormat) : + val dag = within log-time(BRANCH-TABLE-DISPATCH-DAG) : + val branch-table = make-branch-table(ct, branches(f)) + compute-dispatch-dag(branch-table, true) + defn soln-id (s:Soln) : + match(s) : + (s:NoSoln) : 0 + (s:AmbSoln) : 1 + (s:UniqueSoln) : index(s) + 2 + encode-dag(dag, 0, soln-id) + (f:ResolvedMultiFormat) : + val dag = within log-time(BRANCH-TABLE-DISPATCH-DAG) : + val branch-table = make-branch-table(ct, seq(types,methods(f))) + compute-dispatch-dag(branch-table, true) + defn soln-id (s:Soln) : + match(s) : + (s:NoSoln) : 0 + (s:AmbSoln) : 1 + (s:UniqueSoln) : fid(methods(f)[index(s)]) + 2 + encode-dag(dag, num-header-args(f), soln-id) + +;============================================================ +;============== TrieBranchEntries Datastructure ============= +;============================================================ + +defstruct TrieBranchEntries <: BranchEntries : + trie-table : PtrBuffer + +defmethod remove (entries:TrieBranchEntries, i:Int) : + remove(trie-table(entries), i) + false + +defmethod compute (entries:TrieBranchEntries, ct:ClassTable, resolver:EncodingResolver, backend:Backend, i:Int, f:BranchFormat) : + compute-trie-table-entry(trie-table(entries), ct, i, f) + +defmethod key? (entries:TrieBranchEntries, i:Int) : + key?(trie-table(entries), i) + ;======================================================= ;================== PtrBuffer Datastructure ================= ;============================================================ @@ -390,93 +543,158 @@ lostanza defn remove (b:ref, i:ref) -> ref : else : return false +;************************************************** +;************ DISPATCH TABLE BACKEND ************** +;************************************************** + +;============================================================ +;============ DispatchBranchEntries Datastructure =========== +;============================================================ + +defstruct FuncBranchEntries <: BranchEntries : + dispatchers : FuncBuffer + rt : JitRuntime + +defmethod remove (entries:FuncBranchEntries, i:Int) : + remove(dispatchers(entries), i) + false + +defmethod compute (entries:FuncBranchEntries, ct:ClassTable, resolver:EncodingResolver, backend:Backend, i:Int, f:BranchFormat) : + compute-func-entry(rt(entries), resolver, backend, dispatchers(entries), ct, i, f) + +defmethod key? (entries:FuncBranchEntries, i:Int) : + key?(dispatchers(entries), i) + ;======================================================= -;================ Encoding of Branch Formats ================ +;================= FuncBuffer Datastructure ================= ;============================================================ -# Conversion of a Typeset into an Arg # +# Creation of FuncBuffer # Input: - ct:ClassTable - t:TypeSet + n:ref Output: - arg:Arg + buffer:ref -# Conversion of a BranchFormat into an encoded Vector # +# Store new pointer into FuncBuffer # Input: - ct:ClassTable - f:BranchFormat -Output: - table:Vector + b:ref + i:int + p:ptr -# Conversion of a Vector into a ptr # +# Retrieve the data pointer of ref # + + p.data + +# Check whether key i exists in FuncBuffer # Input: - xs:Vector + b:ref + i:ref Output: - ys:ptr + exists?:ref -# Conversion of a BranchFormat into a ptr # +# Remove an entry i from FuncBuffer # Input: - ct:ref - f:ref + b:ref + i:ref Output: - table:ptr + removed?:ref ;============================================================ ;======================================================= -;Encoding a sequence of TypeSets into a dispatch branch -defn make-branch-table (ct:ClassTable, branches:Seqable>) : - within log-time(MAKE-BRANCH-TABLE) : - DagBranchTable( - to-branches(branches, set-representation{ct, _}), - abstract-classes(ct)) +public lostanza deftype FuncBuffer : + rt : ref + var length: int + var data: ptr> -;Convert a BranchFormat to a tuple of IBranch -defn encode-branch-format (ct:ClassTable, f:BranchFormat) -> Vector : +lostanza defn FuncBuffer (rt:ref, n:ref) -> ref : + val len = n.value + val data:ptr> = call-c clib/malloc(len * sizeof(ptr)) + for (var i:int = 0, i < len, i = i + 1) : + data[i] = null + return new FuncBuffer{rt, len, data} + +lostanza defn ensure-capacity (p:ref, c:int) -> int : + val l0 = p.length + if l0 < c : + ;Compute new length + var l:int = l0 + while l < c : l = l * 2 + ;Allocate new data, and copy old stuff over + val data:ptr> = call-c clib/malloc(l * sizeof(ptr)) + call-c clib/memcpy(data, p.data, l0 * sizeof(ptr)) + ;Void out left over slots + for (var i:int = l0, i < l, i = i + 1) : + data[i] = null + ;Free old data, and set new data and length + call-c clib/free(p.data) + p.data = data + p.length = l + return 0 + +lostanza defn set (p:ref, i:int, p*:ptr) -> int : + ensure-capacity(p, i + 1) + ;Free old ptr + val p0 = p.data[i] + if p0 != null : release(p.rt, new Long{p0 as long}) + ;Store new ptr + p.data[i] = p* + return 0 + +lostanza defn key? (b:ref, i:ref) -> ref : + if i.value < b.length : + val p = b.data[i.value] + if p == null : return false + else : return true + else : + return false + +lostanza defn remove (b:ref, i:ref) -> ref : + if i.value < b.length : + val p = b.data[i.value] + if p == null : + return false + else : + release(b.rt, new Long{p as long}) + b.data[i.value] = null + return true + else : + return false + +;============================================================ +;============================================================ + +;Convert a BranchFormat to dispatcher Code +defn jit-branch-format (rt:JitRuntime, resolver:EncodingResolver, backend:Backend, ct:ClassTable, f:BranchFormat, idx:Int) -> Func : match(f) : - (f:MatchFormat) : - val dag = within log-time(BRANCH-TABLE-DISPATCH-DAG) : - val branch-table = make-branch-table(ct, branches(f)) - compute-dispatch-dag(branch-table, false) + (f:MatchFormat) : + val branch-table = make-branch-table(ct, branches(f)) + val dag = compute-dispatch-dag(branch-table, false) defn soln-id (s:Soln) : match(s) : (s:NoSoln) : 0 (s:UniqueSoln) : index(s) + 1 - encode-dag(dag, 0, soln-id) + jit-dag(rt, resolver, backend, dag, 0, soln-id, idx) (f:DispatchFormat) : - val dag = within log-time(BRANCH-TABLE-DISPATCH-DAG) : - val branch-table = make-branch-table(ct, branches(f)) - compute-dispatch-dag(branch-table, true) + val branch-table = make-branch-table(ct, branches(f)) + val dag = compute-dispatch-dag(branch-table, true) defn soln-id (s:Soln) : match(s) : (s:NoSoln) : 0 (s:AmbSoln) : 1 (s:UniqueSoln) : index(s) + 2 - encode-dag(dag, 0, soln-id) + jit-dag(rt, resolver, backend, dag, 0, soln-id, idx) (f:ResolvedMultiFormat) : - val dag = within log-time(BRANCH-TABLE-DISPATCH-DAG) : - val branch-table = make-branch-table(ct, seq(types,methods(f))) - compute-dispatch-dag(branch-table, true) + val branch-table = make-branch-table(ct, seq(types,methods(f))) + val dag = compute-dispatch-dag(branch-table, true) defn soln-id (s:Soln) : match(s) : (s:NoSoln) : 0 (s:AmbSoln) : 1 (s:UniqueSoln) : fid(methods(f)[index(s)]) + 2 - encode-dag(dag, num-header-args(f), soln-id) - -;Conversion of a Vector into a ptr -lostanza defn to-int-ptr (xs:ref>) -> ptr : - val n = length(xs).value - val p:ptr = call-c clib/malloc(n * sizeof(int)) - for (var i:int = 0, i < n, i = i + 1) : - p[i] = get(xs, new Int{i}).value - return p + jit-dag(rt, resolver, backend, dag, num-header-args(f), soln-id, idx) -;Conversion of a BranchFormat into a ptr -lostanza defn to-trie-table (ct:ref, f:ref) -> ptr : - val ints = encode-branch-format(ct, f) - return to-int-ptr(ints) diff --git a/compiler/cvm-code-table.stanza b/compiler/cvm-code-table.stanza index 0577b180b..dad6dc0bf 100644 --- a/compiler/cvm-code-table.stanza +++ b/compiler/cvm-code-table.stanza @@ -32,17 +32,17 @@ lostanza defmethod instructions (t:ref) -> ref : lostanza defmethod load-function (table:ref, fid:ref, - func:ref, + vm-func:ref, externfn?:ref, resolver:ref, backend:ref) -> ref : ;Encode the function using the CVM encoder. - val encoded-function = encode(func, resolver, backend) + val encoded-function = encode(vm-func, resolver, backend) ;Load the bytecode into the bytecode vector. - val num-bytes = length(buffer(encoded-function)) + val num-bytes = length(byte-buffer!(encoded-function)) val offset = alloc(table.bytecode, num-bytes.value) - call-c clib/memcpy(table.bytecode.mem + offset, data(buffer(encoded-function)), num-bytes.value) + call-c clib/memcpy(table.bytecode.mem + offset, data(byte-buffer!(encoded-function)), num-bytes.value) ;Add the offset to the trace entries so that we know their absolute position. val relocated-trace-entries = add-offset(trace-entries(encoded-function), new Long{offset}) diff --git a/compiler/cvm-encoder.stanza b/compiler/cvm-encoder.stanza index 0d96d72e8..032f0c3a7 100644 --- a/compiler/cvm-encoder.stanza +++ b/compiler/cvm-encoder.stanza @@ -14,11 +14,17 @@ defpackage stz/cvm-encoder : import stz/code-table import stz/vm-opcodes import stz/trace-info + import stz/asmjit + import stz/params public defstruct EncodedFunction : - buffer: ByteBuffer + jit?: True|False + func: ByteBuffer|Func trace-entries: Vector +public defn byte-buffer! (f:EncodedFunction) -> ByteBuffer : + func(f) as ByteBuffer + public defn encode (func:VMFunction, resolver:EncodingResolver, backend:Backend) -> EncodedFunction : @@ -698,7 +704,7 @@ public defn encode (func:VMFunction, ;Use delayed actions and encode instructions within delay-actions() : encode(func as VMMultifn|VMFunc) - EncodedFunction(buffer, trace-entry-table) + EncodedFunction(contains?(EXPERIMENTAL-FEATURES, `jit), buffer, trace-entry-table) ;============================================================ ;====================== Utilities =========================== diff --git a/compiler/jit-code-table.stanza b/compiler/jit-code-table.stanza index 981dfba63..65a30622d 100644 --- a/compiler/jit-code-table.stanza +++ b/compiler/jit-code-table.stanza @@ -8,6 +8,7 @@ defpackage stz/jit-code-table : import stz/asmjit import stz/jit-encoder import stz/vm-structures + import stz/branch-table ;============================================================ ;================= Struct Definition ======================== @@ -29,8 +30,8 @@ public defstruct JITStubs : ;================== Constructor ============================= ;============================================================ -public defn JITCodeTable (resolver:EncodingResolver, backend:Backend) -> JITCodeTable : - val runtime = jit-runtime-new() +public defn JITCodeTable (resolver:EncodingResolver, backend:Backend, branch-table:BranchTable) -> JITCodeTable : + val runtime = runtime(branch-table) as JitRuntime val stubs = make-jit-stubs(runtime, resolver, backend) #JITCodeTable(runtime, stubs) diff --git a/compiler/jit-encoder.stanza b/compiler/jit-encoder.stanza index 2a97291b1..35d839509 100644 --- a/compiler/jit-encoder.stanza +++ b/compiler/jit-encoder.stanza @@ -19,6 +19,11 @@ defpackage stz/jit-encoder : import stz/shuffle import stz/timing-log-api import stz/trace-info + import stz/binary-tree + import stz/asm-ir-utils + import stz/asm-ir with: + prefix(Label, Loc, Reg, SetIns, EqOp) => asm-ir- + ;============================================================ ;===================== JIT Encoder ========================== @@ -346,6 +351,7 @@ defmulti emit-function-prelude (gen:AsmGen, args:Tuple, extend-sta defmulti emit-arg-bit-extensions (gen:AsmGen, args:Tuple) -> False defmulti emit-multi-arity-dispatch (emit-arity-code:Int|False -> False, gen:AsmGen, arity-arg:Int, arities:Tuple) -> False defmulti emit-ins (gen:AsmGen, ins:VMIns) -> False +defmulti emit-dispatch-dag (gen:AsmGen, rt:JitRuntime, backend:Backend, dag:Dag, start-depth:Int, soln-id:Soln -> Int, idx:Int) -> False defenum EnterExit: (Enter, Exit) ;The information about a function's local frame. @@ -379,6 +385,7 @@ defn AsmGen (code:CodeHolder, defn callc-ret () : callc-return(registers) defn callc-fret () : callc-freturn(registers) + ;========================================================= ;============== Function Stack Frame ===================== ;========================================================= @@ -494,6 +501,7 @@ defn AsmGen (code:CodeHolder, get-vmstate-current-stack get-vmstate-system-stack get-vmstate-system-registers + get-vmstate-dispatchers get-return get-liveness-map get-stack-size @@ -515,6 +523,7 @@ defn AsmGen (code:CodeHolder, set-vmstate-current-stack set-vmstate-system-stack set-vmstate-system-registers + set-vmstate-dispatchers set-return set-liveness-map set-stack-size @@ -536,6 +545,7 @@ defn AsmGen (code:CodeHolder, VMStateReg VMStateReg VMStateReg + VMStateReg StackPointerReg StackPointerReg StackReg @@ -557,6 +567,7 @@ defn AsmGen (code:CodeHolder, VMSTATE-CURRENT-STACK-OFFSET VMSTATE-SYSTEM-STACK-OFFSET VMSTATE-SYSTEM-REGISTERS-OFFSET + VMSTATE-DISPATCHERS-OFFSET STACK-FRAME-RETURN-OFFSET STACK-FRAME-LIVENESS-MAP-OFFSET STACK-SIZE-OFFSET @@ -578,6 +589,7 @@ defn AsmGen (code:CodeHolder, vmstate-current-stack-memptr vmstate-system-stack-memptr vmstate-system-registers-memptr + vmstate-dispatchers-memptr stack-frame-return-memptr stack-frame-liveness-map-memptr stack-size-memptr @@ -1326,20 +1338,21 @@ defn AsmGen (code:CodeHolder, ;========================================================= ;=================== Dispatch ============================ ;========================================================= - ;Emit instructions for reading the dispatch table with the current + ;Emit instructions for reading and calling the dispatcher table with the current ;values in the vmstate.registers array. - ;Uses Tmp1 internally. defn read-dispatch-table (dst:Gp, format:Int) -> False : - mov(a, reg(Tmp1), format) - val args = [reg(VMStateReg), reg(Tmp1)] - simple-call-c-from-jit-context(dst, read-dispatch-table-addr(), args) + val dispatchers = get-vmstate-dispatchers(rax) + val dispatcher = mov(a, rax, MemPtr(dispatchers, format * SIZEOF-LONG, SIZEOF-LONG)) + call(a, dispatcher) + mov(a, dst, rax) + false ;Emit instructions for performing a dispatch according to the given format ;to the set of given labels. defn emit-dispatch (format:Int, ys:Tuple, labels:Tuple