Skip to content

Commit

Permalink
Clean up powerpc fegetround / __fegetround inlines.
Browse files Browse the repository at this point in the history
The natural fix for some linknamespace test failures, where C90 libm
functions call C99 <fenv.h> functions, is to make fe* into weak
aliases for __fe* and call __fe* from within libm as needed.

To do this, the __fe* names need to be available for that purpose -
that is, they must not be used for something other than aliases of
fe*.  On powerpc, however, __fegetround is an inline function in
fenv_libc.h, with no corresponding fegetround inline function;
fegetround has an equivalent macro expansion in bits/fenvinline.h, but
that is disabled if __NO_MATH_INLINES (which is defined for building
libm).

I see no need for that disabling; it's not even clear that
__NO_MATH_INLINES should affect <fenv.h>, and the results of
fegetround are completely defined so there is no semantic effect of
that disabling at all outside glibc.  The x86 inline feraiseexcept is
conditioned on __USE_EXTERN_INLINES not __NO_MATH_INLINES (but that's
an inline function rather than a macro).

This patch removes the __NO_MATH_INLINES conditional on that
fegetround macro, so resulting in it being expanded inline inside
glibc.  In turn, this means that direct calls to __fegetround from C99
functions in ldbl-128ibm can be changed to calls to fegetround, so
that nofpu fenv_libc.h files don't need to define __fegetround at all
and, by changing ldbl-128ibm files to use <fenv.h> not <fenv_libc.h>,
non-e500 nofpu no longer needs an fenv_libc.h file.

The other macros in fenvinline.h are left conditional on
__NO_MATH_INLINES, although since the only case where this should make
a difference is one involving undefined behavior (if the argument to
the function is not a valid exception macro).

The out-of-line definition for fegetround uses __fegetround (the
inline function removed by this patch).  So this continues to work,
the fenvinline.h header is made to define __fegetround, and then to
define fegetround to call __fegetround.

Tested for powerpc32 (hard float) that installed stripped shared
libraries are unchanged by this patch; also tested that powerpc-nofpu
build still works.  (This patch does not itself fix any bugs; it
simply cleans things up in preparation for separate bug fixes.)

	* sysdeps/powerpc/bits/fenvinline.h (fegetround): Rename macro to
	__fegetround and redefine to call __fegetround.  Remove condition
	on [!__NO_MATH_INLINES].
	* sysdeps/powerpc/fpu/fenv_libc.h (__fegetround): Remove inline
	function.
	* sysdeps/powerpc/nofpu/fenv_libc.h: Remove file.
	* sysdeps/powerpc/powerpc32/e500/nofpu/fenv_libc.h (__fegetround):
	Remove macro.
	* sysdeps/ieee754/ldbl-128ibm/s_llrintl.c: Include <fenv.h>
	instead of <fenv_libc.h>.
	(__llrintl): Call fegetround instead of __fegetround.
	* sysdeps/ieee754/ldbl-128ibm/s_llroundl.c: Include <fenv.h>
	instead of <fenv_libc.h>.
	* sysdeps/ieee754/ldbl-128ibm/s_lrintl.c: Likewise.
	(__lrintl): Call fegetround instead of __fegetround.
	* sysdeps/ieee754/ldbl-128ibm/s_lroundl.c: Include <fenv.h>
	instead of <fenv_libc.h>.
	* sysdeps/ieee754/ldbl-128ibm/s_rintl.c: Likewise.
	(__rintl): Call fegetround instead of __fegetround.
  • Loading branch information
Joseph Myers committed Dec 31, 2014
1 parent 195f3af commit 4a3d399
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 56 deletions.
22 changes: 22 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
2014-12-31 Joseph Myers <joseph@codesourcery.com>

* sysdeps/powerpc/bits/fenvinline.h (fegetround): Rename macro to
__fegetround and redefine to call __fegetround. Remove condition
on [!__NO_MATH_INLINES].
* sysdeps/powerpc/fpu/fenv_libc.h (__fegetround): Remove inline
function.
* sysdeps/powerpc/nofpu/fenv_libc.h: Remove file.
* sysdeps/powerpc/powerpc32/e500/nofpu/fenv_libc.h (__fegetround):
Remove macro.
* sysdeps/ieee754/ldbl-128ibm/s_llrintl.c: Include <fenv.h>
instead of <fenv_libc.h>.
(__llrintl): Call fegetround instead of __fegetround.
* sysdeps/ieee754/ldbl-128ibm/s_llroundl.c: Include <fenv.h>
instead of <fenv_libc.h>.
* sysdeps/ieee754/ldbl-128ibm/s_lrintl.c: Likewise.
(__lrintl): Call fegetround instead of __fegetround.
* sysdeps/ieee754/ldbl-128ibm/s_lroundl.c: Include <fenv.h>
instead of <fenv_libc.h>.
* sysdeps/ieee754/ldbl-128ibm/s_rintl.c: Likewise.
(__rintl): Call fegetround instead of __fegetround.

2014-12-31 Siddhesh Poyarekar <siddhesh@redhat.com>

* scripts/gen-posix-conf-vars.awk: Don't use multi-dimensional
Expand Down
4 changes: 2 additions & 2 deletions sysdeps/ieee754/ldbl-128ibm/s_llrintl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<http://www.gnu.org/licenses/>. */

