[fold-const] Fix native_encode_real for HFmode constants
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Wed, 5 Oct 2016 14:57:14 +0000 (14:57 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Wed, 5 Oct 2016 14:57:14 +0000 (14:57 +0000)
* fold-const.c (native_encode_real): Fix logic for selecting offset
to write to when BYTES_BIG_ENDIAN.

From-SVN: r240791

gcc/ChangeLog
gcc/fold-const.c

index 81e4235d2e45bdd2080edcca899ab54e46f0ade8..6b4dc9cd14504fe2663af27fd11b7212b31ca87e 100644 (file)
@@ -1,3 +1,8 @@
+2016-10-05  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * fold-const.c (native_encode_real): Fix logic for selecting offset
+       to write to when BYTES_BIG_ENDIAN.
+
 2016-10-05  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * builtins.c (fold_builtin_strchr): Remove function.
index a6b7ec7dfeced0a019ce2b7d4c2ee6abde25e84b..65c75f639315d620eddfef3d8362b4902d28440a 100644 (file)
@@ -7142,7 +7142,16 @@ native_encode_real (const_tree expr, unsigned char *ptr, int len, int off)
            offset += byte % UNITS_PER_WORD;
        }
       else
-       offset = BYTES_BIG_ENDIAN ? 3 - byte : byte;
+       {
+         offset = byte;
+         if (BYTES_BIG_ENDIAN)
+           {
+             /* Reverse bytes within each long, or within the entire float
+                if it's smaller than a long (for HFmode).  */
+             offset = MIN (3, total_bytes - 1) - offset;
+             gcc_assert (offset >= 0);
+           }
+       }
       offset = offset + ((bitpos / BITS_PER_UNIT) & ~3);
       if (offset >= off
          && offset - off < len)