aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-08-11 21:57:15 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-08-11 21:57:15 -0700
commit8cb83003709aa90a3410b6352552342ec97d5116 (patch)
tree1b8cb216f7f9bc3b2bba5799e1d8261b28b6513b /src
parent5bb74d2c5ed57a7b52e1a3d01404edfb7a9945ea (diff)
experimental toFloat32 option
Diffstat (limited to 'src')
-rw-r--r--src/parseTools.js17
-rw-r--r--src/preamble.js7
-rw-r--r--src/settings.js1
3 files changed, 20 insertions, 5 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index b655d13e..f11c867a 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -2020,6 +2020,13 @@ function makeIsNaN(value) {
return 'isNaN(' + value + ')';
}
+function makeFloat(value, type) {
+ if (TO_FLOAT32 && type == 'float') {
+ return 'Math.toFloat32(' + value + ')';
+ }
+ return value;
+}
+
// fptoui and fptosi are not in these, because we need to be careful about what we do there. We can't
// just sign/unsign the input first.
var UNSIGNED_OP = set('udiv', 'urem', 'uitofp', 'zext', 'lshr');
@@ -2275,11 +2282,11 @@ function processMathop(item) {
return idents[0] + ' >>> ' + idents[1];
}
// basic float ops
- case 'fadd': return getFastValue(idents[0], '+', idents[1], item.type);
- case 'fsub': return getFastValue(idents[0], '-', idents[1], item.type);
- case 'fdiv': return getFastValue(idents[0], '/', idents[1], item.type);
- case 'fmul': return getFastValue(idents[0], '*', idents[1], item.type);
- case 'frem': return getFastValue(idents[0], '%', idents[1], item.type);
+ case 'fadd': return makeFloat(getFastValue(idents[0], '+', idents[1], item.type), item.type);
+ case 'fsub': return makeFloat(getFastValue(idents[0], '-', idents[1], item.type), item.type);
+ case 'fdiv': return makeFloat(getFastValue(idents[0], '/', idents[1], item.type), item.type);
+ case 'fmul': return makeFloat(getFastValue(idents[0], '*', idents[1], item.type), item.type);
+ case 'frem': return makeFloat(getFastValue(idents[0], '%', idents[1], item.type), item.type);
case 'uitofp': case 'sitofp': return asmCoercion(idents[0], 'double', op[0]);
case 'fptoui': case 'fptosi': return makeRounding(idents[0], bitsLeft, op === 'fptosi', true);
diff --git a/src/preamble.js b/src/preamble.js
index 95bf2dc2..0f3f52c9 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -853,6 +853,13 @@ Math['imul'] = function(a, b) {
#endif
Math.imul = Math['imul'];
+#if TO_FLOAT32
+if (!Math['toFloat32']) Math['toFloat32'] = function(x) {
+ return x;
+};
+Math.toFloat32 = Math['toFloat32'];
+#endif
+
// A counter of dependencies for calling run(). If we need to
// do asynchronous work before running, increment this and
// decrement it. Incrementing must happen in a place like
diff --git a/src/settings.js b/src/settings.js
index 3515091d..3ecac040 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -108,6 +108,7 @@ var PRECISE_I64_MATH = 1; // If enabled, i64 addition etc. is emulated - which i
var PRECISE_I32_MUL = 1; // If enabled, i32 multiplication is done with full precision, which means it is
// correct even if the value exceeds the JS double-integer limit of ~52 bits (otherwise,
// rounding will occur above that range).
+var TO_FLOAT32 = 0; // Use Math.toFloat32
var CLOSURE_ANNOTATIONS = 0; // If set, the generated code will be annotated for the closure
// compiler. This potentially lets closure optimize the code better.