#include <math.h>
#include <fenv_libc.h>
#include <fenv.h>
#include <math_ldbl_opt.h>
#include <float.h>
#include <ieee754.h>
Expand All @@ -43,7 +43,7 @@ __llrintl (long double x)
#endif
)
{
save_round = __fegetround ();
save_round = fegetround ();

if (__glibc_unlikely ((xh == -(double) (-__LONG_LONG_MAX__ - 1))))
{
Expand Down
2 changes: 1 addition & 1 deletion sysdeps/ieee754/ldbl-128ibm/s_llroundl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<http://www.gnu.org/licenses/>. */

#include <math.h>
#include <fenv_libc.h>
#include <fenv.h>
#include <math_ldbl_opt.h>
#include <float.h>
#include <ieee754.h>
Expand Down
4 changes: 2 additions & 2 deletions sysdeps/ieee754/ldbl-128ibm/s_lrintl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<http://www.gnu.org/licenses/>. */

#include <math.h>
#include <fenv_libc.h>
#include <fenv.h>
#include <math_ldbl_opt.h>
#include <float.h>
#include <ieee754.h>
Expand Down Expand Up @@ -49,7 +49,7 @@ __lrintl (long double x)
#endif
)
{
save_round = __fegetround ();
save_round = fegetround ();

#if __LONG_MAX__ == 2147483647
long long llhi = (long long) xh;
Expand Down
2 changes: 1 addition & 1 deletion sysdeps/ieee754/ldbl-128ibm/s_lroundl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<http://www.gnu.org/licenses/>. */

#include <math.h>
#include <fenv_libc.h>
#include <fenv.h>
#include <math_ldbl_opt.h>
#include <float.h>
#include <ieee754.h>
Expand Down
4 changes: 2 additions & 2 deletions sysdeps/ieee754/ldbl-128ibm/s_rintl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
when it's coded in C. */

#include <math.h>
#include <fenv_libc.h>
#include <fenv.h>
#include <math_ldbl_opt.h>
#include <float.h>
#include <ieee754.h>
Expand All @@ -40,7 +40,7 @@ __rintl (long double x)
__builtin_inf ()), 1))
{
double orig_xh;
int save_round = __fegetround ();
int save_round = fegetround ();

/* Long double arithmetic, including the canonicalisation below,
only works in round-to-nearest mode. */
Expand Down
13 changes: 8 additions & 5 deletions sysdeps/powerpc/bits/fenvinline.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */

#if (defined __GNUC__ && !defined _SOFT_FLOAT && !defined __NO_FPRS__ \
&& !defined __NO_MATH_INLINES)
#if defined __GNUC__ && !defined _SOFT_FLOAT && !defined __NO_FPRS__

/* Inline definition for fegetround. */
# define fegetround() \
# define __fegetround() \
(__extension__ ({ int __fegetround_result; \
__asm__ __volatile__ \
("mcrfs 7,7 ; mfcr %0" \
: "=r"(__fegetround_result) : : "cr7"); \
__fegetround_result & 3; }))
# define fegetround() __fegetround ()

# ifndef __NO_MATH_INLINES
/* The weird 'i#*X' constraints on the following suppress a gcc
warning when __excepts is not a constant. Otherwise, they mean the
same as just plain 'i'. */

/* Inline definition for feraiseexcept. */
# define feraiseexcept(__excepts) \
# define feraiseexcept(__excepts) \
((__builtin_constant_p (__excepts) \
&& ((__excepts) & ((__excepts)-1)) == 0 \
&& (__excepts) != FE_INVALID) \
Expand All @@ -45,7 +46,7 @@
: (feraiseexcept) (__excepts))

/* Inline definition for feclearexcept. */
# define feclearexcept(__excepts) \
# define feclearexcept(__excepts) \
((__builtin_constant_p (__excepts) \
&& ((__excepts) & ((__excepts)-1)) == 0 \
&& (__excepts) != FE_INVALID) \
Expand All @@ -57,4 +58,6 @@
: 0) \
: (feclearexcept) (__excepts))

# endif /* !__NO_MATH_INLINES. */

#endif /* __GNUC__ && !_SOFT_FLOAT && !__NO_FPRS__ */
9 changes: 0 additions & 9 deletions sysdeps/powerpc/fpu/fenv_libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ typedef union
} fenv_union_t;


static inline int
__fegetround (void)
{
int result;
asm volatile ("mcrfs 7,7\n\t"
"mfcr %0" : "=r"(result) : : "cr7");
return result & 3;
}

static inline int
__fesetround (int round)
{
Expand Down
31 changes: 0 additions & 31 deletions sysdeps/powerpc/nofpu/fenv_libc.h

This file was deleted.

3 changes: 0 additions & 3 deletions sysdeps/powerpc/powerpc32/e500/nofpu/fenv_libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

#include <fenv.h>

/* ldbl-128ibm code uses __fegetround. */
#define __fegetround() fegetround ()

int __feraiseexcept_spe (int);
libm_hidden_proto (__feraiseexcept_spe)

Expand Down

0 comments on commit 4a3d399

Please sign in to comment.