[PATCH] Cygwin: fegetenv() in winsup/cygwin/fenv.cc should not disable exceptions!
Corinna Vinschen
corinna-cygwin@cygwin.com
Fri Aug 3 07:36:00 GMT 2018
Hi J.H.,
On Aug 3 01:45, J.H. van de Water wrote:
> fegetenv() in winsup/cygwin/fenv.cc
>
> fnstenv MUST be followed by fldenv in fegetenv(), as the former disables all
> exceptions in the x87 FPU, which is not appropriate here (fegetenv() ).
> fldenv after fnstenv should reload the x87 FPU w/ the configuration that was
> saved by fnstenv, i.e. a configuration that might have exceptions enabled.
>
> Note: x86_64 uses SSE for floating-point, not the x87 FPU. However, because
> feraiseexcept() attempts to provoke an exception using the x87 FPU, the bug
> in fegetenv() will make this attempt futile here (x86_64).
>
> Note: WoW uses the x87 FPU for floating-point, not SSE. Here anything that
> would normally result in triggering an exception, not only feraiseexcept(),
> will not be able to, as result of the bug in fegetenv().
> ---
> winsup/cygwin/fenv.cc | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/winsup/cygwin/fenv.cc b/winsup/cygwin/fenv.cc
> index bd3f904..eb5260c 100644
> --- a/winsup/cygwin/fenv.cc
> +++ b/winsup/cygwin/fenv.cc
> @@ -141,7 +141,10 @@ fegetexcept (void)
> int
> fegetenv (fenv_t *envp)
> {
> - __asm__ volatile ("fnstenv %0" : "=m" (envp->_fpu) : );
> + /* fnstenv disables all exceptions in the x87 FPU; as this is not what is
> + desired here, reload the cfg saved from the x87 FPU, back to the FPU */
> + __asm__ volatile ("fnstenv %0"
> + "fldenv %0" : "=m" (envp->_fpu) : );
> if (use_sse)
> __asm__ volatile ("stmxcsr %0" : "=m" (envp->_sse_mxcsr) : );
> return 0;
> --
> 2.7.5
Thank you!
Pushed with tweaks. The string in __asm__ statements works a
bit different and I made a slight change to the commit message.
In terms of x86_64, do we have to change the fenv stuff completely
to use only SSE opcodes? Does that make sense at all?
Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20180803/3d5ff44e/attachment.sig>
More information about the Cygwin-patches
mailing list