aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-27 12:45:00 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-11-27 12:45:00 -0800
commitb61f32f98dbedccc518d7dcabbf6f4505020cfee (patch)
treec506ac3929ab3bc4d5b700e5e3df51dae3c2a0ce
parent17ee516bcd20561dc1badef8a6812f7d1d99a550 (diff)
fix for i64 mode 1 conversion of double to i64
-rw-r--r--src/parseTools.js5
-rw-r--r--tests/runner.py11
2 files changed, 13 insertions, 3 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 57765ac2..3b4e8df4 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -576,7 +576,7 @@ function makeI64(low, high) {
// Splits a number (an integer in a double, possibly > 32 bits) into an I64_MODE 1 i64 value.
// Will suffer from rounding. margeI64 does the opposite.
-// TODO: optimize I64 calcs
+// TODO: optimize I64 calcs. For example, saving their parts as signed 32 as opposed to unsigned would help
function splitI64(value) {
assert(I64_MODE == 1);
return makeInlineCalculation(makeI64('VALUE>>>0', 'Math.floor(VALUE/4294967296)'), value, 'tempBigInt');
@@ -1590,7 +1590,7 @@ function processMathop(item) { with(item) {
return makeInlineCalculation('VALUE-VALUE%1', value, 'tempBigInt');
}
- if ((type == 'i64' || paramTypes[0] == 'i64' || paramTypes[1] == 'i64') && I64_MODE == 1) {
+ if ((type == 'i64' || paramTypes[0] == 'i64' || paramTypes[1] == 'i64' || ident2 == '(i64)') && I64_MODE == 1) {
function warnI64_1() {
warnOnce('Arithmetic on 64-bit integers in mode 1 is rounded and flaky, like mode 0, but much slower!');
}
@@ -1618,6 +1618,7 @@ function processMathop(item) { with(item) {
ident1 + '[1] >>> ' + ident2 + ']';
}
case 'uitofp': case 'sitofp': return ident1 + '[0] + ' + ident1 + '[1]*4294967296';
+ case 'fptoui': case 'fptosi': return splitI64(ident1);
case 'icmp': {
switch (variant) {
case 'uge': case 'sge': return ident1 + '[1] >= ' + ident2 + '[1] && (' + ident1 + '[1] > ' + ident2 + '[1] || ' +
diff --git a/tests/runner.py b/tests/runner.py
index 0eff4c11..db8d3637 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -459,6 +459,14 @@ if 'benchmark' not in str(sys.argv):
// global structs with i64s
printf("*%d,%Ld*\n*%d,%Ld*\n", iub[0].c, iub[0].d, iub[1].c, iub[1].d);
+ // Math mixtures with doubles
+ {
+ uint64_t a = 5;
+ double b = 6.8;
+ uint64_t c = a * b;
+ printf("*prod:%llu*\n*%d,%d,%d*", c, (int)&a, (int)&b, (int)&c); // printing addresses prevents optimizations
+ }
+
// Basic (rounded, for now) math. Just check compilation.
int64_t a = 0x1234def123450789ULL;
a--; if (truthy()) a--; // confuse optimizer
@@ -472,7 +480,8 @@ if 'benchmark' not in str(sys.argv):
self.do_run(src, '*1311918518731868200\n0,0,0,1,1\n1,0,1,0,1*\n*245127260211081*\n*245127260209443*\n' +
'*18446744073709552000*\n*576460752303423500*\n' +
'm1: 127\n*123*\n*127*\n' +
- '*55,17179869201*\n*122,25769803837*\n')
+ '*55,17179869201*\n*122,25769803837*\n' +
+ '*prod:34*\n')
Settings.CORRECT_SIGNS = 1