From: Richard Earnshaw Date: Thu, 24 Sep 2015 09:40:06 +0000 (+0000) Subject: ARM: fp16 Fix PR 67624 - Incorrect conversion of float Infinity to __fp16 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4dfe21acc2072b7dd35cd57ced94cf880b896158;p=gcc.git ARM: fp16 Fix PR 67624 - Incorrect conversion of float Infinity to __fp16 PR libgcc/67624 libgcc: * config/arm/fp16.c (__gnu_f2h_internal): Handle infinity correctly. gcc/testsuite: * gcc.target/arm/fp16-inf.c: New test. From-SVN: r228082 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6dc9d9ea739..fe4f67f7000 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-09-24 Richard Earnshaw + + PR libgcc/67624 + * gcc.target/arm/fp16-inf.c: New test. + 2015-09-24 Kirill Yukhin * gcc.target/i386/avx512vbmi-check.h (main): Fix register diff --git a/gcc/testsuite/gcc.target/arm/fp16-inf.c b/gcc/testsuite/gcc.target/arm/fp16-inf.c new file mode 100644 index 00000000000..ce5c197c121 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/fp16-inf.c @@ -0,0 +1,14 @@ +/* { dg-do run } */ +/* { dg-options "-O -mfp16-format=ieee" } */ + +/* Conversion of infinity to __fp16 and back again should preserve the + value. */ +volatile float f = __builtin_inf (); + +int main () +{ + __fp16 h = f; + if (h != __builtin_inf ()) + __builtin_abort (); + return 0; +} diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index cc5c2c3903b..dee1c115280 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,8 @@ +2015-09-24 Richard Earnshaw + + PR libgcc/67624 + * config/arm/fp16.c (__gnu_f2h_internal): Handle infinity correctly. + 2015-09-24 Rainer Orth * config.host (*-*-solaris2*): Add t-crtstuff-pic to tmake_file. diff --git a/libgcc/config/arm/fp16.c b/libgcc/config/arm/fp16.c index 86a6348aecf..8eaae2b84e7 100644 --- a/libgcc/config/arm/fp16.c +++ b/libgcc/config/arm/fp16.c @@ -35,9 +35,12 @@ __gnu_f2h_internal(unsigned int a, int ieee) { if (!ieee) return sign; + if (mantissa == 0) + return sign | 0x7c00; /* Infinity. */ + /* Remaining cases are NaNs. Convert SNaN to QNaN. */ return sign | 0x7e00 | (mantissa >> 13); } - + if (aexp == 0 && mantissa == 0) return sign; @@ -49,7 +52,7 @@ __gnu_f2h_internal(unsigned int a, int ieee) { mask = 0x00ffffff; if (aexp >= -25) - mask >>= 25 + aexp; + mask >>= 25 + aexp; } else mask = 0x00001fff;