| 1 |
|
| 2 |
// Checks that optimised handling, via Ion, of select-of-I32-values as driven |
| 3 |
// by comparison-of-I32-values, works correctly. See bug 1532286 comment 7. |
| 4 |
|
| 5 |
function moduleText(cmp_kind /* "eq", "ne", "le_u" etc */) |
| 6 |
{ |
| 7 |
return `(module |
| 8 |
(func (export "cmpI32_selI32") |
| 9 |
(param i32) (param i32) (param i32) (param i32) |
| 10 |
(result i32) |
| 11 |
(select (local.get 2) |
| 12 |
(local.get 3) |
| 13 |
(i32.${cmp_kind} (local.get 0) (local.get 1)) |
| 14 |
) |
| 15 |
))`; |
| 16 |
} |
| 17 |
|
| 18 |
// Make sure both endpoints and the middlepoint are covered, with one value |
| 19 |
// either side, so as to expose both signedness and off-by-one failures. |
| 20 |
// Ditto quarter points for good measure. |
| 21 |
const vals = [0x0, 0x1, |
| 22 |
0x3fffffff, 0x40000000, 0x40000001, |
| 23 |
0x7fffffff, 0x80000000, 0x80000001, |
| 24 |
0xbfffffff, 0xC0000000, 0xC0000001, |
| 25 |
0xfffffffe, 0xffffffff]; |
| 26 |
|
| 27 |
const testNames |
| 28 |
= ["eq", "ne", "lt_s", "lt_u", "gt_s", "gt_u", |
| 29 |
"le_s", "le_u", "ge_s", "ge_u"]; |
| 30 |
|
| 31 |
const expected_eq |
| 32 |
= [0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1, |
| 33 |
1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1, |
| 34 |
0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1, |
| 35 |
1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1, |
| 36 |
0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1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,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1, |
| 91 |
1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0, |
| 92 |
0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0]; |
| 93 |
|
| 94 |
const expected_ge_u |
| 95 |
= [0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1, |
| 96 |
1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0, |
| 97 |
0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,0, |
| 98 |
0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0, |
| 99 |
0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0]; |
| 100 |
|
| 101 |
const testExpVecs |
| 102 |
= [expected_eq, expected_ne, |
| 103 |
expected_lt_s, expected_lt_u, expected_gt_s, expected_gt_u, |
| 104 |
expected_le_s, expected_le_u, expected_ge_s, expected_ge_u] |
| 105 |
|
| 106 |
assertEq(testNames.length, testExpVecs.length); |
| 107 |
|
| 108 |
for (i in testNames) { |
| 109 |
const testExp = testExpVecs[i]; |
| 110 |
assertEq(testExp.length, vals.length * vals.length); |
| 111 |
|
| 112 |
const inst = wasmEvalText(moduleText(testNames[i])); |
| 113 |
|
| 114 |
let ctr = 0; |
| 115 |
for (let a of vals) { |
| 116 |
for (let b of vals) { |
| 117 |
const actual = inst.exports.cmpI32_selI32(a, b, 42, 1337); |
| 118 |
const expected = testExp[ctr] == 0 ? 42 : 1337; |
| 119 |
assertEq(expected, actual); |
| 120 |
ctr++; |
| 121 |
} |
| 122 |
} |
| 123 |
} |