Closed Bug 556149 Opened 14 years ago Closed 14 years ago

Math.sin() and Math.cos() return incorrect results for NaN and infinities on iPhone

Categories

(Tamarin Graveyard :: Virtual Machine, defect, P3)

Other
macOS
defect

Tracking

(Not tracked)

VERIFIED FIXED
flash10.1

People

(Reporter: stan, Assigned: lhansen)

References

Details

Attachments

(1 file, 1 obsolete file)

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8
Build Identifier: Tamarin Redux, March '10

The runtime libraries on the iPhone return incorrect values for sin() and cos() of NaN and infinites.

The problem appears to be limited to those library routines, tan, exp, and the arc-etc routines seem to behave correctly.

The problem is reproducible only on the actual device and not in the simulator.

Reproducible: Always

Steps to Reproduce:
Run avmshell tests e15_8_2_7 (cos) and e15_8_2_16 (sin) on the iPhone
Actual Results:  
Math.sin() and Math.cos() return meaningless values in these cases

Expected Results:  
should return NaN.

Watson BUG# 2471259
ATS test 9658
Attached patch Proposed patch (obsolete) — Splinter Review
Patch corresponding to Perforce changelist 655292
Attachment #436078 - Flags: review?(stejohns)
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Assignee: nobody → stejohns
Flags: flashplayer-qrb+
Priority: -- → P3
Target Milestone: --- → flash10.1
Comment on attachment 436078 [details] [diff] [review]
Proposed patch

questions:
- follow VMCFG convention?
- should we have a platform dir for iphone?
Attachment #436078 - Attachment is patch: true
Attachment #436078 - Flags: review?(wmaddox)
Summary: Math.sin() and Math.cos() retuyrn incorrect results for NaN and infinities on iPhone → Math.sin() and Math.cos() return incorrect results for NaN and infinities on iPhone
Possibly, dunno... this is a runtime library specific bug workaround. There doesn't seem to be a convention for that, but I don't see this as lining up along a platform-qualities axis (VMCFG_UNALIGNED_INT_ACCESS) unless that would be something like VMCFG_SDK_HAS_J_RANDOM_BUG. Tying it to a platform in the ifdef makes the issue really easy to understand in the source code. One-stop shopping: "Oh! This SDK has that bug."

Duping the entire file to work around a (one hopes!) temporary bug seems like a bad precedent. "It's a UNIX system! I know this!"

Anyway, happy to take any specific guidance or if you'd like to change it when integrating, that'd be cool too.  But if the ifdef changes we'll need to know because we have to be sure to define it.
This looks reasonable if in fact the bug is strictly in the handling 
of NaNs and infinities.  Please verify that correct results are given
for other values, including large ones.  There is a bug on WinMo that
is worked around in MathUtilsWin.cpp, and might possibly be related to
the ARM processor or to vendor-supplied libraries.
Assignee: stejohns → wmaddox
Comment on attachment 436078 [details] [diff] [review]
Proposed patch

Conceptually this is fine, but AVMSYSTEM_IPHONE isn't defined anywhere. To date we've been using "AVMSYSTEM_MAC && AVMSYSTEM_ARM" to detect CocoaTouch targets.
Attachment #436078 - Flags: review?(stejohns) → review-
From offline discussion, it sounds like "MAC && ARM" isn't the ideal detection strategy for iPhone; Stan is going to resubmit a patch that includes an explicit AVMSYSTEM_IPHONE (or some such) in avmfeatures.as
It's worth adding that there is almost certainly code in VM/Flash/AIR that assumes that the various "_MAC" compile flags are set for iPhone/CocoaTouch targets; thus I'm skeptical as to whether "AVMSYSTEM_IPHONE" could/should be added as a toplevel config, or as a subtype of mac...
(In reply to comment #3)
> this is a runtime library specific bug workaround. There
> doesn't seem to be a convention for that, but I don't see this as lining up
> along a platform-qualities axis (VMCFG_UNALIGNED_INT_ACCESS) unless that would
> be something like VMCFG_SDK_HAS_J_RANDOM_BUG. Tying it to a platform in the
> ifdef makes the issue really easy to understand in the source code. One-stop
> shopping: "Oh! This SDK has that bug."

Well... the SDK has that bug in that version.

A refinement of the feature system I've been hoping to introduce for a while now is a "tweaks" system.  Tweaks are features that have sane default values and that apply to exactly these kinds of problems; the point is just to expose the fact that a tweak is available and not hide it deep in a file with an #ifdef _IPHONE.

Eg,

  <feature>
    <name>AVMTWEAK_IPHONE_HW_SIN_COS_NAN_BUG</name>
    <default>false</default>
    <desc> Iphone hardware version x, y, z have bug in sin and cos where
           they do not handle NaN properly and we must work around it in
           software. </desc>
    ...
  </feature>

would be false everywhere by default (so config files would not have to manually record the setting) but would be set to true for iphone builds.  (I'm not 100% sure that a default setting is a good idea, but the high bit of value for tweaks is the exposure in avmfeatures.as probably.)

Possibly it is too heavyweight a change to do something about this for 10.1 at this point, even though most of the changes would be in the avmfeatures.as script, not in the C++ code itself.
Assignee: wmaddox → lhansen
Attachment #436078 - Flags: review?(wmaddox)
Depends on: 557611
Attached patch PatchSplinter Review
Same functionality with a different #ifdef based on a newly introduced tweak; requires the presence of the tweaks system of course.  See blocking bug.
Attachment #436078 - Attachment is obsolete: true
Attachment #437369 - Flags: review?(stejohns)
Attachment #437369 - Flags: review?(stejohns) → review+
tamarin-redux-argo changeset:   3945:aaea0de6a778
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
QA Contact: vm → cpeyer
Flags: in-testsuite?
Verified fixed per Stan Switzer
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: