Skip to content

Commit

Permalink
addressing Mike's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Krovatkin committed Jun 30, 2017
1 parent cd79abb commit b998a53
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 117 deletions.
25 changes: 8 additions & 17 deletions lib/WasmReader/WasmByteCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,9 @@ void WasmBytecodeGenerator::CheckLaneIndex(Js::OpCodeAsmJs op)
}
}

EmitInfo WasmBytecodeGenerator::EnregisterIndex()
EmitInfo WasmBytecodeGenerator::EmitLaneIndex(Js::OpCodeAsmJs op)
{
CheckLaneIndex(op);
const uint offset = GetReader()->m_currentNode.lane.index;
WasmConstLitNode dummy;
dummy.i32 = offset;
Expand All @@ -1291,23 +1292,14 @@ EmitInfo WasmBytecodeGenerator::EnregisterIndex()

EmitInfo WasmBytecodeGenerator::EmitReplaceLaneExpr(Js::OpCodeAsmJs op, const WasmTypes::WasmType* signature) {

CheckLaneIndex(op);
const WasmTypes::WasmType resultType = signature[0];
const WasmTypes::WasmType valueType = signature[1];
EmitInfo valueArg = PopEvalStack();
if (valueArg.type != valueType)
{
throw WasmCompilationException(_u("lane argument type mismatch"));
}

EmitInfo simdArg = PopEvalStack();
EmitInfo valueArg = PopEvalStack(valueType, _u("lane argument type mismatch"));

EmitInfo simdArg = PopEvalStack(WasmTypes::M128, _u("simd argument type mismatch"));
Assert(resultType == WasmTypes::M128);
if (simdArg.type != WasmTypes::M128)
{
throw WasmCompilationException(_u("simd argument type mismatch"));
}

EmitInfo indexInfo = EnregisterIndex();

EmitInfo indexInfo = EmitLaneIndex(op);
Js::RegSlot resultReg = GetRegisterSpace(resultType)->AcquireTmpRegister();
EmitInfo result(resultReg, resultType);

Expand All @@ -1319,7 +1311,6 @@ EmitInfo WasmBytecodeGenerator::EmitReplaceLaneExpr(Js::OpCodeAsmJs op, const Wa
EmitInfo
WasmBytecodeGenerator::EmitExtractLaneExpr(Js::OpCodeAsmJs op, const WasmTypes::WasmType* signature)
{
CheckLaneIndex(op);
WasmTypes::WasmType resultType = signature[0];
WasmTypes::WasmType simdArgType = signature[1];

Expand All @@ -1329,7 +1320,7 @@ WasmBytecodeGenerator::EmitExtractLaneExpr(Js::OpCodeAsmJs op, const WasmTypes::
EmitInfo resultInfo(resultReg, resultType);

//put index into a register to reuse the existing infra in Interpreter and Compiler
EmitInfo indexInfo = EnregisterIndex();
EmitInfo indexInfo = EmitLaneIndex(op);

m_writer->AsmReg3(op, resultReg, simdArgInfo.location, indexInfo.location);
ReleaseLocation(&indexInfo);
Expand Down
2 changes: 1 addition & 1 deletion lib/WasmReader/WasmByteCodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace Wasm
EmitInfo EmitExtractLaneExpr(Js::OpCodeAsmJs op, const WasmTypes::WasmType* signature);
EmitInfo EmitReplaceLaneExpr(Js::OpCodeAsmJs op, const WasmTypes::WasmType* signature);
void CheckLaneIndex(Js::OpCodeAsmJs op);
EmitInfo EnregisterIndex();
EmitInfo EmitLaneIndex(Js::OpCodeAsmJs op);

EmitInfo EmitConst(WasmTypes::WasmType type, WasmConstLitNode cnst);
void EmitLoadConst(EmitInfo dst, WasmConstLitNode cnst);
Expand Down
48 changes: 23 additions & 25 deletions test/wasm.simd/replaceLaneTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@ function assertEquals(expected, actual) {

const INITIAL_SIZE = 1;
const memObj = new WebAssembly.Memory({initial:INITIAL_SIZE});
const arrays = [new Int32Array (memObj.buffer),
new Int16Array (memObj.buffer),
new Int8Array (memObj.buffer),
new Float32Array (memObj.buffer)
];
const arrays = {
"i32x4" : { arr : new Int32Array (memObj.buffer) , len : 4 } ,
"i16x8" : { arr : new Int16Array (memObj.buffer) , len : 8 } ,
"i8x16" : { arr : new Int8Array (memObj.buffer) , len : 16 } ,
"f32x4" : { arr : new Float32Array (memObj.buffer) , len : 4 }
};

const module = new WebAssembly.Module(readbuffer('replace.wasm'));
const instance = new WebAssembly.Instance(module, { "dummy" : { "memory" : memObj } }).exports;

let testIntFloatReplace = function (funcname, splat, val, len) {
let testIntFloatReplace = function (funcname, splat, val) {

let typeIndex = Math.log2(len) - 2;
let arr = arrays [typeIndex];

if (len == 32) { //special case for floats
len = 4;
}
const type = funcname.split('_')[0];
const arr = arrays [type].arr;
const len = arrays [type].len;

for (let i = 0; i < len; i++) {
instance[funcname+i](splat, val);
Expand All @@ -45,22 +43,22 @@ let testIntFloatReplace = function (funcname, splat, val, len) {
}
}

testIntFloatReplace("i32x4_replace", -1, -2147483648, 4);
testIntFloatReplace("i32x4_replace", 7, -1, 4);
testIntFloatReplace("i32x4_replace", 0, 2147483647, 4);
testIntFloatReplace("i32x4_replace", -1, -2147483648);
testIntFloatReplace("i32x4_replace", 7, -1);
testIntFloatReplace("i32x4_replace", 0, 2147483647);

testIntFloatReplace("i16x8_replace", -1, -32768, 8);
testIntFloatReplace("i16x8_replace", 1001, -1, 8);
testIntFloatReplace("i16x8_replace", 0, 32767, 8);
testIntFloatReplace("i16x8_replace", -1, -32768);
testIntFloatReplace("i16x8_replace", 1001, -1);
testIntFloatReplace("i16x8_replace", 0, 32767);

testIntFloatReplace("i8x16_replace", -1, -128, 16);
testIntFloatReplace("i8x16_replace", 100, -1, 16);
testIntFloatReplace("i8x16_replace", 0, 127, 16);
testIntFloatReplace("i8x16_replace", -1, -128);
testIntFloatReplace("i8x16_replace", 100, -1);
testIntFloatReplace("i8x16_replace", 0, 127);

testIntFloatReplace("f32x4_replace", Number.NEGATIVE_INFINITY, 0.125, 32);
testIntFloatReplace("f32x4_replace", 777.0, 1001.0, 32);
testIntFloatReplace("f32x4_replace", -1.0, Number.POSITIVE_INFINITY, 32);
testIntFloatReplace("f32x4_replace", -100.0, 1.7014118346046924e+38, 32);
testIntFloatReplace("f32x4_replace", Number.NEGATIVE_INFINITY, 0.125);
testIntFloatReplace("f32x4_replace", 777.0, 1001.0);
testIntFloatReplace("f32x4_replace", -1.0, Number.POSITIVE_INFINITY);
testIntFloatReplace("f32x4_replace", -100.0, 1.7014118346046924e+38);

if (passed) {
print("Passed");
Expand Down
30 changes: 0 additions & 30 deletions test/wasm.simd/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,28 @@
<compile-flags> -wasm -wasmsimd</compile-flags>
</default>
</test>
<test>
<default>
<files>loadTests.js</files>
<compile-flags> -maic:0 -wasm -wasmsimd</compile-flags>
</default>
</test>
<test>
<default>
<files>storeTests.js</files>
<compile-flags> -wasm -wasmsimd</compile-flags>
</default>
</test>
<test>
<default>
<files>storeTests.js</files>
<compile-flags> -maic:0 -wasm -wasmsimd</compile-flags>
</default>
</test>
<test>
<default>
<files>constTests.js</files>
<compile-flags> -wasm -wasmsimd</compile-flags>
</default>
</test>
<test>
<default>
<files>constTests.js</files>
<compile-flags> -wasm -wasmsimd -maic:0</compile-flags>
</default>
</test>
<test>
<default>
<files>splatNegTests.js</files>
<compile-flags> -wasm -wasmsimd</compile-flags>
</default>
</test>
<test>
<default>
<files>splatNegTests.js</files>
<compile-flags> -wasm -wasmsimd -maic:0</compile-flags>
</default>
</test>
<test>
<default>
<files>replaceLaneTests.js</files>
<compile-flags> -wasm -wasmsimd</compile-flags>
</default>
</test>
<test>
<default>
<files>replaceLaneTests.js</files>
<compile-flags> -wasm -wasmsimd -maic:0</compile-flags>
</default>
</test>
</regress-exe>
84 changes: 40 additions & 44 deletions test/wasm.simd/splatNegTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,22 @@ let check = function(expected, funName, ...args) {

const INITIAL_SIZE = 1;
const memObj = new WebAssembly.Memory({initial:INITIAL_SIZE});
const arrays = [new Int32Array (memObj.buffer),
new Int16Array (memObj.buffer),
new Int8Array (memObj.buffer),
new Float32Array (memObj.buffer)
];
const arrays = {
"i32x4" : { arr : new Int32Array (memObj.buffer) , len : 4 } ,
"i16x8" : { arr : new Int16Array (memObj.buffer) , len : 8 } ,
"i8x16" : { arr : new Int8Array (memObj.buffer) , len : 16 } ,
"f32x4" : { arr : new Float32Array (memObj.buffer) , len : 4 }
};

//SPLAT
const splatModule = new WebAssembly.Module(readbuffer('splat.wasm'));
const splatInstance = new WebAssembly.Instance(splatModule, { "dummy" : { "memory" : memObj } }).exports;

let testSplat = function (funcname, val, len, checkFun) {

let typeIndex = Math.log2(len) - 2;
let arr = arrays [typeIndex];
let testSplat = function (funcname, val) {

if (len == 32) { //special case for floats
len = 4;
}
const type = funcname.split('_')[0];
const arr = arrays [type].arr;
const len = arrays [type].len;

for (let i = 0; i < len; i++) {
arr[i] = val;
Expand All @@ -62,36 +60,34 @@ let testSplat = function (funcname, val, len, checkFun) {

}

testSplat("i32x4_splat", 0, 4);
testSplat("i32x4_splat", -1, 4);
testSplat("i32x4_splat", -2147483648, 4);
testSplat("i32x4_splat", 0);
testSplat("i32x4_splat", -1);
testSplat("i32x4_splat", -2147483648);

testSplat("i16x8_splat", 0, 8);
testSplat("i16x8_splat", -1, 8);
testSplat("i16x8_splat", 32766, 8);
testSplat("i16x8_splat", 0);
testSplat("i16x8_splat", -1);
testSplat("i16x8_splat", 32766);

testSplat("i8x16_splat", 0, 16);
testSplat("i8x16_splat", -1, 16);
testSplat("i8x16_splat", -128, 16);
testSplat("i8x16_splat", 0);
testSplat("i8x16_splat", -1);
testSplat("i8x16_splat", -128);

testSplat("f32x4_splat", 0.125, 32);
testSplat("f32x4_splat", 1001.0, 32);
testSplat("f32x4_splat", Number.POSITIVE_INFINITY, 32);
testSplat("f32x4_splat", 1.7014118346046924e+38, 32);
testSplat("f32x4_splat", 0.125);
testSplat("f32x4_splat", 1001.0);
testSplat("f32x4_splat", Number.POSITIVE_INFINITY);
testSplat("f32x4_splat", 1.7014118346046924e+38);

//NEG
const module = new WebAssembly.Module(readbuffer('neg.wasm'));
const instance = new WebAssembly.Instance(module, { "dummy" : { "memory" : memObj } }).exports;

let testNeg = function (funcname, val, len) {

let typeIndex = Math.log2(len) - 2;
let arr = arrays [typeIndex];

if (len == 32) { //special case for floats
len = 4;
}
let testNeg = function (funcname, val) {

const type = funcname.split('_')[0];
const arr = arrays [type].arr;
const len = arrays [type].len;

for (let i = 0; i < len; i++) {
arr[i] = val;
}
Expand All @@ -103,21 +99,21 @@ let testNeg = function (funcname, val, len) {
}
};

testNeg("i32x4_neg", 0, 4);
testNeg("i32x4_neg", 1, 4);
testNeg("i32x4_neg", 2147483647, 4);
testNeg("i32x4_neg", 0);
testNeg("i32x4_neg", 1);
testNeg("i32x4_neg", 2147483647);

testNeg("i16x8_neg", 0, 8);
testNeg("i16x8_neg", 1, 8);
testNeg("i16x8_neg", 32767, 8);
testNeg("i16x8_neg", 0);
testNeg("i16x8_neg", 1);
testNeg("i16x8_neg", 32767);

testNeg("i8x16_neg", 0, 16);
testNeg("i8x16_neg", 1, 16);
testNeg("i8x16_neg", 127, 16);
testNeg("i8x16_neg", 0);
testNeg("i8x16_neg", 1);
testNeg("i8x16_neg", 127);

testNeg("f32x4_neg", 0.0, 32);
testNeg("f32x4_neg", 1.0, 32);
testNeg("f32x4_neg", 1000.0, 32);
testNeg("f32x4_neg", 0.0);
testNeg("f32x4_neg", 1.0);
testNeg("f32x4_neg", 1000.0);
testNeg("f32x4_neg", Number.POSITIVE_INFINITY, 32);

if (passed) {
Expand Down

0 comments on commit b998a53

Please sign in to comment.