This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 06/28] powerpc: round/roundf refactor
- From: "Gabriel F. T. Gomes" <gabriel at inconstante dot eti dot br>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: <libc-alpha at sourceware dot org>
- Date: Fri, 3 May 2019 22:10:31 -0300
- Subject: Re: [PATCH 06/28] powerpc: round/roundf refactor
- References: <20190329133529.22523-1-adhemerval.zanella@linaro.org> <20190329133529.22523-7-adhemerval.zanella@linaro.org>
On Fri, Mar 29 2019, Adhemerval Zanella wrote:
>
> * sysdeps/powerpc/fpu/round_to_integer.h (set_rounding_mode): Add
> ROUND handling.
> (round_to_integer_float): Likewise.
Similar to what I mentioned for the floor patch, just make sure you
mention the addition of the ROUND definition.
> diff --git a/sysdeps/powerpc/fpu/round_to_integer.h b/sysdeps/powerpc/fpu/round_to_integer.h
> index 77d9fc1f86..3fa2b77b6d 100644
> --- a/sysdeps/powerpc/fpu/round_to_integer.h
> +++ b/sysdeps/powerpc/fpu/round_to_integer.h
> @@ -38,6 +38,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;
> }
Likewise, check that the FLOOR definition is added to round_mode.
This patch looks good to me with these changes.
Reviewed-by: Gabriel F. T. Gomes <gabriel@inconstante.eti.br>
> @@ -60,12 +61,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);
OK. Restored from the .S files.
> @@ -92,12 +105,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);
OK. Likewise.
> +double
> +__round (double x)
> +{
> +#ifdef _ARCH_PWR5X
> + return __builtin_round (x);
> +#else
> + return round_to_integer_double (ROUND, x);
> +#endif
> +}
OK. Arch check looks correct.
> -.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. */
>
> [...]
>
> -#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; */
OK. Moved to round_to_integer_float and round_to_integer_double.