fix for i64 mode 1 conversion of double to i64

This commit is contained in:
Alon Zakai 2011-11-27 12:45:00 -08:00
Родитель 17ee516bcd
Коммит b61f32f98d
2 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -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] || ' +

Просмотреть файл

@ -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