[PATCH] BZ#887 logb[l](1) shows negative sign on zero in FE_DOWNWARD rounding mode

Andreas Jaeger aj@suse.com
Fri Apr 27 07:06:00 GMT 2012


On 04/26/2012 09:16 PM, Ryan Arnold wrote:
> On POWER4 PowerPC32 for logb(1) and POWER[4|5|6] PowerPC32 for logbl(1)
> in FE_DOWNWARD rounding mode the result is -0.0, which is contrary to
> IEEE 754-2008 (section 5.3.3).
>
> This is bugzilla bug #887:
>
> http://sourceware.org/bugzilla/show_bug.cgi?id=887
>
> This is due to the nature of the Power Architecture fsub instruction
> under hardware rounding mode FE_DOWNWARD.
>
> GCC recently introduced the ability to use the fcfid instruction in
> 32-bit mode on power4, which fixes the issue for logb(1) and expanded
> the use of fcfid for power6 which corrected the issue for logbl(1).
>
> r186387 | meissner | 2012-04-12 13:10:27 -0400 (Thu, 12 Apr 2012) | 16 lines
> [gcc]
> 2012-04-11  Michael Meissner<meissner@linux.vnet.ibm.com>
>           PR target/52775
>           * config/rs6000/rs6000.h (TARGET_FCFID): Add TARGET_PPC_GPOPT to
>           the list of options to enable the FCFID instruction.
>           (TARGET_EXTRA_BUILTINS): Adjust comment.
>
> The included patch adds a test case to the libm test suite to detect
> this issue if the compiler ever regresses.
>
> I couldn't reproduce a similar nextafter() failure per the initial bug
> report so I assume it's been fixed.
>
> Ryan S. Arnold
> IBM Linux Technology Center
>
> 2012-04-26  Ryan S. Arnold<rsa@linux.vnet.ibm.com>
>
> 	[BZ #887]
> 	* math/libm-test.inc (logb_test_downward): New test to expose
> 	erroneous negative sign on -0.0 result of logb[l](1) in FE_DOWNWARD
> 	rounding mode.
>
> diff --git a/math/libm-test.inc b/math/libm-test.inc
> index e0ac613..81de85b 100644
> --- a/math/libm-test.inc
> +++ b/math/libm-test.inc
> @@ -5101,6 +5101,40 @@ logb_test (void)
>     END (logb);
>   }
>
> +static void
> +logb_test_downward (void)
> +{
> +  int save_round_mode;
> +  errno = 0;
> +
> +  FUNC(logb) (0);
> +  if (errno == ENOSYS)
> +    /* Function not implemented.  */
> +    return;
> +
> +  START (logb_downward);
> +
> +  save_round_mode = fegetround ();
> +
> +  if (!fesetround (FE_DOWNWARD))
> +    {
> +
> +      /* IEEE 754-2008 says (section 5.3.3) that "logB(1) is +0.".  Libm
> +       * should not return -0 from logb in any rounding mode.  PowerPC32 has
> +       * failed with this test for power4 logb (and logbl on all PowerPC
> +       * platforms) in the past due to instruction selection.  GCC PR 52775
> +       * provides the availability of the fcfid insn in 32-bit mode which
> +       * eliminates the use of fsub in this instance and prevents the negative
> +       * signed 0.0.  */

Please remove the leading '*' and reformat.

> +      /* BZ #887 .*/

Two spaces after the "."

Ok with those changes.

Thanks,
Andreas

> +      TEST_f_f (logb, 1.000e+0, plus_zero);
> +    }
> +
> +  fesetround (save_round_mode);
> +
> +  END (logb_downward);
> +}
>
>   static void
>   lround_test (void)
> @@ -8210,6 +8244,7 @@ main (int argc, char **argv)
>     log1p_test ();
>     log2_test ();
>     logb_test ();
> +  logb_test_downward ();
>     modf_test ();
>     ilogb_test ();
>     scalb_test ();
>
>


-- 
  Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
   SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
    GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
     GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126



More information about the Libc-alpha mailing list