Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/engine/native/NativeStack.v3
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class NativeStack extends WasmStack {
var next_stack: NativeStack;

new(range) {
if (range == null) return; // allocated without a mapping, so nothing to initialize or scan
if (valuerep.tagged) RiGc.registerScanner(this, NativeStack.scan);
if (range == null) return; // allocated without a mapping, no need to initialize further
clear();
if (Trace.stack && Debug.stack) Trace.OUT.put2("newStack start=0x%x, end=0x%x", range.start - Pointer.NULL, range.end - Pointer.NULL).ln();
}
Expand Down
10 changes: 10 additions & 0 deletions test/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ for target in $TEST_TARGETS; do
do_script virgil/test
done

# Virgil tests compiled to Wasm GC
for target in $TEST_TARGETS; do
export TEST_TARGET=$target
if [ "$target" = v3i ]; then # TODO: runs really, really slow on v3i
skip virgil-gc "runs too slowly"
continue
fi
do_script virgil/test-gc
done

# Wasi tests
for target in $TEST_TARGETS; do
export TEST_TARGET=$target
Expand Down
Binary file added test/microbench/100ms/gc_array_rw00.wasm
Binary file not shown.
37 changes: 37 additions & 0 deletions test/microbench/100ms/gc_array_rw00.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
;; INNER_CALIBRATION = 24000
(module
(type $at (array (mut i32)))
(func $main (export "main")
(local $y i32)

(local.set $y (i32.const 1 (;$REPEAT;)))
(loop $l
(call $fill_sum (array.new_default $at (i32.const 2400000 (;$INNER_ITERATIONS;))))
drop
(local.tee $y (i32.sub (local.get $y) (i32.const 1)))
(br_if $l)
)
)
;; Fills the array with its indices, then sums it.
(func $fill_sum (param $a (ref $at)) (result i32)
(local $i i32) (local $sum i32)
(block $done
(loop $l
(br_if $done (i32.ge_u (local.get $i) (array.len (local.get $a))))
(array.set $at (local.get $a) (local.get $i) (local.get $i))
(local.set $i (i32.add (local.get $i) (i32.const 1)))
(br $l)
)
)
(local.set $i (i32.const 0))
(block $done
(loop $l
(br_if $done (i32.ge_u (local.get $i) (array.len (local.get $a))))
(local.set $sum (i32.add (local.get $sum) (array.get $at (local.get $a) (local.get $i))))
(local.set $i (i32.add (local.get $i) (i32.const 1)))
(br $l)
)
)
(local.get $sum)
)
)
Binary file added test/microbench/100ms/gc_br_on_cast00.wasm
Binary file not shown.
43 changes: 43 additions & 0 deletions test/microbench/100ms/gc_br_on_cast00.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
;; INNER_CALIBRATION = 1000
;; Dispatches on the type of a value with a chain of br_on_cast, as in a type switch.
(module
(type $A (sub (struct (field i32))))
(type $B (sub $A (struct (field i32) (field i32))))
(type $C (sub $A (struct (field i32) (field i64))))
(type $D (sub $A (struct (field i32) (field f64))))
(func $main (export "main")
(local $y i32)

(local.set $y (i32.const 1 (;$REPEAT;)))
(loop $l
(drop (call $dispatch (struct.new_default $D) (i32.const 100000 (;$INNER_ITERATIONS;))))
(local.tee $y (i32.sub (local.get $y) (i32.const 1)))
(br_if $l)
)
)
(func $dispatch (param $x anyref) (param $n i32) (result i32)
(local $sum i32)
(block $done
(loop $l
(br_if $done (i32.eqz (local.get $n)))
(local.set $sum (i32.add (local.get $sum)
(block $out (result i32)
(drop (block $isD (result (ref $D))
(drop (block $isC (result (ref $C))
(drop (block $isB (result (ref $B))
(local.get $x)
(br_on_cast $isB anyref (ref $B))
(br_on_cast $isC anyref (ref $C))
(br_on_cast $isD anyref (ref $D))
(drop)
(br $out (i32.const 0))))
(br $out (i32.const 1))))
(br $out (i32.const 2))))
(i32.const 3))))
(local.set $n (i32.sub (local.get $n) (i32.const 1)))
(br $l)
)
)
(local.get $sum)
)
)
Binary file added test/microbench/100ms/gc_struct_cast02.wasm
Binary file not shown.
27 changes: 27 additions & 0 deletions test/microbench/100ms/gc_struct_cast02.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;; INNER_CALIBRATION = 1650
;; Casts to a non-final supertype, which requires a subtype check, not just an exact match.
(module
(type $A (sub (struct (field i32))))
(type $B (sub $A (struct (field i32) (field i32))))
(type $C (sub $B (struct (field i32) (field i32) (field i32))))
(func $main (export "main")
(local $y i32)

(local.set $y (i32.const 1 (;$REPEAT;)))
(loop $l
(call $cast (struct.new_default $C) (i32.const 165000 (;$INNER_ITERATIONS;)))
(local.tee $y (i32.sub (local.get $y) (i32.const 1)))
(br_if $l)
)
)
(func $cast (param anyref i32)
(block $done
(loop $l
(br_if $done (i32.eqz (local.get 1)))
(drop (ref.cast (ref $B) (local.get 0)))
(local.set 1 (i32.sub (local.get 1) (i32.const 1)))
(br $l)
)
)
)
)
Binary file added test/microbench/100ms/gc_struct_rw00.wasm
Binary file not shown.
28 changes: 28 additions & 0 deletions test/microbench/100ms/gc_struct_rw00.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;; INNER_CALIBRATION = 1000
(module
(type $st (struct (field $a (mut i32)) (field $b (mut i64)) (field $c (mut f64)) (field $d (mut i8))))
(func $main (export "main")
(local $y i32)

(local.set $y (i32.const 1 (;$REPEAT;)))
(loop $l
(call $rw (struct.new_default $st) (i32.const 100000 (;$INNER_ITERATIONS;)))
(local.tee $y (i32.sub (local.get $y) (i32.const 1)))
(br_if $l)
)
)
;; Increments each field of the struct in a loop.
(func $rw (param $s (ref $st)) (param $n i32)
(block $done
(loop $l
(br_if $done (i32.eqz (local.get $n)))
(struct.set $st $a (local.get $s) (i32.add (struct.get $st $a (local.get $s)) (i32.const 1)))
(struct.set $st $b (local.get $s) (i64.add (struct.get $st $b (local.get $s)) (i64.const 3)))
(struct.set $st $c (local.get $s) (f64.add (struct.get $st $c (local.get $s)) (f64.const 0.5)))
(struct.set $st $d (local.get $s) (i32.add (struct.get_u $st $d (local.get $s)) (i32.const 1)))
(local.set $n (i32.sub (local.get $n) (i32.const 1)))
(br $l)
)
)
)
)
37 changes: 37 additions & 0 deletions test/microbench/gc_array_rw00.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
;; INNER_CALIBRATION = 24000
(module
(type $at (array (mut i32)))
(func $main (export "main")
(local $y i32)

(local.set $y (i32.const 1 (;$REPEAT;)))
(loop $l
(call $fill_sum (array.new_default $at (i32.const 1 (;$INNER_ITERATIONS;))))
drop
(local.tee $y (i32.sub (local.get $y) (i32.const 1)))
(br_if $l)
)
)
;; Fills the array with its indices, then sums it.
(func $fill_sum (param $a (ref $at)) (result i32)
(local $i i32) (local $sum i32)
(block $done
(loop $l
(br_if $done (i32.ge_u (local.get $i) (array.len (local.get $a))))
(array.set $at (local.get $a) (local.get $i) (local.get $i))
(local.set $i (i32.add (local.get $i) (i32.const 1)))
(br $l)
)
)
(local.set $i (i32.const 0))
(block $done
(loop $l
(br_if $done (i32.ge_u (local.get $i) (array.len (local.get $a))))
(local.set $sum (i32.add (local.get $sum) (array.get $at (local.get $a) (local.get $i))))
(local.set $i (i32.add (local.get $i) (i32.const 1)))
(br $l)
)
)
(local.get $sum)
)
)
43 changes: 43 additions & 0 deletions test/microbench/gc_br_on_cast00.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
;; INNER_CALIBRATION = 1000
;; Dispatches on the type of a value with a chain of br_on_cast, as in a type switch.
(module
(type $A (sub (struct (field i32))))
(type $B (sub $A (struct (field i32) (field i32))))
(type $C (sub $A (struct (field i32) (field i64))))
(type $D (sub $A (struct (field i32) (field f64))))
(func $main (export "main")
(local $y i32)

(local.set $y (i32.const 1 (;$REPEAT;)))
(loop $l
(drop (call $dispatch (struct.new_default $D) (i32.const 1 (;$INNER_ITERATIONS;))))
(local.tee $y (i32.sub (local.get $y) (i32.const 1)))
(br_if $l)
)
)
(func $dispatch (param $x anyref) (param $n i32) (result i32)
(local $sum i32)
(block $done
(loop $l
(br_if $done (i32.eqz (local.get $n)))
(local.set $sum (i32.add (local.get $sum)
(block $out (result i32)
(drop (block $isD (result (ref $D))
(drop (block $isC (result (ref $C))
(drop (block $isB (result (ref $B))
(local.get $x)
(br_on_cast $isB anyref (ref $B))
(br_on_cast $isC anyref (ref $C))
(br_on_cast $isD anyref (ref $D))
(drop)
(br $out (i32.const 0))))
(br $out (i32.const 1))))
(br $out (i32.const 2))))
(i32.const 3))))
(local.set $n (i32.sub (local.get $n) (i32.const 1)))
(br $l)
)
)
(local.get $sum)
)
)
27 changes: 27 additions & 0 deletions test/microbench/gc_struct_cast02.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;; INNER_CALIBRATION = 1650
;; Casts to a non-final supertype, which requires a subtype check, not just an exact match.
(module
(type $A (sub (struct (field i32))))
(type $B (sub $A (struct (field i32) (field i32))))
(type $C (sub $B (struct (field i32) (field i32) (field i32))))
(func $main (export "main")
(local $y i32)

(local.set $y (i32.const 1 (;$REPEAT;)))
(loop $l
(call $cast (struct.new_default $C) (i32.const 1 (;$INNER_ITERATIONS;)))
(local.tee $y (i32.sub (local.get $y) (i32.const 1)))
(br_if $l)
)
)
(func $cast (param anyref i32)
(block $done
(loop $l
(br_if $done (i32.eqz (local.get 1)))
(drop (ref.cast (ref $B) (local.get 0)))
(local.set 1 (i32.sub (local.get 1) (i32.const 1)))
(br $l)
)
)
)
)
28 changes: 28 additions & 0 deletions test/microbench/gc_struct_rw00.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;; INNER_CALIBRATION = 1000
(module
(type $st (struct (field $a (mut i32)) (field $b (mut i64)) (field $c (mut f64)) (field $d (mut i8))))
(func $main (export "main")
(local $y i32)

(local.set $y (i32.const 1 (;$REPEAT;)))
(loop $l
(call $rw (struct.new_default $st) (i32.const 1 (;$INNER_ITERATIONS;)))
(local.tee $y (i32.sub (local.get $y) (i32.const 1)))
(br_if $l)
)
)
;; Increments each field of the struct in a loop.
(func $rw (param $s (ref $st)) (param $n i32)
(block $done
(loop $l
(br_if $done (i32.eqz (local.get $n)))
(struct.set $st $a (local.get $s) (i32.add (struct.get $st $a (local.get $s)) (i32.const 1)))
(struct.set $st $b (local.get $s) (i64.add (struct.get $st $b (local.get $s)) (i64.const 3)))
(struct.set $st $c (local.get $s) (f64.add (struct.get $st $c (local.get $s)) (f64.const 0.5)))
(struct.set $st $d (local.get $s) (i32.add (struct.get_u $st $d (local.get $s)) (i32.const 1)))
(local.set $n (i32.sub (local.get $n) (i32.const 1)))
(br $l)
)
)
)
)
Loading
Loading