Bug 136261

Summary: ARM32 iOS: JSC Test math.js fails
Product: WebKit Reporter: Michael Saboff <msaboff>
Component: JavaScriptCoreAssignee: Michael Saboff <msaboff>
Status: RESOLVED FIXED    
Severity: Normal    
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch ggaren: review+

Description Michael Saboff 2014-08-26 11:38:20 PDT
All variants of math.js fail the Math.ceil(Number.MIN_VALUE) and Math.floor(-Number.MIN_VALUE) test.  For example:

jsc-layout-tests.yaml/js/script-tests/math.js.layout: --- ../.tests/jsc-layout-tests.yaml/js/math-expected.txt	2014-08-26 09:20:39.000000000 -0700
jsc-layout-tests.yaml/js/script-tests/math.js.layout: +++ ../jsc-layout-tests.yaml/js/script-tests/math.js.layout.out	2014-08-26 09:57:11.000000000 -0700
jsc-layout-tests.yaml/js/script-tests/math.js.layout: @@ -53,7 +53,7 @@
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.ceil(-1) is -1
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.ceil(1.1) is 2
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.ceil(-1.1) is -1
jsc-layout-tests.yaml/js/script-tests/math.js.layout: -PASS Math.ceil(Number.MIN_VALUE) is 1
jsc-layout-tests.yaml/js/script-tests/math.js.layout: +FAIL Math.ceil(Number.MIN_VALUE) should be 1. Was 0.
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.ceil(-Number.MIN_VALUE) is -0
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.ceil(Number.MAX_VALUE) is Number.MAX_VALUE
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.ceil(-Number.MAX_VALUE) is -Number.MAX_VALUE
jsc-layout-tests.yaml/js/script-tests/math.js.layout: @@ -78,7 +78,7 @@
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.floor(1.1) is 1
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.floor(-1.1) is -2
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.floor(Number.MIN_VALUE) is 0
jsc-layout-tests.yaml/js/script-tests/math.js.layout: -PASS Math.floor(-Number.MIN_VALUE) is -1
jsc-layout-tests.yaml/js/script-tests/math.js.layout: +FAIL Math.floor(-Number.MIN_VALUE) should be -1. Was -0.
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.floor(Number.MAX_VALUE) is Number.MAX_VALUE
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.floor(-Number.MAX_VALUE) is -Number.MAX_VALUE
jsc-layout-tests.yaml/js/script-tests/math.js.layout:  PASS Math.floor(Infinity) is Infinity
Comment 1 Michael Saboff 2014-08-28 15:02:28 PDT
This happens on 32 bit ARM code on iOS, even if that code is executed on an ARM64 device.

Number.MIN_VALUE  is coded as a constant in NumberConstructor.cpp as  5E-324.  The issue seems to be that the ceil() and floor() library routines on iOS return the wrong answer for 5E-324 and -5E-324 respectively.  I verified this with a test program.  I checked to see if the issue was the flush to zero of denormalized numbers in ARM, but the FZ bit of the FPSCR register is 0 (Flush-to-zero disabled).  That bit is cleared in jsc.cpp around line 1100.
Comment 2 Michael Saboff 2014-09-04 18:32:45 PDT
Created attachment 237666 [details]
Patch
Comment 3 Geoffrey Garen 2014-09-05 11:55:34 PDT
Comment on attachment 237666 [details]
Patch

r=me
Comment 4 Michael Saboff 2014-09-05 13:08:19 PDT
Committed r173330: <http://trac.webkit.org/changeset/173330>