bug1693500.js (2434B)
1 // |jit-test| skip-if: !wasmSimdEnabled() || wasmCompileMode() != "ion" || (!getBuildConfiguration("x86") && !getBuildConfiguration("x64")) || getBuildConfiguration("simulator") 2 3 const avx = isAvxPresent(); 4 for (let [n1, n2, numInstr] of [ 5 [0x123456789abn, 0xffeeddccbbaa9988n, avx ? 6 : 7], 6 [42n, 0xFFFFFFFFn, avx ? 3 : 4], 7 [0n, 0n, 1], 8 [1n, 1n, 1], 9 ...iota(63).map(i => [2n << BigInt(i), 2n << BigInt(i), 1]), 10 ...iota(63).reduce((acc, i) => { 11 const base = 2n << BigInt(i); 12 return acc.concat(iota(i + 1).map(j => [ 13 base | (1n << BigInt(j)), base | (1n << BigInt(j)), 14 (avx ? 2 : 3) + (j == 0 ? 0 : 1)])); 15 }, []), 16 ...iota(63).map(i => [~(1n << BigInt(i)), ~(1n << BigInt(i)), avx ? 5 : 6]), 17 [0x7fffffffffffffffn, 0x7fffffffffffffffn, avx ? 5 : 6], 18 [-1n, -1n, 3], 19 ]) { 20 var wasm = wasmTextToBinary(`(module 21 (memory (export "memory") 1 1) 22 (func $t (export "t") (param v128) (result v128) 23 local.get 0 24 v128.const i64x2 ${n1} ${n2} 25 i64x2.mul 26 ) 27 (func $t0 (param v128 v128) (result v128) 28 local.get 0 29 local.get 1 30 i64x2.mul 31 ) 32 (func (export "run") (result i32) 33 i32.const 16 34 i32.const 0 35 v128.load 36 call $t 37 v128.store 38 39 v128.const i64x2 ${n1} ${n2} 40 i32.const 0 41 v128.load 42 call $t0 43 44 i32.const 16 45 v128.load 46 i64x2.eq 47 i64x2.all_true 48 ) 49 )`) 50 51 var ins = new WebAssembly.Instance(new WebAssembly.Module(wasm)); 52 var mem64 = new BigInt64Array(ins.exports.memory.buffer, 0, 4); 53 54 for (let [t1, t2] of [ 55 [1n, 1n], [-1n, -2n], [0n, 0n], [0x123456789abn, 0xffeeddccbbaa9988n], 56 [0x100001111n, -0xFF0011n], [5555n, 0n], 57 ]) { 58 mem64[0] = t1; mem64[1] = t2; 59 assertEq(ins.exports.run(), 1); 60 } 61 62 if (hasDisassembler() && getBuildConfiguration("x64")) { 63 const dis = wasmDis(ins.exports.t, {asString: true,}); 64 const lines = getFuncBody(dis).trim().split('\n'); 65 assertEq(lines.length, numInstr); 66 } 67 } 68 69 // Utils. 70 function getFuncBody(dis) { 71 const parts = dis.split(/mov %rsp, %rbp\n|movq %r14, 0x[13]0\(%rbp\)\n|^[0-9A-Fa-f ]+pop %rbp/gm); 72 return parts.at(-2).replace(/[0-9A-F]{8} (?: [0-9a-f]{2})+[\s\n]+/g, ""); 73 }