fix i386 fegetround and make fesetround faster

Note that the new fesetround has slightly different semantics:

Storing the floating-point environment with fnstenv makes the
next fldenv (or fldcw) "non-signaling", so unmasked and pending
exceptions does not invoke the exception handler.
(These are rare since exceptions are handled immediately and by
default all exceptions are masked anyway. But if one manually
unmasks an exception in the control word then either sets the
corresponding exception flag in the status word or the execution
of an exception raising floating-point operation gets interrupted
then it may happen).
So the old implementation did not trap in some rare cases
where the new implementation traps.

However POSIX does not specify anything like the x87 exception
handling traps and the fnstenv/fldenv pair is significantly slower
than the fnstcw/fldcw pair (new code is about 5x faster here and
it's dominated by the function call overhead).
This commit is contained in:
nsz 2012-03-17 13:46:15 +01:00
commit 88cfaf8a14

View file

@ -32,22 +32,22 @@ feraiseexcept:
fesetround: fesetround:
mov 4(%esp),%ecx mov 4(%esp),%ecx
xor %eax,%eax xor %eax,%eax
sub $32,%esp sub $4,%esp
fnstenv (%esp) fnstcw (%esp)
andb $0xf3,1(%esp) andb $0xf3,1(%esp)
or %ecx,(%esp) or %cx,(%esp)
fldenv (%esp) fldcw (%esp)
add $32,%esp add $4,%esp
ret ret
.global fegetround .global fegetround
.type fegetround,@function .type fegetround,@function
fegetround: fegetround:
sub $28,%esp sub $4,%esp
fnstenv (%esp) fnstcw (%esp)
mov 4(%esp),%eax mov (%esp),%ax
add $28,%esp add $4,%esp
and $0xc,%ah and $0xc00,%eax
ret ret
.global fegetenv .global fegetenv