ibmruntimes / v8ppc

Port of Google V8 javascript engine to PowerPC®
Other
94 stars 19 forks source link

EmitVFPTruncate producing incorrect result #68

Closed mtbrandy closed 11 years ago

mtbrandy commented 11 years ago

Simple test case:

$ cat test.js

function test(x) { 
  var y = (1 << 30) + 6; 
  var z = x - y; 
  print(x + " - " + y + " = " + z); 
} 

test(0); 
test(0); 

$ out/ppc.debug/d8 test.js

0 - 1073741830 = -1073741830 
0 - 1073741830 = -1073741824 
mtbrandy commented 11 years ago

I don't think frsp is what we want here. That instruction converts from double to single precision, when what we really need is to remove the fraction (i.e. round down to the nearest whole number).

mtbrandy commented 11 years ago

Assigning this to Peng since it seems like it overlaps with her issue #67.

mtbrandy commented 11 years ago

Donald will take a look.

mtbrandy commented 11 years ago

The following simple tests demonstrate a problem that may or may not be related:

$ cat test2.js

function test(x) { 
  y = x % 1; 
  print(x + " % 1 = " + y); 
} 

test(0x40000000); 
test(0x40000000); 
test(0x40000000); 

$ out/ppc.debug/d8 test2.js

1073741824 % 1 = 0 
1073741824 % 1 = 2.64990441e-315 
1073741824 % 1 = 2.64990441e-315 

$ cat test3.js

function test(x) { 
  y = x % 1; 
  print(x + " % 1 = " + y); 
} 

test(0xffffffff); 
test(0xffffffff); 
test(0xffffffff); 

$ out/ppc.debug/d8 test3.js

4294967295 % 1 = 0 
4294967295 % 1 = 2.300997624e-315 
4294967295 % 1 = 2.300997624e-315 
mtbrandy commented 11 years ago

Commit 2aeeee2a498ecfa1308dd9e178273cfebbb86611 fixes the first to tests, but not the 3rd. I'll open a separate issue since it's not clear that it's related.