This is an archive of the discontinued LLVM Phabricator instance.

[libc] Change FEnv to use MXCSR as source of truth
ClosedPublic

Authored by michaelrj on Mar 16 2022, 12:10 PM.

Details

Summary

This patch primarily fixes the fenv implementation on Windows, since
Windows uses the MXCSR in place of the x87 status registers for storing
information about the floating point environment. This allows FEnv to
work correctly on Windows, and successfully build.

Diff Detail

Event Timeline

michaelrj created this revision.Mar 16 2022, 12:10 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 16 2022, 12:10 PM
michaelrj requested review of this revision.Mar 16 2022, 12:10 PM

Currently the getenv_and_setenv_test.cpp file has a failure on line 71, the rounding mode is not being properly reset to FE_TONEAREST, it's still set to FE_DOWNWARD.

lntue accepted this revision.Mar 16 2022, 12:23 PM
This revision is now accepted and ready to land.Mar 16 2022, 12:23 PM
michaelrj updated this revision to Diff 416004.Mar 16 2022, 3:30 PM

fix the FE_DFL_ENV behavior for set_env

lntue added inline comments.Mar 17 2022, 7:55 AM
libc/src/__support/FPUtil/x86_64/FEnvImpl.h
513

Why do we need to do some extra clean up for the default environment?

michaelrj updated this revision to Diff 417130.Mar 21 2022, 4:21 PM

Big change to get the windows FEnv working. Patch will be renamed to match.

michaelrj retitled this revision from [libc] Clean up Windows build to [libc] Change FEnv to use MXCSR as source of truth.Mar 21 2022, 4:21 PM
michaelrj edited the summary of this revision. (Show Details)
lntue added inline comments.Mar 21 2022, 8:52 PM
libc/src/__support/FPUtil/x86_64/FEnvImpl.h
472

You should either name these bit masks or add comments to tell which flag is set in each line.

584

You should name these bit masks to make it easier to keep track and debug which flag is set in which line. Also look like they can be re-used for control word also.

michaelrj updated this revision to Diff 417429.Mar 22 2022, 4:23 PM
michaelrj marked 3 inline comments as done.

add named constants for exceptions and a round-trip test for Windows.

lntue accepted this revision.Mar 22 2022, 8:11 PM
This revision was automatically updated to reflect the committed changes.