This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Implement C _FloatN, _FloatNx types [version 5]
- From: James Greenhalgh <james dot greenhalgh at arm dot com>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>, <fortran at gcc dot gnu dot org>, <jason at redhat dot com>, <richard dot earnshaw at arm dot com>, <nickc at redhat dot com>, <ramana dot radhakrishnan at arm dot com>, <marcus dot shawcroft at arm dot com>, <dje dot gcc at gmail dot com>, <segher at kernel dot crashing dot org>, <meissner at linux dot vnet dot ibm dot com>, <murphyp at linux dot vnet dot ibm dot com>, <nd at arm dot com>
- Date: Wed, 17 Aug 2016 16:42:44 +0100
- Subject: Re: Implement C _FloatN, _FloatNx types [version 5]
- Authentication-results: sourceware.org; auth=none
- Nodisclaimer: True
- References: <alpine.DEB.2.20.1606211202040.4526@digraph.polyomino.org.uk> <alpine.DEB.2.20.1606211738200.31330@digraph.polyomino.org.uk> <alpine.DEB.2.20.1606231418120.21240@digraph.polyomino.org.uk> <alpine.DEB.2.20.1606271720270.7438@digraph.polyomino.org.uk> <alpine.DEB.2.20.1607191347340.9265@digraph.polyomino.org.uk> <alpine.DEB.2.20.1607222158330.22448@digraph.polyomino.org.uk>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On Fri, Jul 22, 2016 at 09:59:33PM +0000, Joseph Myers wrote:
> Index: gcc/testsuite/gcc.dg/torture/fp-int-convert-float16-timode.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/torture/fp-int-convert-float16-timode.c (nonexistent)
> +++ gcc/testsuite/gcc.dg/torture/fp-int-convert-float16-timode.c (working copy)
> @@ -0,0 +1,15 @@
> +/* Test floating-point conversions. _Float16 type with TImode. */
> +/* { dg-do run } */
> +/* { dg-require-effective-target float16 } */
> +/* { dg-options "" } */
> +
> +#define __STDC_WANT_IEC_60559_TYPES_EXT__
> +#include <float.h>
> +#include "fp-int-convert.h"
> +
> +int
> +main (void)
> +{
> + TEST_I_F(TItype, UTItype, _Float16, FLT16_MANT_DIG);
> + exit (0);
> +}
> Index: gcc/testsuite/gcc.dg/torture/fp-int-convert-float16.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/torture/fp-int-convert-float16.c (nonexistent)
> +++ gcc/testsuite/gcc.dg/torture/fp-int-convert-float16.c (working copy)
> @@ -0,0 +1,19 @@
> +/* Test floating-point conversions. Standard types and _Float16. */
> +/* { dg-do run } */
> +/* { dg-require-effective-target float16 } */
> +/* { dg-options "" } */
> +
> +#define __STDC_WANT_IEC_60559_TYPES_EXT__
> +#include <float.h>
> +#include "fp-int-convert.h"
> +
> +int
> +main (void)
> +{
> + TEST_I_F(signed char, unsigned char, _Float16, FLT16_MANT_DIG);
> + TEST_I_F(signed short, unsigned short, _Float16, FLT16_MANT_DIG);
> + TEST_I_F(signed int, unsigned int, _Float16, FLT16_MANT_DIG);
> + TEST_I_F(signed long, unsigned long, _Float16, FLT16_MANT_DIG);
> + TEST_I_F(signed long long, unsigned long long, _Float16, FLT16_MANT_DIG);
> + exit (0);
> +}
Hi Joseph,
These tests will fail for _Float16 implementations.
One of the tests in fp-int-convert.h tries to convert to and from
0x8..0 in the width of the unsigned integer mode. But 0x8..0 is not
representable in a 16-bit float for any of unsigned int, unsigned long,
unsigned long long, or UTItype so the check that conversion to and from
16-bit float returns the input value will fail.
The relevant line in testsuite/gcc.dg/torture/fp-int-convert.h is:
TEST_I_F_VAL (U, F, (U)~(((U)~(U)0) >> 1), 1);
The reduced, preprocessed test below should show the issue I am referring
to clearly:
extern void abort(void);
extern void exit(int);
typedef int int128_t __attribute__((mode(TI)));
typedef unsigned int uint128_t __attribute__((mode(TI)));
int main (int argc, char** argv)
{
static volatile uint128_t ivin, ivout;
static volatile _Float16 fv1, fv2;
ivin = ~((~(uint128_t)0) >> 1);
fv1 = ~((~(uint128_t)0) >> 1);
fv2 = ivin;
ivout = fv2;
if (ivout != ivin)
abort ();
}
This test will always abort for a _Float16 implementation.
The obvious fix would be this modification to fp-int-convert.h:
- TEST_I_F_VAL (U, F, (U)~(((U)~(U)0) >> 1), 1); \
+ TEST_I_F_VAL (U, F, (U)~(((U)~(U)0) >> 1), P_OK1 (P, U)); \
Thanks,
James