diff options
Diffstat (limited to 'third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting')
11 files changed, 256 insertions, 0 deletions
diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/arithmetic_count.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/arithmetic_count.wat new file mode 100644 index 0000000000..90891313a4 --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/arithmetic_count.wat @@ -0,0 +1,11 @@ +(module + (func $main (export "test_function") + i32.const 4 + i32.const -5 + i32.add + drop + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 3 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/br_table_count.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/br_table_count.wat new file mode 100644 index 0000000000..29846f083d --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/br_table_count.wat @@ -0,0 +1,25 @@ +(module + (func $main (export "test_function") + block $a + i64.const 1 + drop + + block $b + i64.const 2 + drop + + block $c + i64.const 3 + drop + + ;; 3 for above consts, one for i32.const below, 2 for br_table + ;; totalling to an expected count of 6 + (br_table 0 1 2 3 (i32.const 4)) + end + end + end + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 6 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/calls.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/calls.wat new file mode 100644 index 0000000000..6fba4c4e6e --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/calls.wat @@ -0,0 +1,22 @@ +(module + (func $mul2 (param $in i64) (result i64) + get_local $in + get_local $in + i64.mul + ) + (func $main (export "test_function") + i64.const 1 + call $mul2 ;; one from the call, three from the called function, one for the return + drop + i64.const 2 + call $mul2 ;; and again + drop + i64.const 3 + call $mul2 ;; and again + ;; for a total of 3 * 6 == 18 instructions + drop + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 18 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/count_after_br.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/count_after_br.wat new file mode 100644 index 0000000000..52e180f6f1 --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/count_after_br.wat @@ -0,0 +1,21 @@ +(module + (func $main (export "test_function") + block $ops + i32.const 11 + i32.const 10 + i32.add + + br 0 ;; branch to enclosing scope (end of this block) + ;; at this point we've counted four operations... + end + + i32.const 14 + i32.const 15 + i32.add + ;; this puts us at 7 operations + drop + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 7 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/empty_loop.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/empty_loop.wat new file mode 100644 index 0000000000..1817743134 --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/empty_loop.wat @@ -0,0 +1,9 @@ +(module + (func $main (export "test_function") (local $i i32) + loop $inner + end + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 0 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/empty_loop_2.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/empty_loop_2.wat new file mode 100644 index 0000000000..302e0df8e4 --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/empty_loop_2.wat @@ -0,0 +1,11 @@ +(module + (func $main (export "test_function") (local $i i32) + block $a + loop $inner + end + end + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 0 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/if_count.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/if_count.wat new file mode 100644 index 0000000000..e4bcb617ee --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/if_count.wat @@ -0,0 +1,21 @@ +(module + (func $main (export "test_function") + i32.const 11 + i32.const 10 + i32.gt_s + ;; this counts up to 3 + (if ;; this makes 4 + (then + i64.const 5 + i64.const 10 + i64.mul + ;; and these were another 3 + drop + ;; drop is ignored for a total of 7 operations + ) + ) + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 7 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/if_not_taken_count.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/if_not_taken_count.wat new file mode 100644 index 0000000000..af5794d5a9 --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/if_not_taken_count.wat @@ -0,0 +1,21 @@ +(module + (func $main (export "test_function") + i32.const 10 + i32.const 11 + i32.gt_s + ;; this counts up to 3 + (if ;; this makes 4 + ;; but the `then` branch is not taken + (then + i64.const 5 + i64.const 10 + i64.mul + drop + ) + ) + ;; so we only execute 4 operations + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 4 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/indirect_calls.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/indirect_calls.wat new file mode 100644 index 0000000000..e6a5bbf994 --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/indirect_calls.wat @@ -0,0 +1,68 @@ +(module + (type $mulfn (func (param i64) (result i64))) + + ;; mul2 is 3 operations + (func $mul2 (param $in i64) (result i64) + get_local $in + get_local $in + i64.add + ) + ;; mul4 is 2 * |mul2| + 2 call + 3 == 13 + (func $mul4 (param $in i64) (result i64) + get_local $in + call $mul2 + get_local $in + call $mul2 + i64.add + ) + ;; mul8 is 2 * |mul4| + 2 call + 3 == 33 + (func $mul8 (param $in i64) (result i64) + get_local $in + call $mul4 + get_local $in + call $mul4 + i64.add + ) + ;; mul16 is 2 * |mul8| + 2 call + 3 == 73 + ;; by entire accident the number of instructions for + ;; subsequent similar functions for higher powers is given by + ;; mul(n^2) == 10 * (2 ^ (n - 1)) - 10 + 3 + (func $mul16 (param $in i64) (result i64) + get_local $in + call $mul8 + get_local $in + call $mul8 + i64.add + ) + + (table anyfunc + (elem + $mul2 $mul4 $mul8 $mul16 + ) + ) + + (func $main (export "test_function") + ;; call_indirect here is 2, plus 1 for the const, one for the index, and + ;; 1 for return + ;; the called function (mul2) is 3 instructions, for 8 total. + (call_indirect (type $mulfn) (i64.const 0) (i32.const 0)) + drop + + ;; call_indirect here is 2, plus 1 for the const, one for the index, and + ;; 1 for return + ;; the called function (mul4) is 13 instructions, for 18 total. + (call_indirect (type $mulfn) (i64.const 1) (i32.const 1)) + drop + + ;; call_indirect here is 2, plus 1 for the const, one for the index, and + ;; 1 for return + ;; the called function (mul16) is 73 instructions, for 78 total. + (call_indirect (type $mulfn) (i64.const 2) (i32.const 3)) + drop + + ;; for a total of 8 + 18 + 78 == 104 instructions + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 104 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/loops.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/loops.wat new file mode 100644 index 0000000000..3b68a0abd7 --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/loops.wat @@ -0,0 +1,30 @@ +(module + (func $main (export "test_function") (local $i i32) + i32.const 0 + set_local $i + block $outer + loop $inner + ;; each loop iteration is: + ;; * 4 operations to increment i + ;; * 3 operations to test i == 10 + ;; * 1 branch to break (untaken) + ;; * 1 branch to loop + get_local $i + i32.const 1 + i32.add + set_local $i + get_local $i + i32.const 10 + i32.eq + br_if $outer + br $inner + end + end + ;; iterating i = 0..9, that's 10 * 8 instructions from full executions, + ;; plus 9 instructions from the last round. + ;; add two for initializing i and that gives 80 + 9 + 2 = 91 instructions + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 91 + ) +) diff --git a/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/unreachable_call.wat b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/unreachable_call.wat new file mode 100644 index 0000000000..3caf474288 --- /dev/null +++ b/third_party/rust/lucet-runtime-wasmsbx/tests/instruction_counting/unreachable_call.wat @@ -0,0 +1,17 @@ +(module + (func $main (export "test_function") (result i64) + ;; counting the const + i64.const 1 + ;; return is counted by the caller, so we count 1 so far + return + + ;; we had a bug where calls in unreachable code would still add + ;; one to the instruction counter to track a matching return, + ;; but the call would never be made, so the return would never + ;; occur, and the count was in error. + call $main + ) + (func $instruction_count (export "instruction_count") (result i64) + i64.const 1 + ) +) |