| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
| 6 | 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 | 9 |
| 10 function runSelect2(select, which, a, b) { | 10 function runSelect2(select, which, a, b) { |
| 11 assertEquals(which == 0 ? a : b, select(a, b)); | 11 assertEquals(which == 0 ? a : b, select(a, b)); |
| 12 } | 12 } |
| 13 | 13 |
| 14 function testSelect2(type) { | 14 function testSelect2(type) { |
| 15 for (var which = 0; which < 2; which++) { | 15 for (var which = 0; which < 2; which++) { |
| 16 print("type = " + type + ", which = " + which); | 16 print("type = " + type + ", which = " + which); |
| 17 | 17 |
| 18 var builder = new WasmModuleBuilder(); | 18 var builder = new WasmModuleBuilder(); |
| 19 | 19 |
| 20 builder.addFunction("select", [type, type, type]) | 20 builder.addFunction("select", makeSig_r_xx(type, type)) |
| 21 .addBody([kExprGetLocal, which]) | 21 .addBody([kExprGetLocal, which]) |
| 22 .exportFunc() | 22 .exportFunc() |
| 23 | 23 |
| 24 var select = builder.instantiate().exports.select; | 24 var select = builder.instantiate().exports.select; |
| 25 | 25 |
| 26 runSelect2(select, which, 99, 97); | 26 runSelect2(select, which, 99, 97); |
| 27 runSelect2(select, which, -99, -97); | 27 runSelect2(select, which, -99, -97); |
| 28 | 28 |
| 29 if (type != kAstF32) { | 29 if (type != kAstF32) { |
| 30 runSelect2(select, which, 0x80000000 | 0, 0x7fffffff | 0); | 30 runSelect2(select, which, 0x80000000 | 0, 0x7fffffff | 0); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 function testSelect10(t) { | 74 function testSelect10(t) { |
| 75 var kBodySize = 2; | 75 var kBodySize = 2; |
| 76 var kNameOffset = kHeaderSize + 29 + kBodySize + 1; | 76 var kNameOffset = kHeaderSize + 29 + kBodySize + 1; |
| 77 | 77 |
| 78 for (var which = 0; which < 10; which++) { | 78 for (var which = 0; which < 10; which++) { |
| 79 print("type = " + t + ", which = " + which); | 79 print("type = " + t + ", which = " + which); |
| 80 | 80 |
| 81 var builder = new WasmModuleBuilder(); | 81 var builder = new WasmModuleBuilder(); |
| 82 builder.addFunction("select", [t,t,t,t,t,t,t,t,t,t,t]) | 82 builder.addFunction("select", [10,t,t,t,t,t,t,t,t,t,t,1,t]) |
| 83 .addBody([kExprGetLocal, which]) | 83 .addBody([kExprGetLocal, which]) |
| 84 .exportFunc(); | 84 .exportFunc(); |
| 85 | 85 |
| 86 var select = builder.instantiate().exports.select; | 86 var select = builder.instantiate().exports.select; |
| 87 | 87 |
| 88 assertEquals("function", typeof select); | 88 assertEquals("function", typeof select); |
| 89 runSelect10(select, which, 99, 97); | 89 runSelect10(select, which, 99, 97); |
| 90 runSelect10(select, which, -99, -97); | 90 runSelect10(select, which, -99, -97); |
| 91 | 91 |
| 92 if (t != kAstF32) { | 92 if (t != kAstF32) { |
| 93 runSelect10(select, which, 0x80000000 | 0, 0x7fffffff | 0); | 93 runSelect10(select, which, 0x80000000 | 0, 0x7fffffff | 0); |
| 94 runSelect10(select, which, 0x80000001 | 0, 0x7ffffffe | 0); | 94 runSelect10(select, which, 0x80000001 | 0, 0x7ffffffe | 0); |
| 95 runSelect10(select, which, 0xffffffff | 0, 0xfffffffe | 0); | 95 runSelect10(select, which, 0xffffffff | 0, 0xfffffffe | 0); |
| 96 runSelect10(select, which, -2147483647, 2147483646); | 96 runSelect10(select, which, -2147483647, 2147483646); |
| 97 runSelect10(select, which, -2147483646, 2147483645); | 97 runSelect10(select, which, -2147483646, 2147483645); |
| 98 runSelect10(select, which, -2147483648, 2147483647); | 98 runSelect10(select, which, -2147483648, 2147483647); |
| 99 } | 99 } |
| 100 | 100 |
| 101 if (t != kAstI32 && t != kAstI64) { | 101 if (t != kAstI32 && t != kAstI64) { |
| 102 runSelect10(select, which, -1.25, 5.25); | 102 runSelect10(select, which, -1.25, 5.25); |
| 103 runSelect10(select, which, Infinity, -Infinity); | 103 runSelect10(select, which, Infinity, -Infinity); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 | 108 |
| 109 testSelect10(kAstI32); | 109 testSelect10(kAstI32); |
| 110 testSelect10(kAstF32); | 110 testSelect10(kAstF32); |
| 111 testSelect10(kAstF64); | 111 testSelect10(kAstF64); |
| OLD | NEW |