Skip to content

Commit 36d3bc8

Browse files
committed
update simd coercion handling in optimizer to latest simd spec; 1.29.10
1 parent 8ff1ac1 commit 36d3bc8

6 files changed

Lines changed: 33 additions & 11 deletions

File tree

emscripten-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1.29.9
1+
1.29.10
22

tests/optimizer/simd-output.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function a(x, y) {
2+
x = SIMD_int32x4_check(x);
3+
y = SIMD_float32x4_check(y);
4+
var z = SIMD_float32x4(0, 0, 0, 0);
5+
work(z);
6+
}
7+

tests/optimizer/simd.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function a(x, y) {
2+
x = SIMD_int32x4_check(x);
3+
y = SIMD_float32x4_check(y);
4+
var z = SIMD_float32x4(0, 0, 0, 0);
5+
work(z);
6+
}
7+
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a"]
8+

tests/test_other.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,8 @@ def test_js_optimizer(self):
19841984
['asm', 'ensureLabelSet']),
19851985
(path_from_root('tests', 'optimizer', '3154.js'), open(path_from_root('tests', 'optimizer', '3154-output.js')).read(),
19861986
['asm', 'eliminate', 'registerize', 'asmLastOpts', 'last']),
1987+
(path_from_root('tests', 'optimizer', 'simd.js'), open(path_from_root('tests', 'optimizer', 'simd-output.js')).read(),
1988+
['asm', 'eliminate']), # eliminate, just enough to trigger asm normalization/denormalization
19871989
]:
19881990
print input, passes
19891991

tools/js-optimizer.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,9 +2148,11 @@ function detectType(node, asmInfo, inVarDef) {
21482148
case 'call': {
21492149
if (node[1][0] === 'name') {
21502150
switch (node[1][1]) {
2151-
case 'Math_fround': return ASM_FLOAT;
2152-
case 'SIMD_float32x4': return ASM_FLOAT32X4;
2153-
case 'SIMD_int32x4': return ASM_INT32X4;
2151+
case 'Math_fround': return ASM_FLOAT;
2152+
case 'SIMD_float32x4':
2153+
case 'SIMD_float32x4_check': return ASM_FLOAT32X4;
2154+
case 'SIMD_int32x4':
2155+
case 'SIMD_int32x4_check': return ASM_INT32X4;
21542156
default: break;
21552157
}
21562158
}
@@ -2208,8 +2210,8 @@ function makeAsmCoercion(node, type) {
22082210
case ASM_INT: return ['binary', '|', node, ['num', 0]];
22092211
case ASM_DOUBLE: return ['unary-prefix', '+', node];
22102212
case ASM_FLOAT: return ['call', ['name', 'Math_fround'], [node]];
2211-
case ASM_FLOAT32X4: return ['call', ['name', 'SIMD_float32x4'], [node]];
2212-
case ASM_INT32X4: return ['call', ['name', 'SIMD_int32x4'], [node]];
2213+
case ASM_FLOAT32X4: return ['call', ['name', 'SIMD_float32x4_check'], [node]];
2214+
case ASM_INT32X4: return ['call', ['name', 'SIMD_int32x4_check'], [node]];
22132215
case ASM_NONE:
22142216
default: return node; // non-validating code, emit nothing XXX this is dangerous, we should only allow this when we know we are not validating
22152217
}
@@ -2238,7 +2240,7 @@ function makeAsmVarDef(v, type) {
22382240
case ASM_INT32X4: {
22392241
return [v, ['call', ['name', 'SIMD_int32x4'], [['num', 0], ['num', 0], ['num', 0], ['num', 0]]]];
22402242
}
2241-
default: throw 'wha? ' + JSON.stringify([node, type]) + new Error().stack;
2243+
default: throw 'wha? ' + JSON.stringify([v, type]) + new Error().stack;
22422244
}
22432245
}
22442246

tools/optimizer/optimizer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ typedef std::vector<IString> StringVec;
1414

1515
Ref doc, extraInfo;
1616

17+
IString SIMD_INT32X4_CHECK("SIMD_int32x4_check"),
18+
SIMD_FLOAT32X4_CHECK("SIMD_float32x4_check");
19+
1720
//==================
1821
// Infrastructure
1922
//==================
@@ -352,8 +355,8 @@ AsmType detectType(Ref node, AsmData *asmData, bool inVarDef) {
352355
if (node[1][0] == NAME) {
353356
IString name = node[1][1]->getIString();
354357
if (name == MATH_FROUND) return ASM_FLOAT;
355-
else if (name == SIMD_FLOAT32X4) return ASM_FLOAT32X4;
356-
else if (name == SIMD_INT32X4) return ASM_INT32X4;
358+
else if (name == SIMD_FLOAT32X4 || name == SIMD_FLOAT32X4_CHECK) return ASM_FLOAT32X4;
359+
else if (name == SIMD_INT32X4 || name == SIMD_INT32X4_CHECK) return ASM_INT32X4;
357360
}
358361
return ASM_NONE;
359362
} else if (node[0] == CONDITIONAL) {
@@ -508,8 +511,8 @@ Ref makeAsmCoercion(Ref node, AsmType type) {
508511
case ASM_INT: return make3(BINARY, OR, node, makeNum(0));
509512
case ASM_DOUBLE: return make2(UNARY_PREFIX, PLUS, node);
510513
case ASM_FLOAT: return make2(CALL, makeName(MATH_FROUND), &(makeArray())->push_back(node));
511-
case ASM_FLOAT32X4: return make2(CALL, makeName(SIMD_FLOAT32X4), &(makeArray())->push_back(node));
512-
case ASM_INT32X4: return make2(CALL, makeName(SIMD_INT32X4), &(makeArray())->push_back(node));
514+
case ASM_FLOAT32X4: return make2(CALL, makeName(SIMD_FLOAT32X4_CHECK), &(makeArray())->push_back(node));
515+
case ASM_INT32X4: return make2(CALL, makeName(SIMD_INT32X4_CHECK), &(makeArray())->push_back(node));
513516
case ASM_NONE:
514517
default: return node; // non-validating code, emit nothing XXX this is dangerous, we should only allow this when we know we are not validating
515518
}

0 commit comments

Comments
 (0)