baseline-extend8.js (1084B)
1 // This attempts to test that we can do an 8-bit sign extend no matter what the 2 // source register. This test is arguably somewhat tied to the baseline 3 // compiler's register allocator, but is still appropriate for most simple 4 // register allocators. It works by filling an increasing number of registers 5 // with values so as eventually to force the source operand for extend8_s into a 6 // register that does not have a byte personality. 7 8 for ( let i=0; i < 8; i++) { 9 let txt = 10 `(module 11 (func (export "f") (param i32) (result i32) 12 ${adds(i)} 13 (local.set 0 (i32.extend8_s (i32.add (local.get 0) (i32.const 1)))) 14 ${drops(i)} 15 (local.get 0)))`; 16 let ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(txt))); 17 assertEq(ins.exports.f(254), -1); 18 } 19 20 function adds(n) { 21 let s = "" 22 for ( let i=0; i < n; i++ ) 23 s += "(i32.add (local.get 0) (i32.const 1))\n"; 24 return s; 25 } 26 27 function drops(n) { 28 let s = ""; 29 for ( let i=0; i < n; i++ ) 30 s += "drop\n"; 31 return s; 32 }