Skip to content

Commit

Permalink
i386: Convert libc_{feholdexcept_setround,updateenv}_53bit to functions.
Browse files Browse the repository at this point in the history
Also fix a bug in libc_feupdateenv_53bit: don't force the rounding
precision back to _FPU_EXTENDED, instead restore the precision that
the user had in effect beforehand.
  • Loading branch information
rth7680 committed Mar 19, 2012
1 parent b4dabbb commit 7d2e801
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
2012-03-19 Richard Henderson <[email protected]>

* sysdeps/i386/fpu/math_private.h: Include <fenv.h>, <fpu_control.h>.
(libc_feholdexcept_setround_53bit): Convert from macro to function.
(libc_feupdateenv_53bit): Likewise. Don't force _FPU_EXTENDED.

* sysdeps/generic/math_private.h: Include <fenv.h>.
(default_libc_feholdexcept): New.
(default_libc_feholdexcept_setround): New.
Expand Down
58 changes: 29 additions & 29 deletions sysdeps/i386/fpu/math_private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef _MATH_PRIVATE_H

#include <fenv.h>
#include <fpu_control.h>

#define math_opt_barrier(x) \
({ __typeof (x) __x; \
__asm ("" : "=t" (__x) : "0" (x)); \
Expand All @@ -15,34 +18,31 @@ do \
} \
while (0)

#include_next <math_private.h>
static __always_inline void
libc_feholdexcept_setround_53bit (fenv_t *e, int r)
{
feholdexcept (e);
fesetround (r);

#include <fpu_control.h>
fpu_control_t cw;
_FPU_GETCW (cw);
cw &= ~(fpu_control_t) _FPU_EXTENDED;
cw |= _FPU_DOUBLE;
_FPU_SETCW (cw);
}
#define libc_feholdexcept_setround_53bit libc_feholdexcept_setround_53bit

static __always_inline void
libc_feupdateenv_53bit (fenv_t *e)
{
feupdateenv (e);

/* Unfortunately, feupdateenv fails to affect the rounding precision.
We can get that back by restoring the exact control word we saved. */
_FPU_SETCW (e->__control_word);
}
#define libc_feupdateenv_53bit libc_feupdateenv_53bit

#include_next <math_private.h>

#undef libc_feholdexcept_setround_53bit
#define libc_feholdexcept_setround_53bit(e, r) \
do \
{ \
fpu_control_t cw; \
libc_feholdexcept_setround (e, r); \
_FPU_GETCW (cw); \
cw &= ~(fpu_control_t) _FPU_EXTENDED; \
cw |= _FPU_DOUBLE; \
_FPU_SETCW (cw); \
} \
while (0)

#undef libc_feupdateenv_53bit
#define libc_feupdateenv_53bit(e) \
do \
{ \
fpu_control_t cw; \
libc_feupdateenv (e); \
_FPU_GETCW (cw); \
cw &= ~(fpu_control_t) _FPU_EXTENDED; \
cw |= _FPU_EXTENDED; \
_FPU_SETCW (cw); \
} \
while (0)

#endif
#endif /* _MATH_PRIVATE_H */

0 comments on commit 7d2e801

Please sign in to comment.