Monorail Project: v8 Issues People Development process History Sign in
New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.
Issue 2928 ARM and MIPS simulator FP operation precision is wrong on Linux
Starred by 3 users Project Member Reported by pal...@homejinni.com, Oct 7 2013 Back to list
Status: Available
Owner: ----
Cc:
HW: ----
OS: ----
Priority: Medium
Type: Bug


Sign in to add a comment
The default 387 FPU precision is 80-bit (extended) on Linux, therefore the FP operations in the simulator computes slightly different results, than a real ARM or MIPS device.

I've created a small javascript test, which tests the precision:


function precisionTest() {
  // Max value of a 64-bit double (2^53 + 2)
  var maxnum = 9007199254740994.0;
  var smallnum = 1.0 - 1/65536.0;

  var result = maxnum + smallnum;
  print("Result: " + result);

  var diff = result - maxnum;
  print("Diff: " + diff);

  assertEquals(9007199254740994.0, result);
  assertEquals(0, diff);
}

precisionTest();


Result on ARM simulator:

$ out/arm.release/d8 test/mjsunit/mjsunit.js precision_test.js 
Result: 9007199254740996
Diff: 2
test/mjsunit/mjsunit.js:174: Failure: expected <9007199254740996> found <9007199254740994>


MIPS simulator:

$ out/mipsel.release/d8 test/mjsunit/mjsunit.js precision_test.js 
Result: 9007199254740996
Diff: 2
test/mjsunit/mjsunit.js:174: Failure: expected <9007199254740996> found <9007199254740994>


ARM HW (Snapdragon 600 Android):

shell@android:/data/local/tmp/v8 $ out/android_arm.release/d8 test/mjsunit/mjsunit.js precision_test.js
Result: 9007199254740994
Diff: 0


MIPS HW (Sigma 8911):

$ out/mipsel.release/d8 test/mjsunit/mjsunit.js precision_test.js 
Result: 9007199254740994
Diff: 0


I've uploaded a CL for this issue (https://codereview.chromium.org/24067002/), which explicitly set the 387 FPU precision mode to 64-bit double, but as it turned out, the libm library requires extended precision, otherwise the pow function returns very inaccurate result (http://www.sourceware.org/bugzilla/show_bug.cgi?id=706).

Another solution would be to force the g++ compiler to use sse2 instructions for FP operations (-msse2 -mfpmath=sse). Unfortunately, it seems that this solution also does not solve all issues, because most Linux distribution (Ubuntu 12.04 for example) compiles libm for 387 FPU, therefore the libm functions (sqrt, pow, exp, etc.) would still use the 387 FPU operations with extended precision.
 
precision_test.js
354 bytes View Download
Project Member Comment 1 by pal...@homejinni.com, Oct 8 2013
List of failing tests on simulator on Linux due to extended precision:

ARM:

=== benchmarks/sunspider/3d-raytrace ===                                       
/data/palfia/v8/test/benchmarks/sunspider/3d-raytrace.js:446: Error: bad result: expected length 20970 but got 20969
Error: bad result: expected length " + expectedLength + " but got " + testOutp
                                                                    ^
Command: /data/palfia/v8/out/arm.release/d8 --test --nobreak-on-abort --nodead-code-elimination --nofold-constants /data/palfia/v8/test/benchmarks/sunspider/3d-raytrace.js
=== benchmarks/sunspider/access-nbody ===                           
/data/palfia/v8/test/benchmarks/sunspider/access-nbody.js:173: ERROR: bad result: expected -1.3524862408537381 but got -1.352486240853738
    throw "ERROR: bad result: expected " + expected + " but got " + ret;
                                                                  ^
Command: /data/palfia/v8/out/arm.release/d8 --test --nobreak-on-abort --nodead-code-elimination --nofold-constants /data/palfia/v8/test/benchmarks/sunspider/access-nbody.js
=== benchmarks/sunspider/math-partial-sums ===                           
/data/palfia/v8/test/benchmarks/sunspider/math-partial-sums.js:43: ERROR: bad result: expected 60.08994194659945 but got 60.089941946599446
    throw "ERROR: bad result: expected " + expected + " but got " + total;
                                                                  ^
Command: /data/palfia/v8/out/arm.release/d8 --test --nobreak-on-abort --nodead-code-elimination --nofold-constants /data/palfia/v8/test/benchmarks/sunspider/math-partial-sums.js


MIPS:

=== benchmarks/sunspider/3d-cube ===                                           
/data/palfia/v8/test/benchmarks/sunspider/3d-cube.js:340: Error: bad vector sum for CubeSize = 20; expected 2889.0000000000045 but got 2889.0000000000023
ize = " + CubeSize + "; expected " + validation[CubeSize] + " but got " + sum;
                                                                        ^
Command: /data/palfia/v8/out/mipsel.release/d8 --test --nobreak-on-abort --nodead-code-elimination --nofold-constants /data/palfia/v8/test/benchmarks/sunspider/3d-cube.js
=== benchmarks/sunspider/3d-raytrace ===                    
/data/palfia/v8/test/benchmarks/sunspider/3d-raytrace.js:446: Error: bad result: expected length 20970 but got 20661
Error: bad result: expected length " + expectedLength + " but got " + testOutp
                                                                    ^
Command: /data/palfia/v8/out/mipsel.release/d8 --test --nobreak-on-abort --nodead-code-elimination --nofold-constants /data/palfia/v8/test/benchmarks/sunspider/3d-raytrace.js
=== benchmarks/sunspider/access-nbody ===                           
/data/palfia/v8/test/benchmarks/sunspider/access-nbody.js:173: ERROR: bad result: expected -1.3524862408537381 but got -1.352486240853738
    throw "ERROR: bad result: expected " + expected + " but got " + ret;
                                                                  ^
Command: /data/palfia/v8/out/mipsel.release/d8 --test --nobreak-on-abort --nodead-code-elimination --nofold-constants /data/palfia/v8/test/benchmarks/sunspider/access-nbody.js
=== benchmarks/sunspider/math-partial-sums ===                           
/data/palfia/v8/test/benchmarks/sunspider/math-partial-sums.js:43: ERROR: bad result: expected 60.08994194659945 but got 60.089941946599446
    throw "ERROR: bad result: expected " + expected + " but got " + total;
                                                                  ^
Command: /data/palfia/v8/out/mipsel.release/d8 --test --nobreak-on-abort --nodead-code-elimination --nofold-constants /data/palfia/v8/test/benchmarks/sunspider/math-partial-sums.js

Project Member Comment 2 by habl...@google.com, Apr 29 2015
Status: Available
Sign in to add a comment