2015-12-11 12:26:16 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-12-17 10:54:08 +00:00
|
|
|
// Flags: --expose-wasm
|
|
|
|
|
2016-03-07 19:32:35 +00:00
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-03-07 19:32:35 +00:00
|
|
|
function runSelect2(select, which, a, b) {
|
|
|
|
assertEquals(which == 0 ? a : b, select(a, b));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSelect2(type) {
|
|
|
|
for (var which = 0; which < 2; which++) {
|
|
|
|
print("type = " + type + ", which = " + which);
|
|
|
|
|
2016-03-07 19:32:35 +00:00
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
|
2016-04-29 09:39:26 +00:00
|
|
|
builder.addFunction("select", makeSig_r_xx(type, type))
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, which])
|
2016-03-07 19:32:35 +00:00
|
|
|
.exportFunc()
|
|
|
|
|
|
|
|
var select = builder.instantiate().exports.select;
|
|
|
|
|
|
|
|
runSelect2(select, which, 99, 97);
|
|
|
|
runSelect2(select, which, -99, -97);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
if (type != kWasmF32) {
|
2016-03-07 19:32:35 +00:00
|
|
|
runSelect2(select, which, 0x80000000 | 0, 0x7fffffff | 0);
|
|
|
|
runSelect2(select, which, 0x80000001 | 0, 0x7ffffffe | 0);
|
|
|
|
runSelect2(select, which, 0xffffffff | 0, 0xfffffffe | 0);
|
|
|
|
runSelect2(select, which, -2147483647, 2147483646);
|
|
|
|
runSelect2(select, which, -2147483646, 2147483645);
|
|
|
|
runSelect2(select, which, -2147483648, 2147483647);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
if (type != kWasmI32 && type != kWasmI64) {
|
2016-03-07 19:32:35 +00:00
|
|
|
runSelect2(select, which, -1.25, 5.25);
|
|
|
|
runSelect2(select, which, Infinity, -Infinity);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
testSelect2(kWasmI32);
|
|
|
|
testSelect2(kWasmF32);
|
|
|
|
testSelect2(kWasmF64);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
|
2016-03-07 19:32:35 +00:00
|
|
|
function runSelect10(select, which, a, b) {
|
2015-12-11 12:26:16 +00:00
|
|
|
var x = -1;
|
|
|
|
|
|
|
|
var result = [
|
2016-03-07 19:32:35 +00:00
|
|
|
select(a, b, x, x, x, x, x, x, x, x),
|
|
|
|
select(x, a, b, x, x, x, x, x, x, x),
|
|
|
|
select(x, x, a, b, x, x, x, x, x, x),
|
|
|
|
select(x, x, x, a, b, x, x, x, x, x),
|
|
|
|
select(x, x, x, x, a, b, x, x, x, x),
|
|
|
|
select(x, x, x, x, x, a, b, x, x, x),
|
|
|
|
select(x, x, x, x, x, x, a, b, x, x),
|
|
|
|
select(x, x, x, x, x, x, x, a, b, x),
|
|
|
|
select(x, x, x, x, x, x, x, x, a, b),
|
|
|
|
select(x, x, x, x, x, x, x, x, x, a)
|
2015-12-11 12:26:16 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
if (which == i) assertEquals(a, result[i]);
|
|
|
|
else if (which == i+1) assertEquals(b, result[i]);
|
|
|
|
else assertEquals(x, result[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 19:32:35 +00:00
|
|
|
function testSelect10(t) {
|
2015-12-11 12:26:16 +00:00
|
|
|
var kBodySize = 2;
|
2016-02-28 00:37:11 +00:00
|
|
|
var kNameOffset = kHeaderSize + 29 + kBodySize + 1;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
for (var which = 0; which < 10; which++) {
|
2016-03-07 19:32:35 +00:00
|
|
|
print("type = " + t + ", which = " + which);
|
|
|
|
|
|
|
|
var builder = new WasmModuleBuilder();
|
2016-06-21 19:47:51 +00:00
|
|
|
builder.addFunction("select", makeSig([t,t,t,t,t,t,t,t,t,t], [t]))
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, which])
|
2016-03-07 19:32:35 +00:00
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
var select = builder.instantiate().exports.select;
|
|
|
|
|
|
|
|
assertEquals("function", typeof select);
|
|
|
|
runSelect10(select, which, 99, 97);
|
|
|
|
runSelect10(select, which, -99, -97);
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
if (t != kWasmF32) {
|
2016-03-07 19:32:35 +00:00
|
|
|
runSelect10(select, which, 0x80000000 | 0, 0x7fffffff | 0);
|
|
|
|
runSelect10(select, which, 0x80000001 | 0, 0x7ffffffe | 0);
|
|
|
|
runSelect10(select, which, 0xffffffff | 0, 0xfffffffe | 0);
|
|
|
|
runSelect10(select, which, -2147483647, 2147483646);
|
|
|
|
runSelect10(select, which, -2147483646, 2147483645);
|
|
|
|
runSelect10(select, which, -2147483648, 2147483647);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
if (t != kWasmI32 && t != kWasmI64) {
|
2016-03-07 19:32:35 +00:00
|
|
|
runSelect10(select, which, -1.25, 5.25);
|
|
|
|
runSelect10(select, which, Infinity, -Infinity);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
testSelect10(kWasmI32);
|
|
|
|
testSelect10(kWasmF32);
|
|
|
|
testSelect10(kWasmF64);
|