aboutsummaryrefslogtreecommitdiff
path: root/src/parseTools.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-11 11:41:18 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-11 11:41:18 -0800
commit26efdc2c8f5e7efd0898e966d58a783fdc7395ac (patch)
treefacfe273396a007a020be6e2da2594b6672ed198 /src/parseTools.js
parent9ac1fc4a8489e58bfa0152550d1707d9ec81c991 (diff)
perform asm multiply in getFastValue, so it is used everywhere it needs to be
Diffstat (limited to 'src/parseTools.js')
-rw-r--r--src/parseTools.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 03cd346e..3b03fdf5 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1025,6 +1025,15 @@ function asmCoercion(value, type) {
}
}
+function asmMultiply(a, b) {
+ // special-case: there is no integer multiply in asm, because there is no true integer
+ // multiply in JS. While we wait for Math.imul, do double multiply
+ if (USE_MATH_IMUL) {
+ return 'Math.imul(' + a + ',' + b + ')';
+ }
+ return '(~~(+' + a + ' * +' + b + '))';
+}
+
function makeGetTempDouble(i) { // TODO: Support other than i32
return makeGetValue('tempDoublePtr', Runtime.getNativeTypeSize('i32')*i, 'i32');
}
@@ -1341,6 +1350,9 @@ function getFastValue(a, op, b, type) {
return '(' + a + '<<' + shifts + ')';
}
}
+ if (ASM_JS) {
+ return asmMultiply(a, b); // unoptimized multiply, do it using asm.js's special multiply operation
+ }
} else {
if (a == '0') {
return '0';
@@ -2010,15 +2022,11 @@ function processMathop(item) {
Types.preciseI64MathUsed = true;
return '(i64Math' + (ASM_JS ? '_' : '.') + 'multiply(' + idents[0] + ',0,' + idents[1] + ',0),' + makeGetValue('tempDoublePtr', 0, 'i32') + ')';
} else {
- if (ASM_JS) {
- // special-case: there is no integer multiply in asm, because there is no true integer
- // multiply in JS. While we wait for Math.imul, do double multiply
- if (USE_MATH_IMUL) {
- return 'Math.imul(' + idents[0] + ',' + idents[1] + ')';
- }
- return '(~~(+' + idents[0] + ' * +' + idents[1] + '))';
+ var ret = getFastValue(idents[0], '*', idents[1], item.type);
+ if (!ASM_JS) {
+ ret = handleOverflow(ret, bits); // multiply does not need overflow corrections in asm, since it is special-cased
}
- return handleOverflow(getFastValue(idents[0], '*', idents[1], item.type), bits);
+ return ret;
}
}
case 'urem': case 'srem': return getFastValue(idents[0], '%', idents[1], item.type);