| 1 |
// |jit-test| test-also=--setpref=wasm_unroll_loops=true |
| 2 |
|
| 3 |
// Loop unrolling test: 0 exiting values, 2 exit targets => can be unrolled. |
| 4 |
// This is a modified version of unroll2.js. |
| 5 |
|
| 6 |
let t = ` |
| 7 |
(module |
| 8 |
(memory (export "mem") 1) |
| 9 |
(func (export "not_really_memset") |
| 10 |
(param $start i32) (param $byte i32) (param $count i32) |
| 11 |
(local $limit i32) |
| 12 |
(local.set $limit (i32.add (local.get $start) (local.get $count))) |
| 13 |
(loop $cont |
| 14 |
(if (i32.lt_u (local.get $start) (local.get $limit)) (then |
| 15 |
(i32.store8 (local.get $start) |
| 16 |
(i32.xor (local.get $byte) (i32.const 0))) |
| 17 |
(local.set $start (i32.add (local.get $start) (i32.const 1))) |
| 18 |
(if (i32.lt_u (local.get $start) (local.get $limit)) (then |
| 19 |
(i32.store8 (local.get $start) |
| 20 |
(i32.add (local.get $byte) (i32.const 100))) |
| 21 |
(local.set $start (i32.add (local.get $start) (i32.const 1))) |
| 22 |
;; continue |
| 23 |
(br $cont) |
| 24 |
)) |
| 25 |
;; implied else-clause exits the loop |
| 26 |
)) |
| 27 |
;; implied else-clause exits the loop |
| 28 |
) |
| 29 |
) |
| 30 |
)`; |
| 31 |
|
| 32 |
let i = //wasmEvalText(t); |
| 33 |
new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(t))); |
| 34 |
|
| 35 |
i.exports.not_really_memset(1, 22, 1); |
| 36 |
i.exports.not_really_memset(3, 33, 2); |
| 37 |
i.exports.not_really_memset(6, 44, 3); |
| 38 |
i.exports.not_really_memset(10, 55, 4); |
| 39 |
i.exports.not_really_memset(15, 66, 5); |
| 40 |
i.exports.not_really_memset(21, 77, 6); |
| 41 |
i.exports.not_really_memset(28, 88, 7); |
| 42 |
i.exports.not_really_memset(36, 99, 8); |
| 43 |
|
| 44 |
let buf = new Uint8Array(i.exports.mem.buffer); |
| 45 |
|
| 46 |
let s = ""; |
| 47 |
for (let i = 0; i < 45; i++) { |
| 48 |
s = s + (buf[i] + " "); |
| 49 |
} |
| 50 |
|
| 51 |
// The last number (22, 133, 44, 155, etc) in each zero-bordered group is of |
| 52 |
// the form XX if the loop terminates via its first exit edge, and 1XX if it |
| 53 |
// terminates by its second exit edge. |
| 54 |
let expected = |
| 55 |
"0 22 0 33 133 0 44 144 44 0 55 155 55 155 0 66 166 66 166 66 0 77 177 " + |
| 56 |
"77 177 77 177 0 88 188 88 188 88 188 88 0 99 199 99 199 99 199 99 199 0 "; |
| 57 |
|
| 58 |
assertEq(s, expected); |