aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-07 15:49:57 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-07 15:49:57 -0800
commit116eb79d55fd43dfccc8652d530924d02bbd7d58 (patch)
tree02f962eed9d811e6fa104510b6b4f9d66928548e
parent7d249fbeb1ffea43e705f180a67abdfbe2fbae42 (diff)
ensure float literals are hinted as floats in asm
-rw-r--r--src/parseTools.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index a4a5cbac..bcae838a 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -997,6 +997,15 @@ function makeVarDef(js) {
return js;
}
+function asmEnsureFloat(value, type) { // ensures that a float type has either 5.5 (clearly a float) or +5 (float due to asm coercion)
+ if (!ASM_JS) return value;
+ if (!isIntImplemented(type) && isNumber(value) && value.toString().indexOf('.') < 0) {
+ return '(+(' + value + '))';
+ } else {
+ return value;
+ }
+}
+
function asmInitializer(type, impl) {
if (isIntImplemented(type)) {// || (impl && impl == 'VAR_EMULATED')) {
return '0';
@@ -2097,7 +2106,7 @@ function processMathop(item) {
// then unsigning that i32... which would give something huge.
case 'zext': case 'fpext': case 'sext': return idents[0];
case 'fptrunc': return idents[0];
- case 'select': return idents[0] + ' ? ' + idents[1] + ' : ' + idents[2];
+ case 'select': return idents[0] + ' ? ' + asmEnsureFloat(idents[1], item.type) + ' : ' + asmEnsureFloat(idents[2], item.type);
case 'ptrtoint': case 'inttoptr': {
var ret = '';
if (QUANTUM_SIZE == 1) {