forked from bytecodealliance/wasmtime
-
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.
winch(x64): Add support for table instructions (bytecodealliance#7155)
* winch(x64): Add support for table instructions This change adds support for the following table insructions: `elem.drop`, `table.copy`, `table.set`, `table.get`, `table.fill`, `table.grow`, `table.size`, `table.init`. This change also introduces partial support for the `Ref` WebAssembly type, more conretely the `Func` heap type, which means that all the table instructions above, only work this WebAssembly type as of this change. Finally, this change is also a small follow up to the primitives introduced in bytecodealliance#7100, more concretely: * `FnCall::with_lib`: tracks the presence of a libcall and ensures that any result registers are freed right when the call is emitted. * `MacroAssembler::table_elem_addr` returns an address rather than the value of the address, making it convenient for other use cases like `table.set`. -- prtest:full * chore: Make stack functions take impl IntoIterator<..> * Update winch/codegen/src/codegen/call.rs Co-authored-by: Trevor Elliott <awesomelyawesome@gmail.com> * Remove a dangling `dbg!` * Add comment on branching --------- Co-authored-by: Trevor Elliott <awesomelyawesome@gmail.com>
- Loading branch information
1 parent
770bdfd
commit 68524c8
Showing
24 changed files
with
1,301 additions
and
200 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(module | ||
(type $t0 (func)) | ||
(func $f1 (type $t0)) | ||
(func $f2 (type $t0)) | ||
(func $f3 (type $t0)) | ||
|
||
;; Define two tables of funcref | ||
(table $t1 3 funcref) | ||
(table $t2 10 funcref) | ||
|
||
;; Initialize table $t1 with functions $f1, $f2, $f3 | ||
(elem (i32.const 0) $f1 $f2 $f3) | ||
|
||
;; Function to fill table $t1 using a function reference from table $t2 | ||
(func (export "fill") (param $i i32) (param $r i32) (param $n i32) | ||
(local $ref funcref) | ||
(local.set $ref (table.get $t1 (local.get $r))) | ||
(table.fill $t2 (local.get $i) (local.get $ref) (local.get $n)) | ||
) | ||
|
||
(func (export "get") (param $i i32) (result funcref) | ||
(table.get $t2 (local.get $i)) | ||
) | ||
) | ||
|
||
(assert_return (invoke "get" (i32.const 1)) (ref.null func)) | ||
(assert_return (invoke "get" (i32.const 2)) (ref.null func)) | ||
(assert_return (invoke "get" (i32.const 3)) (ref.null func)) | ||
(assert_return (invoke "get" (i32.const 4)) (ref.null func)) | ||
(assert_return (invoke "get" (i32.const 5)) (ref.null func)) | ||
|
||
(assert_return (invoke "fill" (i32.const 2) (i32.const 0) (i32.const 3))) | ||
(assert_return (invoke "get" (i32.const 1)) (ref.null func)) | ||
(assert_return (invoke "get" (i32.const 2)) (ref.func 0)) | ||
(assert_return (invoke "get" (i32.const 3)) (ref.func 0)) | ||
(assert_return (invoke "get" (i32.const 4)) (ref.func 0)) | ||
(assert_return (invoke "get" (i32.const 5)) (ref.null func)) | ||
|
||
(assert_return (invoke "fill" (i32.const 4) (i32.const 1) (i32.const 2))) | ||
(assert_return (invoke "get" (i32.const 3)) (ref.func 0)) | ||
(assert_return (invoke "get" (i32.const 4)) (ref.func 1)) | ||
(assert_return (invoke "get" (i32.const 5)) (ref.func 1)) | ||
(assert_return (invoke "get" (i32.const 6)) (ref.null func)) | ||
|
||
(assert_return (invoke "fill" (i32.const 4) (i32.const 2) (i32.const 0))) | ||
(assert_return (invoke "get" (i32.const 3)) (ref.func 0)) | ||
(assert_return (invoke "get" (i32.const 4)) (ref.func 1)) | ||
(assert_return (invoke "get" (i32.const 5)) (ref.func 1)) | ||
|
||
(assert_return (invoke "fill" (i32.const 8) (i32.const 0) (i32.const 2))) | ||
(assert_return (invoke "get" (i32.const 7)) (ref.null func)) | ||
(assert_return (invoke "get" (i32.const 8)) (ref.func 0)) | ||
(assert_return (invoke "get" (i32.const 9)) (ref.func 0)) | ||
|
||
(assert_return (invoke "fill" (i32.const 9) (i32.const 2) (i32.const 1))) | ||
(assert_return (invoke "get" (i32.const 8)) (ref.func 0)) | ||
(assert_return (invoke "get" (i32.const 9)) (ref.func 2)) | ||
|
||
(assert_return (invoke "fill" (i32.const 10) (i32.const 1) (i32.const 0))) | ||
(assert_return (invoke "get" (i32.const 9)) (ref.func 2)) | ||
|
||
(assert_trap | ||
(invoke "fill" (i32.const 8) (i32.const 0) (i32.const 3)) | ||
"out of bounds table access" | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(module | ||
(table $t3 3 funcref) | ||
(elem (table $t3) (i32.const 1) func $dummy) | ||
(func $dummy) | ||
(func $f3 (export "get-funcref") (param $i i32) (result funcref) | ||
(table.get $t3 (local.get $i)) | ||
) | ||
) | ||
|
||
(assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func)) | ||
(assert_trap (invoke "get-funcref" (i32.const 3)) "out of bounds table access") | ||
(assert_trap (invoke "get-funcref" (i32.const -1)) "out of bounds table access") | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(module | ||
(table $t1 0 funcref) | ||
|
||
(func (export "grow-by-10") (param $r funcref) (result i32) | ||
(table.grow $t1 (local.get $r) (i32.const 10)) | ||
) | ||
(func (export "grow-over") (param $r funcref) (result i32) | ||
(table.grow $t1 (local.get $r) (i32.const 0xffff_fff0)) | ||
) | ||
|
||
(func (export "size") (result i32) | ||
(table.size $t1)) | ||
) | ||
|
||
(assert_return (invoke "size") (i32.const 0)) | ||
(assert_return (invoke "grow-by-10" (ref.null func)) (i32.const 0)) | ||
(assert_return (invoke "size") (i32.const 10)) | ||
|
||
(module | ||
(table $t 0x10 funcref) | ||
(func $f (export "grow") (param $r funcref) (result i32) | ||
(table.grow $t (local.get $r) (i32.const 0xffff_fff0)) | ||
) | ||
) | ||
|
||
(assert_return (invoke "grow" (ref.null func)) (i32.const -1)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(module | ||
(table $t3 2 funcref) | ||
(elem (table $t3) (i32.const 1) func $dummy) | ||
(func $dummy) | ||
|
||
(func $f3 (export "get-funcref") (param $i i32) (result funcref) | ||
(table.get $t3 (local.get $i)) | ||
) | ||
|
||
(func (export "set-funcref") (param $i i32) (param $r funcref) | ||
(table.set $t3 (local.get $i) (local.get $r)) | ||
) | ||
(func (export "set-funcref-from") (param $i i32) (param $j i32) | ||
(table.set $t3 (local.get $i) (table.get $t3 (local.get $j))) | ||
) | ||
) | ||
|
||
(assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func)) | ||
(assert_return (invoke "set-funcref-from" (i32.const 0) (i32.const 1))) | ||
(assert_return (invoke "set-funcref" (i32.const 0) (ref.null func))) | ||
(assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func)) | ||
|
||
(assert_trap (invoke "set-funcref" (i32.const 3) (ref.null func)) "out of bounds table access") | ||
(assert_trap (invoke "set-funcref" (i32.const -1) (ref.null func)) "out of bounds table access") | ||
|
||
(assert_trap (invoke "set-funcref-from" (i32.const 3) (i32.const 1)) "out of bounds table access") | ||
(assert_trap (invoke "set-funcref-from" (i32.const -1) (i32.const 1)) "out of bounds table access") |
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
Oops, something went wrong.