Skip to content

Conversation

@acoates-ms
Copy link
Contributor

@acoates-ms acoates-ms commented Jun 7, 2022

Description

Port #8676 to main.

There was a hope to avoid this fork in main, with #8725, but that ended up hitting the original issue of why we turned on strict mode in the first place. I'd rather get a fix in so that we dont ship this issue again in upcoming releases. When we get a fix for the strict mode, we could remove this patch.

Microsoft Reviewers: Open in CodeFlow

htpiv and others added 2 commits June 7, 2022 10:14
* Change the definition of YGUndefined from NAN (contra the comment in
YGValue, MSVC does define NAN) to __builtin_nanf("0"), which generates
a quiet NaN. The problem with NAN is that corecrt_math.h defines it as:

Which *seems* fine! However, because we are compiling with /fp:precise
(see: microsoft#4122 for more details), that multiplication actually happens at
runtime. And, unfortunately, we're sometimes seeing MXCSR set to round
down (i.e., the_MM_ROUND_DOWN flag is set)), which, combined with th
SSE instructions that happen to run here (specifically, cvtpd2ps), cause
NAN, and thus YGUndefined, to yield a value of 0! What happens is that
cvtpd2ps, when rounding down, converts 1#.INF in double-precision not to
1#.INF in single-precision, but instead to FLT_MAX!!! And, of course,
FLT_MAX*0 is 0, not qNaN. Oops.

Anyways, using __builting_nanf("0") just loads 0x7FC0000 into xmm0,
rather than doing any math, so, even with /fp:precise + bad rounding
modes, YGUndefined is, in fact, a quiet NaN.

* Revert "Change the definition of YGUndefined from NAN (contra the comment in"

This reverts commit 3fb68a2.

Rather than trying to fork YGValue.h, we'll address the underlying
problem by not using /fp:strict for yoga.cpp

* Compiling yoga.cpp with /fp:strict causes
microsoft#8675. We use
this flag to address microsoft#4122, but in my manual testing, as well by
inspecting the disassembly that seemed to be responsible for issue 4122,
this workaround is no longer necessary.

* Patch yoga to use better definition for YGUndefined

* Change files

Co-authored-by: dannyvv <[email protected]>
Co-authored-by: Andrew Coates <[email protected]>
@acoates-ms acoates-ms requested a review from a team as a code owner June 7, 2022 17:26
@acoates-ms acoates-ms merged commit 0cb8b83 into microsoft:main Jun 8, 2022
@acoates-ms acoates-ms deleted the arm64float branch June 8, 2022 16:15
asklar pushed a commit to asklar/react-native-windows that referenced this pull request Jun 18, 2022
* [0.64] Fix ARM64 layout issues in Office (microsoft#8689)

* Change the definition of YGUndefined from NAN (contra the comment in
YGValue, MSVC does define NAN) to __builtin_nanf("0"), which generates
a quiet NaN. The problem with NAN is that corecrt_math.h defines it as:

Which *seems* fine! However, because we are compiling with /fp:precise
(see: microsoft#4122 for more details), that multiplication actually happens at
runtime. And, unfortunately, we're sometimes seeing MXCSR set to round
down (i.e., the_MM_ROUND_DOWN flag is set)), which, combined with th
SSE instructions that happen to run here (specifically, cvtpd2ps), cause
NAN, and thus YGUndefined, to yield a value of 0! What happens is that
cvtpd2ps, when rounding down, converts 1#.INF in double-precision not to
1#.INF in single-precision, but instead to FLT_MAX!!! And, of course,
FLT_MAX*0 is 0, not qNaN. Oops.

Anyways, using __builting_nanf("0") just loads 0x7FC0000 into xmm0,
rather than doing any math, so, even with /fp:precise + bad rounding
modes, YGUndefined is, in fact, a quiet NaN.

* Revert "Change the definition of YGUndefined from NAN (contra the comment in"

This reverts commit 3fb68a2.

Rather than trying to fork YGValue.h, we'll address the underlying
problem by not using /fp:strict for yoga.cpp

* Compiling yoga.cpp with /fp:strict causes
microsoft#8675. We use
this flag to address microsoft#4122, but in my manual testing, as well by
inspecting the disassembly that seemed to be responsible for issue 4122,
this workaround is no longer necessary.

* Patch yoga to use better definition for YGUndefined

* Change files

Co-authored-by: dannyvv <[email protected]>
Co-authored-by: Andrew Coates <[email protected]>

* Fix change file

* react-native-platform-override upgrade

Co-authored-by: Harold Pratt <[email protected]>
Co-authored-by: dannyvv <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants