powerpc: round/roundf refactor

This patches consolidates all the powerpc round{f} implementations on
the generic sysdeps/powerpc/fpu/s_round{f}.  The generic implementation
uses either the compiler builts for ISA 2.03+ (which generates the
frim instruction) or a generic implementation which uses FP only
operations.

The IFUNC organization for powerpc64 is also change to be enabled only
for powerpc64 and not for powerpc64le (since minium ISA of 2.08 does not
require the fallback generic implementation).

Checked on powerpc-linux-gnu (built without --with-cpu, with
--with-cpu=power4 and with --with-cpu=power5+ and --disable-multi-arch),
powerpc64-linux-gnu (built without --with-cp and with --with-cpu=power5+
and --disable-multi-arch).

	* sysdeps/powerpc/fpu/round_to_integer.h (set_fenv_mode): Add
	ROUND handling.
	(round_mode): Add definition for ROUND.
	(round_to_integer_float): Likewise.
	* sysdeps/powerpc/fpu/s_round.c: New file.
	* sysdeps/powerpc/fpu/s_roundf.c: New file.
	* sysdeps/powerpc/powerpc32/fpu/s_round.S: Remove file.
	* sysdeps/powerpc/powerpc32/fpu/s_roundf.S: Likewise.
	* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_round-power5+.S:
	Likewise.
	* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_round-ppc32.S:
	Likewise.
	* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_roundf-power5+.S:
	Likewise.
	* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_roundf-ppc32.S:
	Likewise.
	* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_round-power5+.c: New
	file.
	* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_round-ppc32.c:
	Likewise.
	* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_roundf-power5+.c:
	Likewise.
	* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_roundf-ppc32.c:
	Likewise.
	* sysdep/powerpc/powerpc32/power5+/fpu/s_round.S: Remove file.
	* sysdep/powerpc/powerpc32/power5+/fpu/s_roundf.S: Likewise.
	* sysdep/powerpc/powerpc64/be/fpu/multiarch/Makefile
	(libm-sysdep_routines): Add s_round-power5+, s_round-ppc64,
	s_roundf-power5+, and s_roundf-ppc64.
	(CFLAGS-s_round-power5+.c, CFLAGS-s_roundf-power5+.c): New rule.
	* sysdep/powerpc/powercp64/be/fpu/multiarch/s_round-power5+.c: New
	file.
	* sysdep/powerpc/powercp64/be/fpu/multiarch/s_round-ppc64.c: Likewise.
	* sysdeps/powerpc/powerpc64/fpu/multiarch/s_round.c: Move to ...
	* sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_round.c: ... here.
	* sysdep/powerpc/powercp64/be/fpu/multiarch/s_roundf-power5+.c: New
	file.
	* sysdep/powerpc/powercp64/be/fpu/multiarch/s_roundf-ppc64.c:
	Likewise.
	* sysdeps/powerpc/powerpc64/fpu/multiarch/s_roundf.c: Move to ...
	* sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_roundf.c: ... here.
	* sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile
	(libm-sysdep_routines): Remove s_round-power5+, s_round-ppc64,
	s_roundf-power5+, and s_roundf-ppc64.
	* sysdep/powerpc/powerpc64/fpu/multiarch/s_round-power5+.S: Remove
	file.
	* sysdep/powerpc/powerpc64/fpu/multiarch/s_round-ppc64.S: Likewise.
	* sysdep/powerpc/powerpc64/fpu/multiarch/s_roundf-power5+.S:
	Likewise.
	* sysdep/powerpc/powerpc64/fpu/multiarch/s_roundf-ppc64.S: Likewise.
	* sysdeps/powerpc/powerpc64/fpu/s_round.S: Likewise.
	* sysdeps/powerpc/powerpc64/fpu/s_roundf.S: Likewise.
	* sysdep/powerpc/powerpc64/power5+/fpu/s_round.S: Likewise.
	* sysdep/powerpc/powerpc64/power5+/fpu/s_roundf.S: Likewise.

Reviewed-by: Gabriel F. T. Gomes <gabriel@inconstante.eti.br>
This commit is contained in:
Adhemerval Zanella 2019-03-08 15:20:08 +00:00
parent 252296c625
commit a1cb1888b7
32 changed files with 176 additions and 704 deletions

View File

@ -1,5 +1,60 @@
2019-05-09 Adhemerval Zanella <adhemerval.zanella@linaro.org>
* sysdeps/powerpc/fpu/round_to_integer.h (set_fenv_mode): Add
ROUND handling.
(round_mode): Add definition for ROUND.
(round_to_integer_float): Likewise.
* sysdeps/powerpc/fpu/s_round.c: New file.
* sysdeps/powerpc/fpu/s_roundf.c: New file.
* sysdeps/powerpc/powerpc32/fpu/s_round.S: Remove file.
* sysdeps/powerpc/powerpc32/fpu/s_roundf.S: Likewise.
* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_round-power5+.S:
Likewise.
* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_round-ppc32.S:
Likewise.
* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_roundf-power5+.S:
Likewise.
* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_roundf-ppc32.S:
Likewise.
* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_round-power5+.c: New
file.
* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_round-ppc32.c:
Likewise.
* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_roundf-power5+.c:
Likewise.
* sysdep/powerpc/powepc32/power4/fpu/multiarch/s_roundf-ppc32.c:
Likewise.
* sysdep/powerpc/powerpc32/power5+/fpu/s_round.S: Remove file.
* sysdep/powerpc/powerpc32/power5+/fpu/s_roundf.S: Likewise.
* sysdep/powerpc/powerpc64/be/fpu/multiarch/Makefile
(libm-sysdep_routines): Add s_round-power5+, s_round-ppc64,
s_roundf-power5+, and s_roundf-ppc64.
(CFLAGS-s_round-power5+.c, CFLAGS-s_roundf-power5+.c): New rule.
* sysdep/powerpc/powercp64/be/fpu/multiarch/s_round-power5+.c: New
file.
* sysdep/powerpc/powercp64/be/fpu/multiarch/s_round-ppc64.c: Likewise.
* sysdeps/powerpc/powerpc64/fpu/multiarch/s_round.c: Move to ...
* sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_round.c: ... here.
* sysdep/powerpc/powercp64/be/fpu/multiarch/s_roundf-power5+.c: New
file.
* sysdep/powerpc/powercp64/be/fpu/multiarch/s_roundf-ppc64.c:
Likewise.
* sysdeps/powerpc/powerpc64/fpu/multiarch/s_roundf.c: Move to ...
* sysdeps/powerpc/powerpc64/be/fpu/multiarch/s_roundf.c: ... here.
* sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile
(libm-sysdep_routines): Remove s_round-power5+, s_round-ppc64,
s_roundf-power5+, and s_roundf-ppc64.
* sysdep/powerpc/powerpc64/fpu/multiarch/s_round-power5+.S: Remove
file.
* sysdep/powerpc/powerpc64/fpu/multiarch/s_round-ppc64.S: Likewise.
* sysdep/powerpc/powerpc64/fpu/multiarch/s_roundf-power5+.S:
Likewise.
* sysdep/powerpc/powerpc64/fpu/multiarch/s_roundf-ppc64.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_round.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_roundf.S: Likewise.
* sysdep/powerpc/powerpc64/power5+/fpu/s_round.S: Likewise.
* sysdep/powerpc/powerpc64/power5+/fpu/s_roundf.S: Likewise.
* sysdeps/powerpc/fpu/round_to_integer.h (set_fenv_mode):
Add FLOOR option.
(round_mode): Add definition for FLOOR.

View File

@ -24,7 +24,8 @@
enum round_mode
{
CEIL,
FLOOR
FLOOR,
ROUND
};
static inline void
@ -35,6 +36,7 @@ set_fenv_mode (enum round_mode mode)
{
case CEIL: rmode = FE_UPWARD; break;
case FLOOR: rmode = FE_DOWNWARD; break;
case ROUND: rmode = FE_TOWARDZERO; break;
default: rmode = FE_TONEAREST; break;
}
__fesetround_inline_nocheck (rmode);
@ -57,12 +59,24 @@ round_to_integer_float (enum round_mode mode, float x)
set_fenv_mode (mode);
if (x > 0.0)
{
/* IEEE 1003.1 round function. IEEE specifies "round to the nearest
integer value, rounding halfway cases away from zero, regardless of
the current rounding mode." However PowerPC Architecture defines
"Round to Nearest" as "Choose the best approximation. In case of a
tie, choose the one that is even (least significant bit o).".
So we can't use the PowerPC "Round to Nearest" mode. Instead we set
"Round toward Zero" mode and round by adding +-0.5 before rounding
to the integer value. */
if (mode == ROUND)
r += 0.5f;
r += 0x1p+23;
r -= 0x1p+23;
r = fabs (r);
}
else if (x < 0.0)
{
if (mode == ROUND)
r -= 0.5f;
r -= 0x1p+23;
r += 0x1p+23;
r = -fabs (r);
@ -89,12 +103,16 @@ round_to_integer_double (enum round_mode mode, double x)
set_fenv_mode (mode);
if (x > 0.0)
{
if (mode == ROUND)
r += 0.5;
r += 0x1p+52;
r -= 0x1p+52;
r = fabs (r);
}
else if (x < 0.0)
{
if (mode == ROUND)
r -= 0.5;
r -= 0x1p+52;
r += 0x1p+52;
r = -fabs (r);

View File

@ -0,0 +1,35 @@
/* Largest integral value not greater than argument. PowerPC version.
Copyright (C) 2019 Free Software Foundation, Inc.
This file is part of the GNU C Library
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, see <http://www.gnu.org/licenses/>. */
#define NO_MATH_REDIRECT
#include <math.h>
#include <libm-alias-double.h>
#include <round_to_integer.h>
double
__round (double x)
{
#ifdef _ARCH_PWR5X
return __builtin_round (x);
#else
return round_to_integer_double (ROUND, x);
#endif
}
#ifndef __round
libm_alias_double (__round, round)
#endif

View File

@ -0,0 +1,35 @@
/* Smallest integral value not less than argument. PowerPC version.
Copyright (C) 2019 Free Software Foundation, Inc.
This file is part of the GNU C Library
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, see <http://www.gnu.org/licenses/>. */
#define NO_MATH_REDIRECT
#include <math.h>
#include <libm-alias-float.h>
#include <round_to_integer.h>
float
__roundf (float x)
{
#ifdef _ARCH_PWR5X
return __builtin_roundf (x);
#else
return round_to_integer_float (ROUND, x);
#endif
}
#ifndef __roundf
libm_alias_float (__round, round)
#endif

View File

@ -1,97 +0,0 @@
/* round function. PowerPC32 version.
Copyright (C) 2004-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <math_ldbl_opt.h>
#include <libm-alias-double.h>
.section .rodata.cst8,"aM",@progbits,8
.align 2
.LC0: /* 2**52 */
.long 0x59800000
.LC1: /* 0.5 */
.long 0x3f000000
/* double [fp1] round (double x [fp1])
IEEE 1003.1 round function. IEEE specifies "round to the nearest
integer value, rounding halfway cases away from zero, regardless of
the current rounding mode." However PowerPC Architecture defines
"Round to Nearest" as "Choose the best approximation. In case of a
tie, choose the one that is even (least significant bit o).".
So we can't use the PowerPC "Round to Nearest" mode. Instead we set
"Round toward Zero" mode and round by adding +-0.5 before rounding
to the integer value. */
.section ".text"
ENTRY (__round)
#ifdef SHARED
mflr r11
cfi_register(lr,r11)
SETUP_GOT_ACCESS(r9,got_label)
addis r9,r9,.LC0-got_label@ha
addi r9,r9,.LC0-got_label@l
mtlr r11
cfi_same_value (lr)
lfs fp13,0(r9)
#else
lis r9,.LC0@ha
lfs fp13,.LC0@l(r9)
#endif
fabs fp0,fp1
fsub fp12,fp13,fp13 /* generate 0.0 */
fcmpu cr7,fp0,fp13 /* if (fabs(x) > TWO52) */
mffs fp11 /* Save current FPU rounding mode and
"inexact" state. */
fcmpu cr6,fp1,fp12 /* if (x > 0.0) */
bnl- cr7,.L10
mtfsfi 7,1 /* Set rounding mode toward 0. */
#ifdef SHARED
lfs fp10,.LC1-.LC0(r9)
#else
lis r9,.LC1@ha
lfs fp10,.LC1@l(r9)
#endif
ble- cr6,.L4
fadd fp1,fp1,fp10 /* x+= 0.5; */
fadd fp1,fp1,fp13 /* x+= TWO52; */
fsub fp1,fp1,fp13 /* x-= TWO52; */
fabs fp1,fp1 /* if (x == 0.0) */
/* x = 0.0; */
mtfsf 0xff,fp11 /* Restore previous rounding mode and
"inexact" state. */
blr
.L4:
fsub fp9,fp1,fp10 /* x+= 0.5; */
bge- cr6,.L9 /* if (x < 0.0) */
fsub fp1,fp9,fp13 /* x-= TWO52; */
fadd fp1,fp1,fp13 /* x+= TWO52; */
fnabs fp1,fp1 /* if (x == 0.0) */
/* x = -0.0; */
.L9:
mtfsf 0xff,fp11 /* Restore previous rounding mode and
"inexact" state. */
blr
.L10:
/* Ensure sNaN input is converted to qNaN. */
fcmpu cr7,fp1,fp1
beqlr cr7
fadd fp1,fp1,fp1
blr
END (__round)
libm_alias_double (__round, round)

View File

@ -1,96 +0,0 @@
/* roundf function. PowerPC32 version.
Copyright (C) 2004-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <libm-alias-float.h>
.section .rodata.cst8,"aM",@progbits,8
.align 3
.LC0: /* 2**23 */
.long 0x4b000000
.LC1: /* 0.5 */
.long 0x3f000000
/* float [fp1] roundf (float x [fp1])
IEEE 1003.1 round function. IEEE specifies "round to the nearest
integer value, rounding halfway cases away from zero, regardless of
the current rounding mode." However PowerPC Architecture defines
"Round to Nearest" as "Choose the best approximation. In case of a
tie, choose the one that is even (least significant bit o).".
So we can't use the PowerPC "Round to Nearest" mode. Instead we set
"Round toward Zero" mode and round by adding +-0.5 before rounding
to the integer value. */
.section ".text"
ENTRY (__roundf )
#ifdef SHARED
mflr r11
cfi_register(lr,r11)
SETUP_GOT_ACCESS(r9,got_label)
addis r9,r9,.LC0-got_label@ha
addi r9,r9,.LC0-got_label@l
mtlr r11
cfi_same_value (lr)
lfs fp13,0(r9)
#else
lis r9,.LC0@ha
lfs fp13,.LC0@l(r9)
#endif
fabs fp0,fp1
fsubs fp12,fp13,fp13 /* generate 0.0 */
fcmpu cr7,fp0,fp13 /* if (fabs(x) > TWO23) */
mffs fp11 /* Save current FPU rounding mode and
"inexact" state. */
fcmpu cr6,fp1,fp12 /* if (x > 0.0) */
bnl- cr7,.L10
mtfsfi 7,1 /* Set rounding mode toward 0. */
#ifdef SHARED
lfs fp10,.LC1-.LC0(r9)
#else
lfs fp10,.LC1@l(r9)
#endif
ble- cr6,.L4
fadds fp1,fp1,fp10 /* x+= 0.5; */
fadds fp1,fp1,fp13 /* x+= TWO23; */
fsubs fp1,fp1,fp13 /* x-= TWO23; */
fabs fp1,fp1 /* if (x == 0.0) */
/* x = 0.0; */
mtfsf 0xff,fp11 /* Restore previous rounding mode and
"inexact" state. */
blr
.L4:
fsubs fp9,fp1,fp10 /* x+= 0.5; */
bge- cr6,.L9 /* if (x < 0.0) */
fsubs fp1,fp9,fp13 /* x-= TWO23; */
fadds fp1,fp1,fp13 /* x+= TWO23; */
fnabs fp1,fp1 /* if (x == 0.0) */
/* x = -0.0; */
.L9:
mtfsf 0xff,fp11 /* Restore previous rounding mode and
"inexact" state. */
blr
.L10:
/* Ensure sNaN input is converted to qNaN. */
fcmpu cr7,fp1,fp1
beqlr cr7
fadds fp1,fp1,fp1
blr
END (__roundf)
libm_alias_float (__round, round)

View File

@ -1,33 +0,0 @@
/* round function. PowerPC32/power5+ version.
Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <math_ldbl_opt.h>
#undef hidden_def
#define hidden_def(name)
#undef weak_alias
#define weak_alias(name, alias)
#undef strong_alias
#define strong_alias(name, alias)
#undef compat_symbol
#define compat_symbol(lib, name, alias, ver)
#define __round __round_power5plus
#include <sysdeps/powerpc/powerpc32/power5+/fpu/s_round.S>

View File

@ -0,0 +1,3 @@
#include <math.h>
#define __round __round_power5plus
#include <sysdeps/powerpc/fpu/s_round.c>

View File

@ -1,31 +0,0 @@
/* round function. PowerPC32 default version.
Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <math_ldbl_opt.h>
#undef weak_alias
#define weak_alias(a,b)
#undef strong_alias
#define strong_alias(a,b)
#undef compat_symbol
#define compat_symbol(a,b,c,d)
#define __round __round_ppc32
#include <sysdeps/powerpc/powerpc32/fpu/s_round.S>

View File

@ -0,0 +1,3 @@
#include <math.h>
#define __round __round_ppc32
#include <sysdeps/powerpc/fpu/s_round.c>

View File

@ -1,26 +0,0 @@
/* roundf function. PowerPC32/power5+ version.
Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#undef weak_alias
#define weak_alias(name, alias)
#define __roundf __roundf_power5plus
#include <sysdeps/powerpc/powerpc32/power5+/fpu/s_roundf.S>

View File

@ -0,0 +1,3 @@
#include <math.h>
#define __roundf __roundf_power5plus
#include <sysdeps/powerpc/fpu/s_roundf.c>

View File

@ -1,27 +0,0 @@
/* roundf function. PowerPC32 default version.
Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <math_ldbl_opt.h>
#undef weak_alias
#define weak_alias(a,b)
#define __roundf __roundf_ppc32
#include <sysdeps/powerpc/powerpc32/fpu/s_roundf.S>

View File

@ -0,0 +1,3 @@
#include <math.h>
#define __roundf __roundf_ppc32
#include <sysdeps/powerpc/fpu/s_roundf.c>

View File

@ -1,29 +0,0 @@
/* round function. PowerPC32/power5+ version.
Copyright (C) 2006-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <math_ldbl_opt.h>
#include <libm-alias-double.h>
.machine "power5"
EALIGN (__round, 4, 0)
frin fp1, fp1
blr
END (__round)
libm_alias_double (__round, round)

View File

@ -1,30 +0,0 @@
/* roundf function. PowerPC32/power5+ version.
Copyright (C) 2006-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <libm-alias-float.h>
.machine "power5"
EALIGN (__roundf, 4, 0)
frin fp1, fp1 /* The rounding instructions are double. */
frsp fp1, fp1 /* But we need to set ooverflow for float. */
blr
END (__roundf)
libm_alias_float (__round, round)

View File

@ -6,10 +6,16 @@ libm-sysdep_routines += s_ceil-power5+ \
s_floor-power5+ \
s_floor-ppc64 \
s_floorf-power5+ \
s_floorf-ppc64
s_floorf-ppc64 \
s_round-power5+ \
s_round-ppc64 \
s_roundf-power5+ \
s_roundf-ppc64
CFLAGS-s_ceil-power5+.c = -mcpu=power5+
CFLAGS-s_ceilf-power5+.c = -mcpu=power5+
CFLAGS-s_floor-power5+.c = -mcpu=power5+
CFLAGS-s_floorf-power5+.c = -mcpu=power5+
CFLAGS-s_round-power5+.c = -mcpu=power5+
CFLAGS-s_roundf-power5+.c = -mcpu=power5+
endif

View File

@ -0,0 +1,3 @@
#include <math.h>
#define __round __round_power5plus
#include <sysdeps/powerpc/fpu/s_round.c>

View File

@ -0,0 +1,3 @@
#include <math.h>
#define __round __round_ppc64
#include <sysdeps/powerpc/fpu/s_round.c>

View File

@ -0,0 +1,3 @@
#include <math.h>
#define __roundf __roundf_power5plus
#include <sysdeps/powerpc/fpu/s_roundf.c>

View File

@ -0,0 +1,3 @@
#include <math.h>
#define __roundf __roundf_ppc64
#include <sysdeps/powerpc/fpu/s_roundf.c>

View File

@ -15,8 +15,7 @@ sysdep_calls := s_copysign-power6 s_copysign-ppc64 \
sysdep_routines += $(sysdep_calls)
libm-sysdep_routines += s_llround-power6x \
s_llround-power5+ s_llround-ppc64 \
s_round-power5+ s_round-ppc64 \
s_roundf-power5+ s_roundf-ppc64 s_trunc-power5+ \
s_trunc-power5+ \
s_trunc-ppc64 s_truncf-power5+ s_truncf-ppc64 \
s_llrint-power6x s_llrint-ppc64 \
s_logb-power7 s_logbf-power7 \

View File

@ -1,30 +0,0 @@
/* round function. PowerPC64/power5+ version.
Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <shlib-compat.h>
#undef weak_alias
#define weak_alias(a,b)
#undef strong_alias
#define strong_alias(a,b)
#undef compat_symbol
#define compat_symbol(a,b,c,d)
#define __round __round_power5plus
#include <sysdeps/powerpc/powerpc64/power5+/fpu/s_round.S>

View File

@ -1,30 +0,0 @@
/* round function. PowerPC64 default version.
Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <shlib-compat.h>
#undef weak_alias
#define weak_alias(a,b)
#undef strong_alias
#define strong_alias(a,b)
#undef compat_symbol
#define compat_symbol(a,b,c,d)
#define __round __round_ppc64
#include <sysdeps/powerpc/powerpc64/fpu/s_round.S>

View File

@ -1,24 +0,0 @@
/* roundf function. PowerPC64/power5+ version.
Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#undef weak_alias
#define weak_alias(a,b)
#define __roundf __roundf_power5plus
#include <sysdeps/powerpc/powerpc64/power5+/fpu/s_roundf.S>

View File

@ -1,24 +0,0 @@
/* roundf function. PowerPC64 default version.
Copyright (C) 2013-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#undef weak_alias
#define weak_alias(a,b)
#define __roundf __roundf_ppc64
#include <sysdeps/powerpc/powerpc64/fpu/s_roundf.S>

View File

@ -1,80 +0,0 @@
/* round function. PowerPC64 version.
Copyright (C) 2004-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <math_ldbl_opt.h>
#include <libm-alias-double.h>
.section ".toc","aw"
.LC0: /* 2**52 */
.tc FD_43300000_0[TC],0x4330000000000000
.LC1: /* 0.5 */
.tc FD_3fe00000_0[TC],0x3fe0000000000000
.section ".text"
/* double [fp1] round (double x [fp1])
IEEE 1003.1 round function. IEEE specifies "round to the nearest
integer value, rounding halfway cases away from zero, regardless of
the current rounding mode." However PowerPC Architecture defines
"Round to Nearest" as "Choose the best approximation. In case of a
tie, choose the one that is even (least significant bit o).".
So we can't use the PowerPC "Round to Nearest" mode. Instead we set
"Round toward Zero" mode and round by adding +-0.5 before rounding
to the integer value. */
ENTRY (__round, 4)
CALL_MCOUNT 0
lfd fp13,.LC0@toc(2)
fabs fp0,fp1
fsub fp12,fp13,fp13 /* generate 0.0 */
fcmpu cr7,fp0,fp13 /* if (fabs(x) > TWO52) */
mffs fp11 /* Save current FPU rounding mode and
"inexact" state. */
fcmpu cr6,fp1,fp12 /* if (x > 0.0) */
bnl- cr7,.L10
mtfsfi 7,1 /* Set rounding mode toward 0. */
lfd fp10,.LC1@toc(2)
ble- cr6,.L4
fadd fp1,fp1,fp10 /* x+= 0.5; */
fadd fp1,fp1,fp13 /* x+= TWO52; */
fsub fp1,fp1,fp13 /* x-= TWO52; */
fabs fp1,fp1 /* if (x == 0.0) */
/* x = 0.0; */
mtfsf 0xff,fp11 /* Restore previous rounding mode and
"inexact" state. */
blr
.L4:
fsub fp9,fp1,fp10 /* x+= 0.5; */
bge- cr6,.L9 /* if (x < 0.0) */
fsub fp1,fp9,fp13 /* x-= TWO52; */
fadd fp1,fp1,fp13 /* x+= TWO52; */
fnabs fp1,fp1 /* if (x == 0.0) */
/* x = -0.0; */
.L9:
mtfsf 0xff,fp11 /* Restore previous rounding mode and
"inexact" state. */
blr
.L10:
/* Ensure sNaN input is converted to qNaN. */
fcmpu cr7,fp1,fp1
beqlr cr7
fadd fp1,fp1,fp1
blr
END (__round)
libm_alias_double (__round, round)

View File

@ -1,82 +0,0 @@
/* roundf function. PowerPC64 version.
Copyright (C) 2004-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <libm-alias-float.h>
.section ".toc","aw"
.p2align 3
.LC0: /* 2**23 */
.long 0x4b000000
.LC1: /* 0.5 */
.long 0x3f000000
.section ".text"
/* float [fp1] roundf (float x [fp1])
IEEE 1003.1 round function. IEEE specifies "round to the nearest
integer value, rounding halfway cases away from zero, regardless of
the current rounding mode." However PowerPC Architecture defines
"Round to Nearest" as "Choose the best approximation. In case of a
tie, choose the one that is even (least significant bit o).".
So we can't use the PowerPC "Round to Nearest" mode. Instead we set
"Round toward Zero" mode and round by adding +-0.5 before rounding
to the integer value. */
ENTRY (__roundf, 4)
CALL_MCOUNT 0
lfs fp13,.LC0@toc(2)
fabs fp0,fp1
fsubs fp12,fp13,fp13 /* generate 0.0 */
fcmpu cr7,fp0,fp13 /* if (fabs(x) > TWO23) */
mffs fp11 /* Save current FPU rounding mode and
"inexact" state. */
fcmpu cr6,fp1,fp12 /* if (x > 0.0) */
bnl- cr7,.L10
mtfsfi 7,1 /* Set rounding mode toward 0. */
lfs fp10,.LC1@toc(2)
ble- cr6,.L4
fadds fp1,fp1,fp10 /* x+= 0.5; */
fadds fp1,fp1,fp13 /* x+= TWO23; */
fsubs fp1,fp1,fp13 /* x-= TWO23; */
fabs fp1,fp1 /* if (x == 0.0) */
/* x = 0.0; */
mtfsf 0xff,fp11 /* Restore previous rounding mode and
"inexact" state. */
blr
.L4:
fsubs fp9,fp1,fp10 /* x+= 0.5; */
bge- cr6,.L9 /* if (x < 0.0) */
fsubs fp1,fp9,fp13 /* x-= TWO23; */
fadds fp1,fp1,fp13 /* x+= TWO23; */
fnabs fp1,fp1 /* if (x == 0.0) */
/* x = -0.0; */
.L9:
mtfsf 0xff,fp11 /* Restore previous rounding mode and
"inexact" state. */
blr
.L10:
/* Ensure sNaN input is converted to qNaN. */
fcmpu cr7,fp1,fp1
beqlr cr7
fadds fp1,fp1,fp1
blr
END (__roundf)
libm_alias_float (__round, round)

View File

@ -1,30 +0,0 @@
/* round function. PowerPC64/power5+ version.
Copyright (C) 2006-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <math_ldbl_opt.h>
#include <libm-alias-double.h>
.machine "power5"
ENTRY_TOCLESS (__round, 4)
CALL_MCOUNT 0
frin fp1, fp1
blr
END (__round)
libm_alias_double (__round, round)

View File

@ -1,31 +0,0 @@
/* roundf function. PowerPC64/power5+ version.
Copyright (C) 2006-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <libm-alias-float.h>
.machine "power5"
ENTRY_TOCLESS (__roundf, 4)
CALL_MCOUNT 0
frin fp1, fp1 /* The rounding instructions are double. */
frsp fp1, fp1 /* But we need to set ooverflow for float. */
blr
END (__roundf)
libm_alias_float (__round, round)