params.js 3.25 KB
Newer Older
1 2 3 4
// 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.

5 6
// Flags: --expose-wasm

7
load("test/mjsunit/wasm/wasm-constants.js");
8
load("test/mjsunit/wasm/wasm-module-builder.js");
9

10 11
function runSelect2(select, which, a, b) {
  assertEquals(which == 0 ? a : b, select(a, b));
12 13 14 15 16 17
}

function testSelect2(type) {
  for (var which = 0; which < 2; which++) {
    print("type = " + type + ", which = " + which);

18 19
    var builder = new WasmModuleBuilder();

20
    builder.addFunction("select", makeSig_r_xx(type, type))
21 22 23 24 25 26 27
      .addBody([kExprGetLocal, which])
      .exportFunc()

    var select = builder.instantiate().exports.select;

    runSelect2(select, which, 99, 97);
    runSelect2(select, which, -99, -97);
28

29
    if (type != kWasmF32) {
30 31 32 33 34 35
      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);
36 37
    }

38
    if (type != kWasmI32 && type != kWasmI64) {
39 40
      runSelect2(select, which, -1.25, 5.25);
      runSelect2(select, which, Infinity, -Infinity);
41 42 43 44 45
    }
  }
}


46 47 48
testSelect2(kWasmI32);
testSelect2(kWasmF32);
testSelect2(kWasmF64);
49 50


51
function runSelect10(select, which, a, b) {
52 53 54
  var x = -1;

  var result = [
55 56 57 58 59 60 61 62 63 64
    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)
65 66 67 68 69 70 71 72 73
  ];

  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]);
  }
}

74
function testSelect10(t) {
75
  var kBodySize = 2;
76
  var kNameOffset = kHeaderSize + 29 + kBodySize + 1;
77 78

  for (var which = 0; which < 10; which++) {
79 80 81
    print("type = " + t + ", which = " + which);

    var builder = new WasmModuleBuilder();
rossberg's avatar
rossberg committed
82
    builder.addFunction("select", makeSig([t,t,t,t,t,t,t,t,t,t], [t]))
83 84 85 86 87 88 89 90 91
      .addBody([kExprGetLocal, which])
      .exportFunc();

    var select = builder.instantiate().exports.select;

    assertEquals("function", typeof select);
    runSelect10(select, which, 99, 97);
    runSelect10(select, which, -99, -97);

92
    if (t != kWasmF32) {
93 94 95 96 97 98
      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);
99 100
    }

101
    if (t != kWasmI32 && t != kWasmI64) {
102 103
      runSelect10(select, which, -1.25, 5.25);
      runSelect10(select, which, Infinity, -Infinity);
104 105 106 107 108
    }
  }
}


109 110 111
testSelect10(kWasmI32);
testSelect10(kWasmF32);
testSelect10(kWasmF64);