LCOV - code coverage report
Current view: top level - gcc - real.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 84.3 % 2228 1878
Test Date: 2024-03-23 14:05:01 Functions: 87.4 % 135 118
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* real.cc - software floating point emulation.
       2                 :             :    Copyright (C) 1993-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Stephen L. Moshier (moshier@world.std.com).
       4                 :             :    Re-written by Richard Henderson <rth@redhat.com>
       5                 :             : 
       6                 :             :    This file is part of GCC.
       7                 :             : 
       8                 :             :    GCC is free software; you can redistribute it and/or modify it under
       9                 :             :    the terms of the GNU General Public License as published by the Free
      10                 :             :    Software Foundation; either version 3, or (at your option) any later
      11                 :             :    version.
      12                 :             : 
      13                 :             :    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      14                 :             :    WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15                 :             :    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      16                 :             :    for more details.
      17                 :             : 
      18                 :             :    You should have received a copy of the GNU General Public License
      19                 :             :    along with GCC; see the file COPYING3.  If not see
      20                 :             :    <http://www.gnu.org/licenses/>.  */
      21                 :             : 
      22                 :             : #include "config.h"
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "tm.h"
      26                 :             : #include "rtl.h"
      27                 :             : #include "tree.h"
      28                 :             : #include "realmpfr.h"
      29                 :             : #include "dfp.h"
      30                 :             : 
      31                 :             : /* The floating point model used internally is not exactly IEEE 754
      32                 :             :    compliant, and close to the description in the ISO C99 standard,
      33                 :             :    section 5.2.4.2.2 Characteristics of floating types.
      34                 :             : 
      35                 :             :    Specifically
      36                 :             : 
      37                 :             :         x = s * b^e * \sum_{k=1}^p f_k * b^{-k}
      38                 :             : 
      39                 :             :         where
      40                 :             :                 s = sign (+- 1)
      41                 :             :                 b = base or radix, here always 2
      42                 :             :                 e = exponent
      43                 :             :                 p = precision (the number of base-b digits in the significand)
      44                 :             :                 f_k = the digits of the significand.
      45                 :             : 
      46                 :             :    We differ from typical IEEE 754 encodings in that the entire
      47                 :             :    significand is fractional.  Normalized significands are in the
      48                 :             :    range [0.5, 1.0).
      49                 :             : 
      50                 :             :    A requirement of the model is that P be larger than the largest
      51                 :             :    supported target floating-point type by at least 2 bits.  This gives
      52                 :             :    us proper rounding when we truncate to the target type.  In addition,
      53                 :             :    E must be large enough to hold the smallest supported denormal number
      54                 :             :    in a normalized form.
      55                 :             : 
      56                 :             :    Both of these requirements are easily satisfied.  The largest target
      57                 :             :    significand is 113 bits; we store at least 160.  The smallest
      58                 :             :    denormal number fits in 17 exponent bits; we store 26.  */
      59                 :             : 
      60                 :             : 
      61                 :             : /* Used to classify two numbers simultaneously.  */
      62                 :             : #define CLASS2(A, B)  ((A) << 2 | (B))
      63                 :             : 
      64                 :             : #if HOST_BITS_PER_LONG != 64 && HOST_BITS_PER_LONG != 32
      65                 :             :  #error "Some constant folding done by hand to avoid shift count warnings"
      66                 :             : #endif
      67                 :             : 
      68                 :             : static void get_zero (REAL_VALUE_TYPE *, int);
      69                 :             : static void get_canonical_qnan (REAL_VALUE_TYPE *, int);
      70                 :             : static void get_canonical_snan (REAL_VALUE_TYPE *, int);
      71                 :             : static void get_inf (REAL_VALUE_TYPE *, int);
      72                 :             : static bool sticky_rshift_significand (REAL_VALUE_TYPE *,
      73                 :             :                                        const REAL_VALUE_TYPE *, unsigned int);
      74                 :             : static void rshift_significand (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *,
      75                 :             :                                 unsigned int);
      76                 :             : static void lshift_significand (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *,
      77                 :             :                                 unsigned int);
      78                 :             : static void lshift_significand_1 (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
      79                 :             : static bool add_significands (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *,
      80                 :             :                               const REAL_VALUE_TYPE *);
      81                 :             : static bool sub_significands (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *,
      82                 :             :                               const REAL_VALUE_TYPE *, int);
      83                 :             : static void neg_significand (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
      84                 :             : static int cmp_significands (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
      85                 :             : static int cmp_significand_0 (const REAL_VALUE_TYPE *);
      86                 :             : static void set_significand_bit (REAL_VALUE_TYPE *, unsigned int);
      87                 :             : static void clear_significand_bit (REAL_VALUE_TYPE *, unsigned int);
      88                 :             : static bool test_significand_bit (REAL_VALUE_TYPE *, unsigned int);
      89                 :             : static void clear_significand_below (REAL_VALUE_TYPE *, unsigned int);
      90                 :             : static bool div_significands (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *,
      91                 :             :                               const REAL_VALUE_TYPE *);
      92                 :             : static void normalize (REAL_VALUE_TYPE *);
      93                 :             : 
      94                 :             : static bool do_add (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *,
      95                 :             :                     const REAL_VALUE_TYPE *, int);
      96                 :             : static bool do_multiply (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *,
      97                 :             :                          const REAL_VALUE_TYPE *);
      98                 :             : static bool do_divide (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *,
      99                 :             :                        const REAL_VALUE_TYPE *);
     100                 :             : static int do_compare (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *, int);
     101                 :             : static void do_fix_trunc (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
     102                 :             : 
     103                 :             : static unsigned long rtd_divmod (REAL_VALUE_TYPE *, REAL_VALUE_TYPE *);
     104                 :             : static void decimal_from_integer (REAL_VALUE_TYPE *);
     105                 :             : static void decimal_integer_string (char *, const REAL_VALUE_TYPE *,
     106                 :             :                                     size_t);
     107                 :             : 
     108                 :             : static const REAL_VALUE_TYPE * ten_to_ptwo (int);
     109                 :             : static const REAL_VALUE_TYPE * ten_to_mptwo (int);
     110                 :             : static const REAL_VALUE_TYPE * real_digit (int);
     111                 :             : static void times_pten (REAL_VALUE_TYPE *, int);
     112                 :             : 
     113                 :             : static void round_for_format (const struct real_format *, REAL_VALUE_TYPE *);
     114                 :             : 
     115                 :             : /* Determine whether a floating-point value X is a denormal.  R is
     116                 :             :    expected to be in denormal form, so this function is only
     117                 :             :    meaningful after a call to round_for_format.  */
     118                 :             : 
     119                 :             : static inline bool
     120                 :     1571794 : real_isdenormal (const REAL_VALUE_TYPE *r)
     121                 :             : {
     122                 :     1571794 :   return r->cl == rvc_normal && (r->sig[SIGSZ-1] & SIG_MSB) == 0;
     123                 :             : }
     124                 :             : 
     125                 :             : /* Initialize R with a positive zero.  */
     126                 :             : 
     127                 :             : static inline void
     128                 :   119908072 : get_zero (REAL_VALUE_TYPE *r, int sign)
     129                 :             : {
     130                 :   119908072 :   memset (r, 0, sizeof (*r));
     131                 :   119908072 :   r->sign = sign;
     132                 :     4431955 : }
     133                 :             : 
     134                 :             : /* Initialize R with the canonical quiet NaN.  */
     135                 :             : 
     136                 :             : static inline void
     137                 :      234291 : get_canonical_qnan (REAL_VALUE_TYPE *r, int sign)
     138                 :             : {
     139                 :      234291 :   memset (r, 0, sizeof (*r));
     140                 :      234291 :   r->cl = rvc_nan;
     141                 :      234291 :   r->sign = sign;
     142                 :      234291 :   r->canonical = 1;
     143                 :      231662 : }
     144                 :             : 
     145                 :             : static inline void
     146                 :      144574 : get_canonical_snan (REAL_VALUE_TYPE *r, int sign)
     147                 :             : {
     148                 :      144574 :   memset (r, 0, sizeof (*r));
     149                 :      144574 :   r->cl = rvc_nan;
     150                 :      144574 :   r->sign = sign;
     151                 :      144574 :   r->signalling = 1;
     152                 :      144574 :   r->canonical = 1;
     153                 :      144558 : }
     154                 :             : 
     155                 :             : static inline void
     156                 :     6608562 : get_inf (REAL_VALUE_TYPE *r, int sign)
     157                 :             : {
     158                 :     6608562 :   memset (r, 0, sizeof (*r));
     159                 :     6608562 :   r->cl = rvc_inf;
     160                 :     6608562 :   r->sign = sign;
     161                 :     2496935 : }
     162                 :             : 
     163                 :             : 
     164                 :             : /* Right-shift the significand of A by N bits; put the result in the
     165                 :             :    significand of R.  If any one bits are shifted out, return true.  */
     166                 :             : 
     167                 :             : static bool
     168                 :    95414357 : sticky_rshift_significand (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a,
     169                 :             :                            unsigned int n)
     170                 :             : {
     171                 :    95414357 :   unsigned long sticky = 0;
     172                 :    95414357 :   unsigned int i, ofs = 0;
     173                 :             : 
     174                 :    95414357 :   if (n >= HOST_BITS_PER_LONG)
     175                 :             :     {
     176                 :      157112 :       for (i = 0, ofs = n / HOST_BITS_PER_LONG; i < ofs; ++i)
     177                 :       80400 :         sticky |= a->sig[i];
     178                 :       76712 :       n &= HOST_BITS_PER_LONG - 1;
     179                 :             :     }
     180                 :             : 
     181                 :    95414357 :   if (n != 0)
     182                 :             :     {
     183                 :    95410907 :       sticky |= a->sig[ofs] & (((unsigned long)1 << n) - 1);
     184                 :   381643628 :       for (i = 0; i < SIGSZ; ++i)
     185                 :             :         {
     186                 :   286232721 :           r->sig[i]
     187                 :   286232721 :             = (((ofs + i >= SIGSZ ? 0 : a->sig[ofs + i]) >> n)
     188                 :   286232721 :                | ((ofs + i + 1 >= SIGSZ ? 0 : a->sig[ofs + i + 1])
     189                 :   286232721 :                   << (HOST_BITS_PER_LONG - n)));
     190                 :             :         }
     191                 :             :     }
     192                 :             :   else
     193                 :             :     {
     194                 :        9939 :       for (i = 0; ofs + i < SIGSZ; ++i)
     195                 :        6489 :         r->sig[i] = a->sig[ofs + i];
     196                 :        7311 :       for (; i < SIGSZ; ++i)
     197                 :        3861 :         r->sig[i] = 0;
     198                 :             :     }
     199                 :             : 
     200                 :    95414357 :   return sticky != 0;
     201                 :             : }
     202                 :             : 
     203                 :             : /* Right-shift the significand of A by N bits; put the result in the
     204                 :             :    significand of R.  */
     205                 :             : 
     206                 :             : static void
     207                 :       93719 : rshift_significand (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a,
     208                 :             :                     unsigned int n)
     209                 :             : {
     210                 :       93719 :   unsigned int i, ofs = n / HOST_BITS_PER_LONG;
     211                 :             : 
     212                 :       93719 :   n &= HOST_BITS_PER_LONG - 1;
     213                 :       93719 :   if (n != 0)
     214                 :             :     {
     215                 :      374876 :       for (i = 0; i < SIGSZ; ++i)
     216                 :             :         {
     217                 :      281157 :           r->sig[i]
     218                 :      281157 :             = (((ofs + i >= SIGSZ ? 0 : a->sig[ofs + i]) >> n)
     219                 :      281157 :                | ((ofs + i + 1 >= SIGSZ ? 0 : a->sig[ofs + i + 1])
     220                 :      281157 :                   << (HOST_BITS_PER_LONG - n)));
     221                 :             :         }
     222                 :             :     }
     223                 :             :   else
     224                 :             :     {
     225                 :           0 :       for (i = 0; ofs + i < SIGSZ; ++i)
     226                 :           0 :         r->sig[i] = a->sig[ofs + i];
     227                 :           0 :       for (; i < SIGSZ; ++i)
     228                 :           0 :         r->sig[i] = 0;
     229                 :             :     }
     230                 :       93719 : }
     231                 :             : 
     232                 :             : /* Left-shift the significand of A by N bits; put the result in the
     233                 :             :    significand of R.  */
     234                 :             : 
     235                 :             : static void
     236                 :   133106158 : lshift_significand (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a,
     237                 :             :                     unsigned int n)
     238                 :             : {
     239                 :   133106158 :   unsigned int i, ofs = n / HOST_BITS_PER_LONG;
     240                 :             : 
     241                 :   133106158 :   n &= HOST_BITS_PER_LONG - 1;
     242                 :   133106158 :   if (n == 0)
     243                 :             :     {
     244                 :       58366 :       for (i = 0; ofs + i < SIGSZ; ++i)
     245                 :       38673 :         r->sig[SIGSZ-1-i] = a->sig[SIGSZ-1-i-ofs];
     246                 :       40099 :       for (; i < SIGSZ; ++i)
     247                 :       20406 :         r->sig[SIGSZ-1-i] = 0;
     248                 :             :     }
     249                 :             :   else
     250                 :   532345860 :     for (i = 0; i < SIGSZ; ++i)
     251                 :             :       {
     252                 :   798518790 :         r->sig[SIGSZ-1-i]
     253                 :   399259395 :           = (((ofs + i >= SIGSZ ? 0 : a->sig[SIGSZ-1-i-ofs]) << n)
     254                 :   399259395 :              | ((ofs + i + 1 >= SIGSZ ? 0 : a->sig[SIGSZ-1-i-ofs-1])
     255                 :   399259395 :                 >> (HOST_BITS_PER_LONG - n)));
     256                 :             :       }
     257                 :   133106158 : }
     258                 :             : 
     259                 :             : /* Likewise, but N is specialized to 1.  */
     260                 :             : 
     261                 :             : static inline void
     262                 :  1027304669 : lshift_significand_1 (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a)
     263                 :             : {
     264                 :  1027304669 :   unsigned int i;
     265                 :             : 
     266                 :  3081914007 :   for (i = SIGSZ - 1; i > 0; --i)
     267                 :  2054609338 :     r->sig[i] = (a->sig[i] << 1) | (a->sig[i-1] >> (HOST_BITS_PER_LONG - 1));
     268                 :  1027304669 :   r->sig[0] = a->sig[0] << 1;
     269                 :  1027304669 : }
     270                 :             : 
     271                 :             : /* Add the significands of A and B, placing the result in R.  Return
     272                 :             :    true if there was carry out of the most significant word.  */
     273                 :             : 
     274                 :             : static inline bool
     275                 :    96327169 : add_significands (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a,
     276                 :             :                   const REAL_VALUE_TYPE *b)
     277                 :             : {
     278                 :    96327169 :   bool carry = false;
     279                 :    96327169 :   int i;
     280                 :             : 
     281                 :   385308676 :   for (i = 0; i < SIGSZ; ++i)
     282                 :             :     {
     283                 :   288981507 :       unsigned long ai = a->sig[i];
     284                 :   288981507 :       unsigned long ri = ai + b->sig[i];
     285                 :             : 
     286                 :   288981507 :       if (carry)
     287                 :             :         {
     288                 :     7417125 :           carry = ri < ai;
     289                 :     7417125 :           carry |= ++ri == 0;
     290                 :             :         }
     291                 :             :       else
     292                 :   281564382 :         carry = ri < ai;
     293                 :             : 
     294                 :   288981507 :       r->sig[i] = ri;
     295                 :             :     }
     296                 :             : 
     297                 :    96327169 :   return carry;
     298                 :             : }
     299                 :             : 
     300                 :             : /* Subtract the significands of A and B, placing the result in R.  CARRY is
     301                 :             :    true if there's a borrow incoming to the least significant word.
     302                 :             :    Return true if there was borrow out of the most significant word.  */
     303                 :             : 
     304                 :             : static inline bool
     305                 :   388150553 : sub_significands (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a,
     306                 :             :                   const REAL_VALUE_TYPE *b, int carry)
     307                 :             : {
     308                 :   388150553 :   int i;
     309                 :             : 
     310                 :  1552602212 :   for (i = 0; i < SIGSZ; ++i)
     311                 :             :     {
     312                 :  1164451659 :       unsigned long ai = a->sig[i];
     313                 :  1164451659 :       unsigned long ri = ai - b->sig[i];
     314                 :             : 
     315                 :  1164451659 :       if (carry)
     316                 :             :         {
     317                 :    84425113 :           carry = ri > ai;
     318                 :    84425113 :           carry |= ~--ri == 0;
     319                 :             :         }
     320                 :             :       else
     321                 :  1080026546 :         carry = ri > ai;
     322                 :             : 
     323                 :  1164451659 :       r->sig[i] = ri;
     324                 :             :     }
     325                 :             : 
     326                 :   388150553 :   return carry;
     327                 :             : }
     328                 :             : 
     329                 :             : /* Negate the significand A, placing the result in R.  */
     330                 :             : 
     331                 :             : static inline void
     332                 :        7610 : neg_significand (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a)
     333                 :             : {
     334                 :        7610 :   bool carry = true;
     335                 :        7610 :   int i;
     336                 :             : 
     337                 :       30440 :   for (i = 0; i < SIGSZ; ++i)
     338                 :             :     {
     339                 :       22830 :       unsigned long ri, ai = a->sig[i];
     340                 :             : 
     341                 :       22830 :       if (carry)
     342                 :             :         {
     343                 :       21882 :           if (ai)
     344                 :             :             {
     345                 :        7610 :               ri = -ai;
     346                 :        7610 :               carry = false;
     347                 :             :             }
     348                 :             :           else
     349                 :             :             ri = ai;
     350                 :             :         }
     351                 :             :       else
     352                 :         948 :         ri = ~ai;
     353                 :             : 
     354                 :       22830 :       r->sig[i] = ri;
     355                 :             :     }
     356                 :        7610 : }
     357                 :             : 
     358                 :             : /* Compare significands.  Return tri-state vs zero.  */
     359                 :             : 
     360                 :             : static inline int
     361                 :     1090843 : cmp_significands (const REAL_VALUE_TYPE *a, const REAL_VALUE_TYPE *b)
     362                 :             : {
     363                 :     1090843 :   int i;
     364                 :             : 
     365                 :   861747557 :   for (i = SIGSZ - 1; i >= 0; --i)
     366                 :             :     {
     367                 :   852313358 :       unsigned long ai = a->sig[i];
     368                 :   852313358 :       unsigned long bi = b->sig[i];
     369                 :             : 
     370                 :   852313358 :       if (ai > bi)
     371                 :             :         return 1;
     372                 :   690316251 :       if (ai < bi)
     373                 :             :         return -1;
     374                 :             :     }
     375                 :             : 
     376                 :             :   return 0;
     377                 :             : }
     378                 :             : 
     379                 :             : /* Return true if A is nonzero.  */
     380                 :             : 
     381                 :             : static inline int
     382                 :    26563675 : cmp_significand_0 (const REAL_VALUE_TYPE *a)
     383                 :             : {
     384                 :    26563675 :   int i;
     385                 :             : 
     386                 :    27209519 :   for (i = SIGSZ - 1; i >= 0; --i)
     387                 :    27113848 :     if (a->sig[i])
     388                 :             :       return 1;
     389                 :             : 
     390                 :             :   return 0;
     391                 :             : }
     392                 :             : 
     393                 :             : /* Set bit N of the significand of R.  */
     394                 :             : 
     395                 :             : static inline void
     396                 :   369274094 : set_significand_bit (REAL_VALUE_TYPE *r, unsigned int n)
     397                 :             : {
     398                 :   369274094 :   r->sig[n / HOST_BITS_PER_LONG]
     399                 :   369274094 :     |= (unsigned long)1 << (n % HOST_BITS_PER_LONG);
     400                 :   365796608 : }
     401                 :             : 
     402                 :             : /* Clear bit N of the significand of R.  */
     403                 :             : 
     404                 :             : static inline void
     405                 :      169135 : clear_significand_bit (REAL_VALUE_TYPE *r, unsigned int n)
     406                 :             : {
     407                 :      169135 :   r->sig[n / HOST_BITS_PER_LONG]
     408                 :      169135 :     &= ~((unsigned long)1 << (n % HOST_BITS_PER_LONG));
     409                 :           0 : }
     410                 :             : 
     411                 :             : /* Test bit N of the significand of R.  */
     412                 :             : 
     413                 :             : static inline bool
     414                 :    33153252 : test_significand_bit (REAL_VALUE_TYPE *r, unsigned int n)
     415                 :             : {
     416                 :             :   /* ??? Compiler bug here if we return this expression directly.
     417                 :             :      The conversion to bool strips the "&1" and we wind up testing
     418                 :             :      e.g. 2 != 0 -> true.  Seen in gcc version 3.2 20020520.  */
     419                 :    33153252 :   int t = (r->sig[n / HOST_BITS_PER_LONG] >> (n % HOST_BITS_PER_LONG)) & 1;
     420                 :    33153252 :   return t;
     421                 :             : }
     422                 :             : 
     423                 :             : /* Clear bits 0..N-1 of the significand of R.  */
     424                 :             : 
     425                 :             : static void
     426                 :    35187661 : clear_significand_below (REAL_VALUE_TYPE *r, unsigned int n)
     427                 :             : {
     428                 :    35187661 :   int i, w = n / HOST_BITS_PER_LONG;
     429                 :             : 
     430                 :   102739524 :   for (i = 0; i < w; ++i)
     431                 :    67551863 :     r->sig[i] = 0;
     432                 :             : 
     433                 :             :   /* We are actually passing N == SIGNIFICAND_BITS which would result
     434                 :             :      in an out-of-bound access below.  */
     435                 :    35187633 :   if (n % HOST_BITS_PER_LONG != 0)
     436                 :    22288496 :     r->sig[w] &= ~(((unsigned long)1 << (n % HOST_BITS_PER_LONG)) - 1);
     437                 :    35187633 : }
     438                 :             : 
     439                 :             : /* Divide the significands of A and B, placing the result in R.  Return
     440                 :             :    true if the division was inexact.  */
     441                 :             : 
     442                 :             : static inline bool
     443                 :     5236755 : div_significands (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a,
     444                 :             :                   const REAL_VALUE_TYPE *b)
     445                 :             : {
     446                 :     5236755 :   REAL_VALUE_TYPE u;
     447                 :     5236755 :   int i, bit = SIGNIFICAND_BITS - 1;
     448                 :     5236755 :   unsigned long msb, inexact;
     449                 :             : 
     450                 :     5236755 :   u = *a;
     451                 :     5236755 :   memset (r->sig, 0, sizeof (r->sig));
     452                 :             : 
     453                 :     5236755 :   msb = 0;
     454                 :     5236755 :   goto start;
     455                 :  1000220205 :   do
     456                 :             :     {
     457                 :  1000220205 :       msb = u.sig[SIGSZ-1] & SIG_MSB;
     458                 :  1000220205 :       lshift_significand_1 (&u, &u);
     459                 :  1005456960 :     start:
     460                 :  1793975188 :       if (msb || cmp_significands (&u, b) >= 0)
     461                 :             :         {
     462                 :   365627473 :           sub_significands (&u, &u, b, 0);
     463                 :   365627473 :           set_significand_bit (r, bit);
     464                 :             :         }
     465                 :             :     }
     466                 :  1005456960 :   while (--bit >= 0);
     467                 :             : 
     468                 :    20947020 :   for (i = 0, inexact = 0; i < SIGSZ; i++)
     469                 :    15710265 :     inexact |= u.sig[i];
     470                 :             : 
     471                 :     5236755 :   return inexact != 0;
     472                 :             : }
     473                 :             : 
     474                 :             : /* Adjust the exponent and significand of R such that the most
     475                 :             :    significant bit is set.  We underflow to zero and overflow to
     476                 :             :    infinity here, without denormals.  (The intermediate representation
     477                 :             :    exponent is large enough to handle target denormals normalized.)  */
     478                 :             : 
     479                 :             : static void
     480                 :   425547435 : normalize (REAL_VALUE_TYPE *r)
     481                 :             : {
     482                 :   425547435 :   int shift = 0, exp;
     483                 :   425547435 :   int i, j;
     484                 :             : 
     485                 :   425547435 :   if (r->decimal)
     486                 :             :     return;
     487                 :             : 
     488                 :             :   /* Find the first word that is nonzero.  */
     489                 :   750749098 :   for (i = SIGSZ - 1; i >= 0; i--)
     490                 :   642627729 :     if (r->sig[i] == 0)
     491                 :   325598650 :       shift += HOST_BITS_PER_LONG;
     492                 :             :     else
     493                 :             :       break;
     494                 :             : 
     495                 :             :   /* Zero significand flushes to zero.  */
     496                 :   425150448 :   if (i < 0)
     497                 :             :     {
     498                 :   108121369 :       r->cl = rvc_zero;
     499                 :   108121369 :       SET_REAL_EXP (r, 0);
     500                 :   108121369 :       return;
     501                 :             :     }
     502                 :             : 
     503                 :             :   /* Find the first bit that is nonzero.  */
     504                 :  1448597882 :   for (j = 0; ; j++)
     505                 :  1765626961 :     if (r->sig[i] & ((unsigned long)1 << (HOST_BITS_PER_LONG - 1 - j)))
     506                 :             :       break;
     507                 :   317029079 :   shift += j;
     508                 :             : 
     509                 :   317029079 :   if (shift > 0)
     510                 :             :     {
     511                 :   133102224 :       exp = REAL_EXP (r) - shift;
     512                 :   133102224 :       if (exp > MAX_EXP)
     513                 :             :         get_inf (r, r->sign);
     514                 :   133102224 :       else if (exp < -MAX_EXP)
     515                 :           0 :         get_zero (r, r->sign);
     516                 :             :       else
     517                 :             :         {
     518                 :   133102224 :           SET_REAL_EXP (r, exp);
     519                 :   133102224 :           lshift_significand (r, r, shift);
     520                 :             :         }
     521                 :             :     }
     522                 :             : }
     523                 :             : 
     524                 :             : /* Calculate R = A + (SUBTRACT_P ? -B : B).  Return true if the
     525                 :             :    result may be inexact due to a loss of precision.  */
     526                 :             : 
     527                 :             : static bool
     528                 :   241060565 : do_add (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a,
     529                 :             :         const REAL_VALUE_TYPE *b, int subtract_p)
     530                 :             : {
     531                 :   241060565 :   int dexp, sign, exp;
     532                 :   241060565 :   REAL_VALUE_TYPE t;
     533                 :   241060565 :   bool inexact = false;
     534                 :             : 
     535                 :             :   /* Determine if we need to add or subtract.  */
     536                 :   241060565 :   sign = a->sign;
     537                 :   241060565 :   subtract_p = (sign ^ b->sign) ^ subtract_p;
     538                 :             : 
     539                 :   241060565 :   switch (CLASS2 (a->cl, b->cl))
     540                 :             :     {
     541                 :    31240075 :     case CLASS2 (rvc_zero, rvc_zero):
     542                 :             :       /* -0 + -0 = -0, -0 - +0 = -0; all other cases yield +0.  */
     543                 :    31240075 :       get_zero (r, sign & !subtract_p);
     544                 :    31240075 :       return false;
     545                 :             : 
     546                 :    33577721 :     case CLASS2 (rvc_zero, rvc_normal):
     547                 :    33577721 :     case CLASS2 (rvc_zero, rvc_inf):
     548                 :    33577721 :     case CLASS2 (rvc_zero, rvc_nan):
     549                 :             :       /* 0 + ANY = ANY.  */
     550                 :    33577721 :     case CLASS2 (rvc_normal, rvc_nan):
     551                 :    33577721 :     case CLASS2 (rvc_inf, rvc_nan):
     552                 :    33577721 :     case CLASS2 (rvc_nan, rvc_nan):
     553                 :             :       /* ANY + NaN = NaN.  */
     554                 :    33577721 :     case CLASS2 (rvc_normal, rvc_inf):
     555                 :             :       /* R + Inf = Inf.  */
     556                 :    33577721 :       *r = *b;
     557                 :             :       /* Make resulting NaN value to be qNaN. The caller has the
     558                 :             :          responsibility to avoid the operation if flag_signaling_nans
     559                 :             :          is on.  */
     560                 :    33577721 :       r->signalling = 0;
     561                 :    33577721 :       r->sign = sign ^ subtract_p;
     562                 :    33577721 :       return false;
     563                 :             : 
     564                 :    78325399 :     case CLASS2 (rvc_normal, rvc_zero):
     565                 :    78325399 :     case CLASS2 (rvc_inf, rvc_zero):
     566                 :    78325399 :     case CLASS2 (rvc_nan, rvc_zero):
     567                 :             :       /* ANY + 0 = ANY.  */
     568                 :    78325399 :     case CLASS2 (rvc_nan, rvc_normal):
     569                 :    78325399 :     case CLASS2 (rvc_nan, rvc_inf):
     570                 :             :       /* NaN + ANY = NaN.  */
     571                 :    78325399 :     case CLASS2 (rvc_inf, rvc_normal):
     572                 :             :       /* Inf + R = Inf.  */
     573                 :    78325399 :       *r = *a;
     574                 :             :       /* Make resulting NaN value to be qNaN. The caller has the
     575                 :             :          responsibility to avoid the operation if flag_signaling_nans
     576                 :             :          is on.  */
     577                 :    78325399 :       r->signalling = 0;
     578                 :    78325399 :       return false;
     579                 :             : 
     580                 :     4379612 :     case CLASS2 (rvc_inf, rvc_inf):
     581                 :     4379612 :       if (subtract_p)
     582                 :             :         /* Inf - Inf = NaN.  */
     583                 :         923 :         get_canonical_qnan (r, 0);
     584                 :             :       else
     585                 :             :         /* Inf + Inf = Inf.  */
     586                 :     4378689 :         *r = *a;
     587                 :             :       return false;
     588                 :             : 
     589                 :    93537758 :     case CLASS2 (rvc_normal, rvc_normal):
     590                 :    93537758 :       break;
     591                 :             : 
     592                 :             :     default:
     593                 :             :       gcc_unreachable ();
     594                 :             :     }
     595                 :             : 
     596                 :             :   /* Swap the arguments such that A has the larger exponent.  */
     597                 :    93537758 :   dexp = REAL_EXP (a) - REAL_EXP (b);
     598                 :    93537758 :   if (dexp < 0)
     599                 :             :     {
     600                 :    87597852 :       const REAL_VALUE_TYPE *t;
     601                 :    87597852 :       t = a, a = b, b = t;
     602                 :    87597852 :       dexp = -dexp;
     603                 :    87597852 :       sign ^= subtract_p;
     604                 :             :     }
     605                 :    93537758 :   exp = REAL_EXP (a);
     606                 :             : 
     607                 :             :   /* If the exponents are not identical, we need to shift the
     608                 :             :      significand of B down.  */
     609                 :    93537758 :   if (dexp > 0)
     610                 :             :     {
     611                 :             :       /* If the exponents are too far apart, the significands
     612                 :             :          do not overlap, which makes the subtraction a noop.  */
     613                 :    91076886 :       if (dexp >= SIGNIFICAND_BITS)
     614                 :             :         {
     615                 :       76242 :           *r = *a;
     616                 :       76242 :           r->sign = sign;
     617                 :       76242 :           return true;
     618                 :             :         }
     619                 :             : 
     620                 :    91000644 :       inexact |= sticky_rshift_significand (&t, b, dexp);
     621                 :    91000644 :       b = &t;
     622                 :             :     }
     623                 :             : 
     624                 :    93461516 :   if (subtract_p)
     625                 :             :     {
     626                 :      120065 :       if (sub_significands (r, a, b, inexact))
     627                 :             :         {
     628                 :             :           /* We got a borrow out of the subtraction.  That means that
     629                 :             :              A and B had the same exponent, and B had the larger
     630                 :             :              significand.  We need to swap the sign and negate the
     631                 :             :              significand.  */
     632                 :        7610 :           sign ^= 1;
     633                 :        7610 :           neg_significand (r, r);
     634                 :             :         }
     635                 :             :     }
     636                 :             :   else
     637                 :             :     {
     638                 :    93341451 :       if (add_significands (r, a, b))
     639                 :             :         {
     640                 :             :           /* We got carry out of the addition.  This means we need to
     641                 :             :              shift the significand back down one bit and increase the
     642                 :             :              exponent.  */
     643                 :     4062330 :           inexact |= sticky_rshift_significand (r, r, 1);
     644                 :     4062330 :           r->sig[SIGSZ-1] |= SIG_MSB;
     645                 :     4062330 :           if (++exp > MAX_EXP)
     646                 :             :             {
     647                 :           0 :               get_inf (r, sign);
     648                 :           0 :               return true;
     649                 :             :             }
     650                 :             :         }
     651                 :             :     }
     652                 :             : 
     653                 :    93461516 :   r->cl = rvc_normal;
     654                 :    93461516 :   r->sign = sign;
     655                 :    93461516 :   SET_REAL_EXP (r, exp);
     656                 :             :   /* Zero out the remaining fields.  */
     657                 :    93461516 :   r->signalling = 0;
     658                 :    93461516 :   r->canonical = 0;
     659                 :    93461516 :   r->decimal = 0;
     660                 :             : 
     661                 :             :   /* Re-normalize the result.  */
     662                 :    93461516 :   normalize (r);
     663                 :             : 
     664                 :             :   /* Special case: if the subtraction results in zero, the result
     665                 :             :      is positive.  */
     666                 :    93461516 :   if (r->cl == rvc_zero)
     667                 :        8581 :     r->sign = 0;
     668                 :             :   else
     669                 :    93452935 :     r->sig[0] |= inexact;
     670                 :             : 
     671                 :             :   return inexact;
     672                 :             : }
     673                 :             : 
     674                 :             : /* Calculate R = A * B.  Return true if the result may be inexact.  */
     675                 :             : 
     676                 :             : static bool
     677                 :    42755261 : do_multiply (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a,
     678                 :             :              const REAL_VALUE_TYPE *b)
     679                 :             : {
     680                 :    42755261 :   REAL_VALUE_TYPE u, t, *rr;
     681                 :    42755261 :   unsigned int i, j, k;
     682                 :    42755261 :   int sign = a->sign ^ b->sign;
     683                 :    42755261 :   bool inexact = false;
     684                 :             : 
     685                 :    42755261 :   switch (CLASS2 (a->cl, b->cl))
     686                 :             :     {
     687                 :     6645391 :     case CLASS2 (rvc_zero, rvc_zero):
     688                 :     6645391 :     case CLASS2 (rvc_zero, rvc_normal):
     689                 :     6645391 :     case CLASS2 (rvc_normal, rvc_zero):
     690                 :             :       /* +-0 * ANY = 0 with appropriate sign.  */
     691                 :     6645391 :       get_zero (r, sign);
     692                 :     6645391 :       return false;
     693                 :             : 
     694                 :           0 :     case CLASS2 (rvc_zero, rvc_nan):
     695                 :           0 :     case CLASS2 (rvc_normal, rvc_nan):
     696                 :           0 :     case CLASS2 (rvc_inf, rvc_nan):
     697                 :           0 :     case CLASS2 (rvc_nan, rvc_nan):
     698                 :             :       /* ANY * NaN = NaN.  */
     699                 :           0 :       *r = *b;
     700                 :             :       /* Make resulting NaN value to be qNaN. The caller has the
     701                 :             :          responsibility to avoid the operation if flag_signaling_nans
     702                 :             :          is on.  */
     703                 :           0 :       r->signalling = 0;
     704                 :           0 :       r->sign = sign;
     705                 :           0 :       return false;
     706                 :             : 
     707                 :          36 :     case CLASS2 (rvc_nan, rvc_zero):
     708                 :          36 :     case CLASS2 (rvc_nan, rvc_normal):
     709                 :          36 :     case CLASS2 (rvc_nan, rvc_inf):
     710                 :             :       /* NaN * ANY = NaN.  */
     711                 :          36 :       *r = *a;
     712                 :             :       /* Make resulting NaN value to be qNaN. The caller has the
     713                 :             :          responsibility to avoid the operation if flag_signaling_nans
     714                 :             :          is on.  */
     715                 :          36 :       r->signalling = 0;
     716                 :          36 :       r->sign = sign;
     717                 :          36 :       return false;
     718                 :             : 
     719                 :        2115 :     case CLASS2 (rvc_zero, rvc_inf):
     720                 :        2115 :     case CLASS2 (rvc_inf, rvc_zero):
     721                 :             :       /* 0 * Inf = NaN */
     722                 :        2115 :       get_canonical_qnan (r, sign);
     723                 :        2115 :       return false;
     724                 :             : 
     725                 :     2881728 :     case CLASS2 (rvc_inf, rvc_inf):
     726                 :     2881728 :     case CLASS2 (rvc_normal, rvc_inf):
     727                 :     2881728 :     case CLASS2 (rvc_inf, rvc_normal):
     728                 :             :       /* Inf * Inf = Inf, R * Inf = Inf */
     729                 :     2881728 :       get_inf (r, sign);
     730                 :     2881728 :       return false;
     731                 :             : 
     732                 :    33225991 :     case CLASS2 (rvc_normal, rvc_normal):
     733                 :    33225991 :       break;
     734                 :             : 
     735                 :             :     default:
     736                 :             :       gcc_unreachable ();
     737                 :             :     }
     738                 :             : 
     739                 :    33225991 :   if (r == a || r == b)
     740                 :             :     rr = &t;
     741                 :             :   else
     742                 :    16671948 :     rr = r;
     743                 :    33225991 :   get_zero (rr, 0);
     744                 :             : 
     745                 :             :   /* Collect all the partial products.  Since we don't have sure access
     746                 :             :      to a widening multiply, we split each long into two half-words.
     747                 :             : 
     748                 :             :      Consider the long-hand form of a four half-word multiplication:
     749                 :             : 
     750                 :             :                  A  B  C  D
     751                 :             :               *  E  F  G  H
     752                 :             :              --------------
     753                 :             :                 DE DF DG DH
     754                 :             :              CE CF CG CH
     755                 :             :           BE BF BG BH
     756                 :             :        AE AF AG AH
     757                 :             : 
     758                 :             :      We construct partial products of the widened half-word products
     759                 :             :      that are known to not overlap, e.g. DF+DH.  Each such partial
     760                 :             :      product is given its proper exponent, which allows us to sum them
     761                 :             :      and obtain the finished product.  */
     762                 :             : 
     763                 :   232580228 :   for (i = 0; i < SIGSZ * 2; ++i)
     764                 :             :     {
     765                 :   199355921 :       unsigned long ai = a->sig[i / 2];
     766                 :   199355921 :       if (i & 1)
     767                 :    99677958 :         ai >>= HOST_BITS_PER_LONG / 2;
     768                 :             :       else
     769                 :    99677963 :         ai &= ((unsigned long)1 << (HOST_BITS_PER_LONG / 2)) - 1;
     770                 :             : 
     771                 :   199355921 :       if (ai == 0)
     772                 :    82516321 :         continue;
     773                 :             : 
     774                 :   350517111 :       for (j = 0; j < 2; ++j)
     775                 :             :         {
     776                 :   233679195 :           int exp = (REAL_EXP (a) - (2*SIGSZ-1-i)*(HOST_BITS_PER_LONG/2)
     777                 :   233679195 :                      + (REAL_EXP (b) - (1-j)*(HOST_BITS_PER_LONG/2)));
     778                 :             : 
     779                 :   233679195 :           if (exp > MAX_EXP)
     780                 :             :             {
     781                 :        1684 :               get_inf (r, sign);
     782                 :        1684 :               return true;
     783                 :             :             }
     784                 :   233677511 :           if (exp < -MAX_EXP)
     785                 :             :             {
     786                 :             :               /* Would underflow to zero, which we shouldn't bother adding.  */
     787                 :           0 :               inexact = true;
     788                 :           0 :               continue;
     789                 :             :             }
     790                 :             : 
     791                 :   233677511 :           memset (&u, 0, sizeof (u));
     792                 :   233677511 :           u.cl = rvc_normal;
     793                 :   233677511 :           SET_REAL_EXP (&u, exp);
     794                 :             : 
     795                 :   934710044 :           for (k = j; k < SIGSZ * 2; k += 2)
     796                 :             :             {
     797                 :   701032533 :               unsigned long bi = b->sig[k / 2];
     798                 :   701032533 :               if (k & 1)
     799                 :   350513748 :                 bi >>= HOST_BITS_PER_LONG / 2;
     800                 :             :               else
     801                 :   350518785 :                 bi &= ((unsigned long)1 << (HOST_BITS_PER_LONG / 2)) - 1;
     802                 :             : 
     803                 :   701032533 :               u.sig[k / 2] = ai * bi;
     804                 :             :             }
     805                 :             : 
     806                 :   233677511 :           normalize (&u);
     807                 :   233677511 :           inexact |= do_add (rr, rr, &u, 0);
     808                 :             :         }
     809                 :             :     }
     810                 :             : 
     811                 :    33224307 :   rr->sign = sign;
     812                 :    33224307 :   if (rr != r)
     813                 :    16552359 :     *r = t;
     814                 :             : 
     815                 :             :   return inexact;
     816                 :             : }
     817                 :             : 
     818                 :             : /* Calculate R = A / B.  Return true if the result may be inexact.  */
     819                 :             : 
     820                 :             : static bool
     821                 :     6248905 : do_divide (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a,
     822                 :             :            const REAL_VALUE_TYPE *b)
     823                 :             : {
     824                 :     6248905 :   int exp, sign = a->sign ^ b->sign;
     825                 :     6248905 :   REAL_VALUE_TYPE t, *rr;
     826                 :     6248905 :   bool inexact;
     827                 :             : 
     828                 :     6248905 :   switch (CLASS2 (a->cl, b->cl))
     829                 :             :     {
     830                 :         428 :     case CLASS2 (rvc_zero, rvc_zero):
     831                 :             :       /* 0 / 0 = NaN.  */
     832                 :         428 :     case CLASS2 (rvc_inf, rvc_inf):
     833                 :             :       /* Inf / Inf = NaN.  */
     834                 :         428 :       get_canonical_qnan (r, sign);
     835                 :         428 :       return false;
     836                 :             : 
     837                 :      573722 :     case CLASS2 (rvc_zero, rvc_normal):
     838                 :      573722 :     case CLASS2 (rvc_zero, rvc_inf):
     839                 :             :       /* 0 / ANY = 0.  */
     840                 :      573722 :     case CLASS2 (rvc_normal, rvc_inf):
     841                 :             :       /* R / Inf = 0.  */
     842                 :      573722 :       get_zero (r, sign);
     843                 :      573722 :       return false;
     844                 :             : 
     845                 :        7792 :     case CLASS2 (rvc_normal, rvc_zero):
     846                 :             :       /* R / 0 = Inf.  */
     847                 :        7792 :     case CLASS2 (rvc_inf, rvc_zero):
     848                 :             :       /* Inf / 0 = Inf.  */
     849                 :        7792 :       get_inf (r, sign);
     850                 :        7792 :       return false;
     851                 :             : 
     852                 :           0 :     case CLASS2 (rvc_zero, rvc_nan):
     853                 :           0 :     case CLASS2 (rvc_normal, rvc_nan):
     854                 :           0 :     case CLASS2 (rvc_inf, rvc_nan):
     855                 :           0 :     case CLASS2 (rvc_nan, rvc_nan):
     856                 :             :       /* ANY / NaN = NaN.  */
     857                 :           0 :       *r = *b;
     858                 :             :       /* Make resulting NaN value to be qNaN. The caller has the
     859                 :             :          responsibility to avoid the operation if flag_signaling_nans
     860                 :             :          is on.  */
     861                 :           0 :       r->signalling = 0;
     862                 :           0 :       r->sign = sign;
     863                 :           0 :       return false;
     864                 :             : 
     865                 :           0 :     case CLASS2 (rvc_nan, rvc_zero):
     866                 :           0 :     case CLASS2 (rvc_nan, rvc_normal):
     867                 :           0 :     case CLASS2 (rvc_nan, rvc_inf):
     868                 :             :       /* NaN / ANY = NaN.  */
     869                 :           0 :       *r = *a;
     870                 :             :       /* Make resulting NaN value to be qNaN. The caller has the
     871                 :             :          responsibility to avoid the operation if flag_signaling_nans
     872                 :             :          is on.  */
     873                 :           0 :       r->signalling = 0;
     874                 :           0 :       r->sign = sign;
     875                 :           0 :       return false;
     876                 :             : 
     877                 :      430208 :     case CLASS2 (rvc_inf, rvc_normal):
     878                 :             :       /* Inf / R = Inf.  */
     879                 :      430208 :       get_inf (r, sign);
     880                 :      430208 :       return false;
     881                 :             : 
     882                 :     5236755 :     case CLASS2 (rvc_normal, rvc_normal):
     883                 :     5236755 :       break;
     884                 :             : 
     885                 :             :     default:
     886                 :             :       gcc_unreachable ();
     887                 :             :     }
     888                 :             : 
     889                 :     5236755 :   if (r == a || r == b)
     890                 :             :     rr = &t;
     891                 :             :   else
     892                 :     4380996 :     rr = r;
     893                 :             : 
     894                 :             :   /* Make sure all fields in the result are initialized.  */
     895                 :     5236755 :   get_zero (rr, 0);
     896                 :     5236755 :   rr->cl = rvc_normal;
     897                 :     5236755 :   rr->sign = sign;
     898                 :             : 
     899                 :     5236755 :   exp = REAL_EXP (a) - REAL_EXP (b) + 1;
     900                 :     5236755 :   if (exp > MAX_EXP)
     901                 :             :     {
     902                 :           0 :       get_inf (r, sign);
     903                 :           0 :       return true;
     904                 :             :     }
     905                 :     5236755 :   if (exp < -MAX_EXP)
     906                 :             :     {
     907                 :           0 :       get_zero (r, sign);
     908                 :           0 :       return true;
     909                 :             :     }
     910                 :     5236755 :   SET_REAL_EXP (rr, exp);
     911                 :             : 
     912                 :     5236755 :   inexact = div_significands (rr, a, b);
     913                 :             : 
     914                 :             :   /* Re-normalize the result.  */
     915                 :     5236755 :   normalize (rr);
     916                 :     5236755 :   rr->sig[0] |= inexact;
     917                 :             : 
     918                 :     5236755 :   if (rr != r)
     919                 :      855759 :     *r = t;
     920                 :             : 
     921                 :             :   return inexact;
     922                 :             : }
     923                 :             : 
     924                 :             : /* Return a tri-state comparison of A vs B.  Return NAN_RESULT if
     925                 :             :    one of the two operands is a NaN.  */
     926                 :             : 
     927                 :             : static int
     928                 :   118008556 : do_compare (const REAL_VALUE_TYPE *a, const REAL_VALUE_TYPE *b,
     929                 :             :             int nan_result)
     930                 :             : {
     931                 :   118008556 :   int ret;
     932                 :             : 
     933                 :   118008556 :   switch (CLASS2 (a->cl, b->cl))
     934                 :             :     {
     935                 :             :     case CLASS2 (rvc_zero, rvc_zero):
     936                 :             :       /* Sign of zero doesn't matter for compares.  */
     937                 :             :       return 0;
     938                 :             : 
     939                 :    24423344 :     case CLASS2 (rvc_normal, rvc_zero):
     940                 :             :       /* Decimal float zero is special and uses rvc_normal, not rvc_zero.  */
     941                 :    24423344 :       if (a->decimal)
     942                 :       56750 :         return decimal_do_compare (a, b, nan_result);
     943                 :             :       /* Fall through.  */
     944                 :    40799683 :     case CLASS2 (rvc_inf, rvc_zero):
     945                 :    40799683 :     case CLASS2 (rvc_inf, rvc_normal):
     946                 :    40799683 :       return (a->sign ? -1 : 1);
     947                 :             : 
     948                 :    25014668 :     case CLASS2 (rvc_inf, rvc_inf):
     949                 :    25014668 :       return -a->sign - -b->sign;
     950                 :             : 
     951                 :     1318343 :     case CLASS2 (rvc_zero, rvc_normal):
     952                 :             :       /* Decimal float zero is special and uses rvc_normal, not rvc_zero.  */
     953                 :     1318343 :       if (b->decimal)
     954                 :        1366 :         return decimal_do_compare (a, b, nan_result);
     955                 :             :       /* Fall through.  */
     956                 :     9553087 :     case CLASS2 (rvc_zero, rvc_inf):
     957                 :     9553087 :     case CLASS2 (rvc_normal, rvc_inf):
     958                 :     9553087 :       return (b->sign ? 1 : -1);
     959                 :             : 
     960                 :       13263 :     case CLASS2 (rvc_zero, rvc_nan):
     961                 :       13263 :     case CLASS2 (rvc_normal, rvc_nan):
     962                 :       13263 :     case CLASS2 (rvc_inf, rvc_nan):
     963                 :       13263 :     case CLASS2 (rvc_nan, rvc_nan):
     964                 :       13263 :     case CLASS2 (rvc_nan, rvc_zero):
     965                 :       13263 :     case CLASS2 (rvc_nan, rvc_normal):
     966                 :       13263 :     case CLASS2 (rvc_nan, rvc_inf):
     967                 :       13263 :       return nan_result;
     968                 :             : 
     969                 :    32250327 :     case CLASS2 (rvc_normal, rvc_normal):
     970                 :    32250327 :       break;
     971                 :             : 
     972                 :             :     default:
     973                 :             :       gcc_unreachable ();
     974                 :             :     }
     975                 :             : 
     976                 :    32250327 :   if (a->decimal || b->decimal)
     977                 :      205056 :     return decimal_do_compare (a, b, nan_result);
     978                 :             : 
     979                 :    32045271 :   if (a->sign != b->sign)
     980                 :    11619104 :     return -a->sign - -b->sign;
     981                 :             : 
     982                 :    20426167 :   if (REAL_EXP (a) > REAL_EXP (b))
     983                 :             :     ret = 1;
     984                 :    13142464 :   else if (REAL_EXP (a) < REAL_EXP (b))
     985                 :             :     ret = -1;
     986                 :             :   else
     987                 :    20426167 :     ret = cmp_significands (a, b);
     988                 :             : 
     989                 :    20426167 :   return (a->sign ? -ret : ret);
     990                 :             : }
     991                 :             : 
     992                 :             : /* Return A truncated to an integral value toward zero.  */
     993                 :             : 
     994                 :             : static void
     995                 :     1169949 : do_fix_trunc (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *a)
     996                 :             : {
     997                 :     1169949 :   *r = *a;
     998                 :             : 
     999                 :     1169949 :   switch (r->cl)
    1000                 :             :     {
    1001                 :       22735 :     case rvc_zero:
    1002                 :       22735 :     case rvc_inf:
    1003                 :       22735 :     case rvc_nan:
    1004                 :             :       /* Make resulting NaN value to be qNaN. The caller has the
    1005                 :             :          responsibility to avoid the operation if flag_signaling_nans
    1006                 :             :          is on.  */
    1007                 :       22735 :       r->signalling = 0;
    1008                 :       22735 :       break;
    1009                 :             : 
    1010                 :     1147214 :     case rvc_normal:
    1011                 :     1147214 :       if (r->decimal)
    1012                 :             :         {
    1013                 :         324 :           decimal_do_fix_trunc (r, a);
    1014                 :         324 :           return;
    1015                 :             :         }
    1016                 :     1146890 :       if (REAL_EXP (r) <= 0)
    1017                 :       44433 :         get_zero (r, r->sign);
    1018                 :     1102457 :       else if (REAL_EXP (r) < SIGNIFICAND_BITS)
    1019                 :     1102380 :         clear_significand_below (r, SIGNIFICAND_BITS - REAL_EXP (r));
    1020                 :             :       break;
    1021                 :             : 
    1022                 :           0 :     default:
    1023                 :           0 :       gcc_unreachable ();
    1024                 :             :     }
    1025                 :             : }
    1026                 :             : 
    1027                 :             : /* Perform the binary or unary operation described by CODE.
    1028                 :             :    For a unary operation, leave OP1 NULL.  This function returns
    1029                 :             :    true if the result may be inexact due to loss of precision.  */
    1030                 :             : 
    1031                 :             : bool
    1032                 :    30868709 : real_arithmetic (REAL_VALUE_TYPE *r, int icode, const REAL_VALUE_TYPE *op0,
    1033                 :             :                  const REAL_VALUE_TYPE *op1)
    1034                 :             : {
    1035                 :    30868709 :   enum tree_code code = (enum tree_code) icode;
    1036                 :             : 
    1037                 :    30868709 :   if (op0->decimal || (op1 && op1->decimal))
    1038                 :      375171 :     return decimal_real_arithmetic (r, code, op0, op1);
    1039                 :             : 
    1040                 :    30493538 :   switch (code)
    1041                 :             :     {
    1042                 :     5544168 :     case PLUS_EXPR:
    1043                 :             :       /* Clear any padding areas in *r if it isn't equal to one of the
    1044                 :             :          operands so that we can later do bitwise comparisons later on.  */
    1045                 :     5544168 :       if (r != op0 && r != op1)
    1046                 :     5544168 :         memset (r, '\0', sizeof (*r));
    1047                 :     5544168 :       return do_add (r, op0, op1, 0);
    1048                 :             : 
    1049                 :     1836870 :     case MINUS_EXPR:
    1050                 :     1836870 :       if (r != op0 && r != op1)
    1051                 :     1834041 :         memset (r, '\0', sizeof (*r));
    1052                 :     1836870 :       return do_add (r, op0, op1, 1);
    1053                 :             : 
    1054                 :     5325746 :     case MULT_EXPR:
    1055                 :     5325746 :       if (r != op0 && r != op1)
    1056                 :     5325682 :         memset (r, '\0', sizeof (*r));
    1057                 :     5325746 :       return do_multiply (r, op0, op1);
    1058                 :             : 
    1059                 :     3804480 :     case RDIV_EXPR:
    1060                 :     3804480 :       if (r != op0 && r != op1)
    1061                 :     3802402 :         memset (r, '\0', sizeof (*r));
    1062                 :     3804480 :       return do_divide (r, op0, op1);
    1063                 :             : 
    1064                 :         467 :     case MIN_EXPR:
    1065                 :         467 :       if (op1->cl == rvc_nan)
    1066                 :             :       {
    1067                 :           0 :         *r = *op1;
    1068                 :             :         /* Make resulting NaN value to be qNaN. The caller has the
    1069                 :             :            responsibility to avoid the operation if flag_signaling_nans
    1070                 :             :            is on.  */
    1071                 :           0 :         r->signalling = 0;
    1072                 :             :       }
    1073                 :         467 :       else if (do_compare (op0, op1, -1) < 0)
    1074                 :         159 :         *r = *op0;
    1075                 :             :       else
    1076                 :         308 :         *r = *op1;
    1077                 :             :       break;
    1078                 :             : 
    1079                 :         444 :     case MAX_EXPR:
    1080                 :         444 :       if (op1->cl == rvc_nan)
    1081                 :             :       {
    1082                 :           0 :         *r = *op1;
    1083                 :             :         /* Make resulting NaN value to be qNaN. The caller has the
    1084                 :             :            responsibility to avoid the operation if flag_signaling_nans
    1085                 :             :            is on.  */
    1086                 :           0 :         r->signalling = 0;
    1087                 :             :       }
    1088                 :         444 :       else if (do_compare (op0, op1, 1) < 0)
    1089                 :         177 :         *r = *op1;
    1090                 :             :       else
    1091                 :         267 :         *r = *op0;
    1092                 :             :       break;
    1093                 :             : 
    1094                 :    13270935 :     case NEGATE_EXPR:
    1095                 :    13270935 :       *r = *op0;
    1096                 :    13270935 :       r->sign ^= 1;
    1097                 :    13270935 :       break;
    1098                 :             : 
    1099                 :      710428 :     case ABS_EXPR:
    1100                 :      710428 :       *r = *op0;
    1101                 :      710428 :       r->sign = 0;
    1102                 :      710428 :       break;
    1103                 :             : 
    1104                 :           0 :     case FIX_TRUNC_EXPR:
    1105                 :           0 :       do_fix_trunc (r, op0);
    1106                 :           0 :       break;
    1107                 :             : 
    1108                 :           0 :     default:
    1109                 :           0 :       gcc_unreachable ();
    1110                 :             :     }
    1111                 :             :   return false;
    1112                 :             : }
    1113                 :             : 
    1114                 :             : REAL_VALUE_TYPE
    1115                 :    13280080 : real_value_negate (const REAL_VALUE_TYPE *op0)
    1116                 :             : {
    1117                 :    13280080 :   REAL_VALUE_TYPE r;
    1118                 :    13280080 :   real_arithmetic (&r, NEGATE_EXPR, op0, NULL);
    1119                 :    13280080 :   return r;
    1120                 :             : }
    1121                 :             : 
    1122                 :             : REAL_VALUE_TYPE
    1123                 :      710428 : real_value_abs (const REAL_VALUE_TYPE *op0)
    1124                 :             : {
    1125                 :      710428 :   REAL_VALUE_TYPE r;
    1126                 :      710428 :   real_arithmetic (&r, ABS_EXPR, op0, NULL);
    1127                 :      710428 :   return r;
    1128                 :             : }
    1129                 :             : 
    1130                 :             : /* Return whether OP0 == OP1.  */
    1131                 :             : 
    1132                 :             : bool
    1133                 :    40191369 : real_equal (const REAL_VALUE_TYPE *op0, const REAL_VALUE_TYPE *op1)
    1134                 :             : {
    1135                 :    40191369 :   return do_compare (op0, op1, -1) == 0;
    1136                 :             : }
    1137                 :             : 
    1138                 :             : /* Return whether OP0 < OP1.  */
    1139                 :             : 
    1140                 :             : bool
    1141                 :    45246458 : real_less (const REAL_VALUE_TYPE *op0, const REAL_VALUE_TYPE *op1)
    1142                 :             : {
    1143                 :    45246458 :   return do_compare (op0, op1, 1) < 0;
    1144                 :             : }
    1145                 :             : 
    1146                 :             : bool
    1147                 :    28281439 : real_compare (int icode, const REAL_VALUE_TYPE *op0,
    1148                 :             :               const REAL_VALUE_TYPE *op1)
    1149                 :             : {
    1150                 :    28281439 :   enum tree_code code = (enum tree_code) icode;
    1151                 :             : 
    1152                 :    28281439 :   switch (code)
    1153                 :             :     {
    1154                 :      112958 :     case LT_EXPR:
    1155                 :      112958 :       return real_less (op0, op1);
    1156                 :    23020349 :     case LE_EXPR:
    1157                 :    23020349 :       return do_compare (op0, op1, 1) <= 0;
    1158                 :      754100 :     case GT_EXPR:
    1159                 :      754100 :       return do_compare (op0, op1, -1) > 0;
    1160                 :     3650626 :     case GE_EXPR:
    1161                 :     3650626 :       return do_compare (op0, op1, -1) >= 0;
    1162                 :       29707 :     case EQ_EXPR:
    1163                 :       29707 :       return real_equal (op0, op1);
    1164                 :      663043 :     case NE_EXPR:
    1165                 :      663043 :       return do_compare (op0, op1, -1) != 0;
    1166                 :       35720 :     case UNORDERED_EXPR:
    1167                 :       35720 :       return op0->cl == rvc_nan || op1->cl == rvc_nan;
    1168                 :        1047 :     case ORDERED_EXPR:
    1169                 :        1047 :       return op0->cl != rvc_nan && op1->cl != rvc_nan;
    1170                 :         135 :     case UNLT_EXPR:
    1171                 :         135 :       return do_compare (op0, op1, -1) < 0;
    1172                 :        6907 :     case UNLE_EXPR:
    1173                 :        6907 :       return do_compare (op0, op1, -1) <= 0;
    1174                 :         986 :     case UNGT_EXPR:
    1175                 :         986 :       return do_compare (op0, op1, 1) > 0;
    1176                 :        5816 :     case UNGE_EXPR:
    1177                 :        5816 :       return do_compare (op0, op1, 1) >= 0;
    1178                 :          45 :     case UNEQ_EXPR:
    1179                 :          45 :       return do_compare (op0, op1, 0) == 0;
    1180                 :           0 :     case LTGT_EXPR:
    1181                 :           0 :       return do_compare (op0, op1, 0) != 0;
    1182                 :             : 
    1183                 :           0 :     default:
    1184                 :           0 :       gcc_unreachable ();
    1185                 :             :     }
    1186                 :             : }
    1187                 :             : 
    1188                 :             : /* Return floor log2(R).  */
    1189                 :             : 
    1190                 :             : int
    1191                 :           0 : real_exponent (const REAL_VALUE_TYPE *r)
    1192                 :             : {
    1193                 :           0 :   switch (r->cl)
    1194                 :             :     {
    1195                 :             :     case rvc_zero:
    1196                 :             :       return 0;
    1197                 :           0 :     case rvc_inf:
    1198                 :           0 :     case rvc_nan:
    1199                 :           0 :       return (unsigned int)-1 >> 1;
    1200                 :           0 :     case rvc_normal:
    1201                 :           0 :       return REAL_EXP (r);
    1202                 :           0 :     default:
    1203                 :           0 :       gcc_unreachable ();
    1204                 :             :     }
    1205                 :             : }
    1206                 :             : 
    1207                 :             : /* R = OP0 * 2**EXP.  */
    1208                 :             : 
    1209                 :             : void
    1210                 :       10113 : real_ldexp (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *op0, int exp)
    1211                 :             : {
    1212                 :       10113 :   *r = *op0;
    1213                 :       10113 :   switch (r->cl)
    1214                 :             :     {
    1215                 :         196 :     case rvc_zero:
    1216                 :         196 :     case rvc_inf:
    1217                 :         196 :     case rvc_nan:
    1218                 :             :       /* Make resulting NaN value to be qNaN. The caller has the
    1219                 :             :          responsibility to avoid the operation if flag_signaling_nans
    1220                 :             :          is on.  */
    1221                 :         196 :       r->signalling = 0;
    1222                 :         196 :       break;
    1223                 :             : 
    1224                 :        9917 :     case rvc_normal:
    1225                 :        9917 :       exp += REAL_EXP (op0);
    1226                 :        9917 :       if (exp > MAX_EXP)
    1227                 :           0 :         get_inf (r, r->sign);
    1228                 :        9917 :       else if (exp < -MAX_EXP)
    1229                 :           0 :         get_zero (r, r->sign);
    1230                 :             :       else
    1231                 :        9917 :         SET_REAL_EXP (r, exp);
    1232                 :             :       break;
    1233                 :             : 
    1234                 :           0 :     default:
    1235                 :           0 :       gcc_unreachable ();
    1236                 :             :     }
    1237                 :       10113 : }
    1238                 :             : 
    1239                 :             : /* Determine whether a floating-point value X is infinite.  */
    1240                 :             : 
    1241                 :             : bool
    1242                 :    50591840 : real_isinf (const REAL_VALUE_TYPE *r)
    1243                 :             : {
    1244                 :    50591840 :   return (r->cl == rvc_inf);
    1245                 :             : }
    1246                 :             : 
    1247                 :             : /* Determine whether a floating-point value X is infinite with SIGN.  */
    1248                 :             : 
    1249                 :             : bool
    1250                 :    21151766 : real_isinf (const REAL_VALUE_TYPE *r, bool sign)
    1251                 :             : {
    1252                 :    21151766 :   return real_isinf (r) && r->sign == sign;
    1253                 :             : }
    1254                 :             : 
    1255                 :             : /* Determine whether a floating-point value X is a NaN.  */
    1256                 :             : 
    1257                 :             : bool
    1258                 :   118972755 : real_isnan (const REAL_VALUE_TYPE *r)
    1259                 :             : {
    1260                 :   118972755 :   return (r->cl == rvc_nan);
    1261                 :             : }
    1262                 :             : 
    1263                 :             : /* Determine whether a floating-point value X is a signaling NaN.  */ 
    1264                 :       68911 : bool real_issignaling_nan (const REAL_VALUE_TYPE *r)
    1265                 :             : {
    1266                 :       68911 :   return real_isnan (r) && r->signalling;
    1267                 :             : }
    1268                 :             : 
    1269                 :             : /* Determine whether a floating-point value X is finite.  */
    1270                 :             : 
    1271                 :             : bool
    1272                 :     1695361 : real_isfinite (const REAL_VALUE_TYPE *r)
    1273                 :             : {
    1274                 :     1695361 :   return (r->cl != rvc_nan) && (r->cl != rvc_inf);
    1275                 :             : }
    1276                 :             : 
    1277                 :             : /* Determine whether a floating-point value X is negative.  */
    1278                 :             : 
    1279                 :             : bool
    1280                 :    25720281 : real_isneg (const REAL_VALUE_TYPE *r)
    1281                 :             : {
    1282                 :    25720281 :   return r->sign;
    1283                 :             : }
    1284                 :             : 
    1285                 :             : /* Determine whether a floating-point value X is plus or minus zero.  */
    1286                 :             : 
    1287                 :             : bool
    1288                 :    40403262 : real_iszero (const REAL_VALUE_TYPE *r)
    1289                 :             : {
    1290                 :    40403262 :   return r->cl == rvc_zero;
    1291                 :             : }
    1292                 :             : 
    1293                 :             : /* Determine whether a floating-point value X is zero with SIGN.  */
    1294                 :             : 
    1295                 :             : bool
    1296                 :    23549382 : real_iszero (const REAL_VALUE_TYPE *r, bool sign)
    1297                 :             : {
    1298                 :    23549382 :   return real_iszero (r) && r->sign == sign;
    1299                 :             : }
    1300                 :             : 
    1301                 :             : /* Determine whether a floating-point value X is minus zero.  */
    1302                 :             : 
    1303                 :             : bool
    1304                 :    15376250 : real_isnegzero (const REAL_VALUE_TYPE *r)
    1305                 :             : {
    1306                 :    15376250 :   return r->sign && r->cl == rvc_zero;
    1307                 :             : }
    1308                 :             : 
    1309                 :             : /* Compare two floating-point objects for bitwise identity.  */
    1310                 :             : 
    1311                 :             : bool
    1312                 :   175798933 : real_identical (const REAL_VALUE_TYPE *a, const REAL_VALUE_TYPE *b)
    1313                 :             : {
    1314                 :   175798933 :   int i;
    1315                 :             : 
    1316                 :   175798933 :   if (a->cl != b->cl)
    1317                 :             :     return false;
    1318                 :   145001199 :   if (a->sign != b->sign)
    1319                 :             :     return false;
    1320                 :             : 
    1321                 :   140458859 :   switch (a->cl)
    1322                 :             :     {
    1323                 :             :     case rvc_zero:
    1324                 :             :     case rvc_inf:
    1325                 :             :       return true;
    1326                 :             : 
    1327                 :    20124619 :     case rvc_normal:
    1328                 :    20124619 :       if (a->decimal != b->decimal)
    1329                 :             :         return false;
    1330                 :    20120193 :       if (REAL_EXP (a) != REAL_EXP (b))
    1331                 :             :         return false;
    1332                 :             :       break;
    1333                 :             : 
    1334                 :      110196 :     case rvc_nan:
    1335                 :      110196 :       if (a->signalling != b->signalling)
    1336                 :             :         return false;
    1337                 :             :       /* The significand is ignored for canonical NaNs.  */
    1338                 :      106129 :       if (a->canonical || b->canonical)
    1339                 :       43395 :         return a->canonical == b->canonical;
    1340                 :             :       break;
    1341                 :             : 
    1342                 :           0 :     default:
    1343                 :           0 :       gcc_unreachable ();
    1344                 :             :     }
    1345                 :             : 
    1346                 :    61934606 :   for (i = 0; i < SIGSZ; ++i)
    1347                 :    47096989 :     if (a->sig[i] != b->sig[i])
    1348                 :             :       return false;
    1349                 :             : 
    1350                 :             :   return true;
    1351                 :             : }
    1352                 :             : 
    1353                 :             : /* Try to change R into its exact multiplicative inverse in format FMT.
    1354                 :             :    Return true if successful.  */
    1355                 :             : 
    1356                 :             : bool
    1357                 :     1073936 : exact_real_inverse (format_helper fmt, REAL_VALUE_TYPE *r)
    1358                 :             : {
    1359                 :     1073936 :   const REAL_VALUE_TYPE *one = real_digit (1);
    1360                 :     1073936 :   REAL_VALUE_TYPE u;
    1361                 :     1073936 :   int i;
    1362                 :             : 
    1363                 :     1073936 :   if (r->cl != rvc_normal)
    1364                 :             :     return false;
    1365                 :             : 
    1366                 :             :   /* Check for a power of two: all significand bits zero except the MSB.  */
    1367                 :     3193142 :   for (i = 0; i < SIGSZ-1; ++i)
    1368                 :     2129305 :     if (r->sig[i] != 0)
    1369                 :             :       return false;
    1370                 :     1063837 :   if (r->sig[SIGSZ-1] != SIG_MSB)
    1371                 :             :     return false;
    1372                 :             : 
    1373                 :             :   /* Find the inverse and truncate to the required format.  */
    1374                 :      306168 :   do_divide (&u, one, r);
    1375                 :      306168 :   real_convert (&u, fmt, &u);
    1376                 :             : 
    1377                 :             :   /* The rounding may have overflowed.  */
    1378                 :      306168 :   if (u.cl != rvc_normal)
    1379                 :             :     return false;
    1380                 :      918504 :   for (i = 0; i < SIGSZ-1; ++i)
    1381                 :      612336 :     if (u.sig[i] != 0)
    1382                 :             :       return false;
    1383                 :      306168 :   if (u.sig[SIGSZ-1] != SIG_MSB)
    1384                 :             :     return false;
    1385                 :             : 
    1386                 :      306168 :   *r = u;
    1387                 :      306168 :   return true;
    1388                 :             : }
    1389                 :             : 
    1390                 :             : /* Return true if arithmetic on values in IMODE that were promoted
    1391                 :             :    from values in TMODE is equivalent to direct arithmetic on values
    1392                 :             :    in TMODE.  */
    1393                 :             : 
    1394                 :             : bool
    1395                 :      139058 : real_can_shorten_arithmetic (machine_mode imode, machine_mode tmode)
    1396                 :             : {
    1397                 :      139058 :   const struct real_format *tfmt, *ifmt;
    1398                 :      139058 :   tfmt = REAL_MODE_FORMAT (tmode);
    1399                 :      139058 :   ifmt = REAL_MODE_FORMAT (imode);
    1400                 :             :   /* These conditions are conservative rather than trying to catch the
    1401                 :             :      exact boundary conditions; the main case to allow is IEEE float
    1402                 :             :      and double.  */
    1403                 :      139058 :   return (ifmt->b == tfmt->b
    1404                 :      139058 :           && ifmt->p > 2 * tfmt->p
    1405                 :       51600 :           && ifmt->emin < 2 * tfmt->emin - tfmt->p - 2
    1406                 :       29612 :           && ifmt->emin < tfmt->emin - tfmt->emax - tfmt->p - 2
    1407                 :       29612 :           && ifmt->emax > 2 * tfmt->emax + 2
    1408                 :       29612 :           && ifmt->emax > tfmt->emax - tfmt->emin + tfmt->p + 2
    1409                 :             :           && ifmt->round_towards_zero == tfmt->round_towards_zero
    1410                 :       29612 :           && (ifmt->has_sign_dependent_rounding
    1411                 :             :               == tfmt->has_sign_dependent_rounding)
    1412                 :       29612 :           && ifmt->has_nans >= tfmt->has_nans
    1413                 :       29612 :           && ifmt->has_inf >= tfmt->has_inf
    1414                 :       29612 :           && ifmt->has_signed_zero >= tfmt->has_signed_zero
    1415                 :      177672 :           && !MODE_COMPOSITE_P (tmode)
    1416                 :      316730 :           && !MODE_COMPOSITE_P (imode));
    1417                 :             : }
    1418                 :             : 
    1419                 :             : /* Render R as an integer.  */
    1420                 :             : 
    1421                 :             : HOST_WIDE_INT
    1422                 :       14008 : real_to_integer (const REAL_VALUE_TYPE *r)
    1423                 :             : {
    1424                 :       14008 :   unsigned HOST_WIDE_INT i;
    1425                 :             : 
    1426                 :       14008 :   switch (r->cl)
    1427                 :             :     {
    1428                 :             :     case rvc_zero:
    1429                 :       14008 :     underflow:
    1430                 :             :       return 0;
    1431                 :             : 
    1432                 :        3141 :     case rvc_inf:
    1433                 :        3141 :     case rvc_nan:
    1434                 :        3141 :     overflow:
    1435                 :        3141 :       i = HOST_WIDE_INT_1U << (HOST_BITS_PER_WIDE_INT - 1);
    1436                 :        3141 :       if (!r->sign)
    1437                 :        2175 :         i--;
    1438                 :        3141 :       return i;
    1439                 :             : 
    1440                 :       11102 :     case rvc_normal:
    1441                 :       11102 :       if (r->decimal)
    1442                 :           0 :         return decimal_real_to_integer (r);
    1443                 :             : 
    1444                 :       11102 :       if (REAL_EXP (r) <= 0)
    1445                 :         393 :         goto underflow;
    1446                 :             :       /* Only force overflow for unsigned overflow.  Signed overflow is
    1447                 :             :          undefined, so it doesn't matter what we return, and some callers
    1448                 :             :          expect to be able to use this routine for both signed and
    1449                 :             :          unsigned conversions.  */
    1450                 :       10709 :       if (REAL_EXP (r) > HOST_BITS_PER_WIDE_INT)
    1451                 :         243 :         goto overflow;
    1452                 :             : 
    1453                 :       10466 :       if (HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG)
    1454                 :       10466 :         i = r->sig[SIGSZ-1];
    1455                 :             :       else
    1456                 :             :         {
    1457                 :             :           gcc_assert (HOST_BITS_PER_WIDE_INT == 2 * HOST_BITS_PER_LONG);
    1458                 :             :           i = r->sig[SIGSZ-1];
    1459                 :             :           i = i << (HOST_BITS_PER_LONG - 1) << 1;
    1460                 :             :           i |= r->sig[SIGSZ-2];
    1461                 :             :         }
    1462                 :             : 
    1463                 :       10466 :       i >>= HOST_BITS_PER_WIDE_INT - REAL_EXP (r);
    1464                 :             : 
    1465                 :       10466 :       if (r->sign)
    1466                 :        4938 :         i = -i;
    1467                 :       10466 :       return i;
    1468                 :             : 
    1469                 :           0 :     default:
    1470                 :           0 :       gcc_unreachable ();
    1471                 :             :     }
    1472                 :             : }
    1473                 :             : 
    1474                 :             : /* Likewise, but producing a wide-int of PRECISION.  If the value cannot
    1475                 :             :    be represented in precision, *FAIL is set to TRUE.  */
    1476                 :             : 
    1477                 :             : wide_int
    1478                 :       75312 : real_to_integer (const REAL_VALUE_TYPE *r, bool *fail, int precision)
    1479                 :             : {
    1480                 :       75312 :   HOST_WIDE_INT valb[WIDE_INT_MAX_INL_ELTS], *val;
    1481                 :       75312 :   int exp;
    1482                 :       75312 :   int words, w;
    1483                 :       75312 :   wide_int result;
    1484                 :             : 
    1485                 :       75312 :   switch (r->cl)
    1486                 :             :     {
    1487                 :       23318 :     case rvc_zero:
    1488                 :       23318 :     underflow:
    1489                 :       23318 :       return wi::zero (precision);
    1490                 :             : 
    1491                 :         248 :     case rvc_inf:
    1492                 :         248 :     case rvc_nan:
    1493                 :         248 :     overflow:
    1494                 :         248 :       *fail = true;
    1495                 :             : 
    1496                 :         248 :       if (r->sign)
    1497                 :          36 :         return wi::set_bit_in_zero (precision - 1, precision);
    1498                 :             :       else
    1499                 :         212 :         return ~wi::set_bit_in_zero (precision - 1, precision);
    1500                 :             : 
    1501                 :       51955 :     case rvc_normal:
    1502                 :       51955 :       if (r->decimal)
    1503                 :         350 :         return decimal_real_to_integer (r, fail, precision);
    1504                 :             : 
    1505                 :       51605 :       exp = REAL_EXP (r);
    1506                 :       51605 :       if (exp <= 0)
    1507                 :           0 :         goto underflow;
    1508                 :             :       /* Only force overflow for unsigned overflow.  Signed overflow is
    1509                 :             :          undefined, so it doesn't matter what we return, and some callers
    1510                 :             :          expect to be able to use this routine for both signed and
    1511                 :             :          unsigned conversions.  */
    1512                 :       51605 :       if (exp > precision)
    1513                 :         209 :         goto overflow;
    1514                 :             : 
    1515                 :             :       /* Put the significand into a wide_int that has precision W, which
    1516                 :             :          is the smallest HWI-multiple that has at least PRECISION bits.
    1517                 :             :          This ensures that the top bit of the significand is in the
    1518                 :             :          top bit of the wide_int.  */
    1519                 :       51396 :       words = ((precision + HOST_BITS_PER_WIDE_INT - 1)
    1520                 :             :                / HOST_BITS_PER_WIDE_INT);
    1521                 :       51396 :       val = valb;
    1522                 :       51396 :       if (UNLIKELY (words > WIDE_INT_MAX_INL_ELTS))
    1523                 :           0 :         val = XALLOCAVEC (HOST_WIDE_INT, words);
    1524                 :       51396 :       w = words * HOST_BITS_PER_WIDE_INT;
    1525                 :             : 
    1526                 :             : #if (HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG)
    1527                 :      103646 :       for (int i = 0; i < words; i++)
    1528                 :             :         {
    1529                 :       52250 :           int j = SIGSZ - words + i;
    1530                 :       52250 :           val[i] = (j < 0) ? 0 : r->sig[j];
    1531                 :             :         }
    1532                 :             : #else
    1533                 :             :       gcc_assert (HOST_BITS_PER_WIDE_INT == 2 * HOST_BITS_PER_LONG);
    1534                 :             :       for (int i = 0; i < words; i++)
    1535                 :             :         {
    1536                 :             :           int j = SIGSZ - (words * 2) + (i * 2);
    1537                 :             :           if (j < 0)
    1538                 :             :             val[i] = 0;
    1539                 :             :           else
    1540                 :             :             val[i] = r->sig[j];
    1541                 :             :           j += 1;
    1542                 :             :           if (j >= 0)
    1543                 :             :             val[i] |= (unsigned HOST_WIDE_INT) r->sig[j] << HOST_BITS_PER_LONG;
    1544                 :             :         }
    1545                 :             : #endif
    1546                 :             :       /* Shift the value into place and truncate to the desired precision.  */
    1547                 :       51396 :       result = wide_int::from_array (val, words, w);
    1548                 :       51396 :       result = wi::lrshift (result, w - exp);
    1549                 :       51396 :       result = wide_int::from (result, precision, UNSIGNED);
    1550                 :             : 
    1551                 :       51396 :       if (r->sign)
    1552                 :       21653 :         return -result;
    1553                 :             :       else
    1554                 :       29743 :         return result;
    1555                 :             : 
    1556                 :           0 :     default:
    1557                 :           0 :       gcc_unreachable ();
    1558                 :             :     }
    1559                 :       75312 : }
    1560                 :             : 
    1561                 :             : /* A subroutine of real_to_decimal.  Compute the quotient and remainder
    1562                 :             :    of NUM / DEN.  Return the quotient and place the remainder in NUM.
    1563                 :             :    It is expected that NUM / DEN are close enough that the quotient is
    1564                 :             :    small.  */
    1565                 :             : 
    1566                 :             : static unsigned long
    1567                 :    21567922 : rtd_divmod (REAL_VALUE_TYPE *num, REAL_VALUE_TYPE *den)
    1568                 :             : {
    1569                 :    21567922 :   unsigned long q, msb;
    1570                 :    21567922 :   int expn = REAL_EXP (num), expd = REAL_EXP (den);
    1571                 :             : 
    1572                 :    21567922 :   if (expn < expd)
    1573                 :             :     return 0;
    1574                 :             : 
    1575                 :    13725458 :   q = msb = 0;
    1576                 :    13725458 :   goto start;
    1577                 :    27084464 :   do
    1578                 :             :     {
    1579                 :    27084464 :       msb = num->sig[SIGSZ-1] & SIG_MSB;
    1580                 :    27084464 :       q <<= 1;
    1581                 :    27084464 :       lshift_significand_1 (num, num);
    1582                 :    40809922 :     start:
    1583                 :    73845599 :       if (msb || cmp_significands (num, den) >= 0)
    1584                 :             :         {
    1585                 :    21910545 :           sub_significands (num, num, den, 0);
    1586                 :    21910545 :           q |= 1;
    1587                 :             :         }
    1588                 :             :     }
    1589                 :    40809922 :   while (--expn >= expd);
    1590                 :             : 
    1591                 :    13725458 :   SET_REAL_EXP (num, expd);
    1592                 :    13725458 :   normalize (num);
    1593                 :             : 
    1594                 :    13725458 :   return q;
    1595                 :             : }
    1596                 :             : 
    1597                 :             : /* Render R as a decimal floating point constant.  Emit DIGITS significant
    1598                 :             :    digits in the result, bounded by BUF_SIZE.  If DIGITS is 0, choose the
    1599                 :             :    maximum for the representation.  If CROP_TRAILING_ZEROS, strip trailing
    1600                 :             :    zeros.  If MODE is VOIDmode, round to nearest value.  Otherwise, round
    1601                 :             :    to a string that, when parsed back in mode MODE, yields the same value.  */
    1602                 :             : 
    1603                 :             : #define M_LOG10_2       0.30102999566398119521
    1604                 :             : 
    1605                 :             : void
    1606                 :      616418 : real_to_decimal_for_mode (char *str, const REAL_VALUE_TYPE *r_orig,
    1607                 :             :                           size_t buf_size, size_t digits,
    1608                 :             :                           int crop_trailing_zeros, machine_mode mode)
    1609                 :             : {
    1610                 :      616418 :   const struct real_format *fmt = NULL;
    1611                 :      616418 :   const REAL_VALUE_TYPE *one, *ten;
    1612                 :      616418 :   REAL_VALUE_TYPE r, pten, u, v;
    1613                 :      616418 :   int dec_exp, cmp_one, digit;
    1614                 :      616418 :   size_t max_digits;
    1615                 :      616418 :   char *p, *first, *last;
    1616                 :      616418 :   bool sign;
    1617                 :      616418 :   bool round_up;
    1618                 :             : 
    1619                 :      616418 :   if (mode != VOIDmode)
    1620                 :             :    {
    1621                 :      430284 :      fmt = REAL_MODE_FORMAT (mode);
    1622                 :      430284 :      gcc_assert (fmt);
    1623                 :             :    }
    1624                 :             : 
    1625                 :      616418 :   r = *r_orig;
    1626                 :      616418 :   switch (r.cl)
    1627                 :             :     {
    1628                 :       93337 :     case rvc_zero:
    1629                 :       93337 :       strcpy (str, (r.sign ? "-0.0" : "0.0"));
    1630                 :       94171 :       return;
    1631                 :      522301 :     case rvc_normal:
    1632                 :      522301 :       break;
    1633                 :         421 :     case rvc_inf:
    1634                 :         421 :       strcpy (str, (r.sign ? "-Inf" : "+Inf"));
    1635                 :         421 :       return;
    1636                 :         359 :     case rvc_nan:
    1637                 :             :       /* ??? Print the significand as well, if not canonical?  */
    1638                 :         359 :       sprintf (str, "%c%cNaN", (r_orig->sign ? '-' : '+'),
    1639                 :         359 :                (r_orig->signalling ? 'S' : 'Q'));
    1640                 :         359 :       return;
    1641                 :           0 :     default:
    1642                 :           0 :       gcc_unreachable ();
    1643                 :             :     }
    1644                 :             : 
    1645                 :      522301 :   if (r.decimal)
    1646                 :             :     {
    1647                 :          54 :       decimal_real_to_decimal (str, &r, buf_size, digits, crop_trailing_zeros);
    1648                 :          54 :       return;
    1649                 :             :     }
    1650                 :             : 
    1651                 :             :   /* Bound the number of digits printed by the size of the representation.  */
    1652                 :      522247 :   max_digits = SIGNIFICAND_BITS * M_LOG10_2;
    1653                 :      522247 :   if (digits == 0 || digits > max_digits)
    1654                 :       91236 :     digits = max_digits;
    1655                 :             : 
    1656                 :             :   /* Estimate the decimal exponent, and compute the length of the string it
    1657                 :             :      will print as.  Be conservative and add one to account for possible
    1658                 :             :      overflow or rounding error.  */
    1659                 :      522247 :   dec_exp = REAL_EXP (&r) * M_LOG10_2;
    1660                 :     1656850 :   for (max_digits = 1; dec_exp ; max_digits++)
    1661                 :     1134603 :     dec_exp /= 10;
    1662                 :             : 
    1663                 :             :   /* Bound the number of digits printed by the size of the output buffer.  */
    1664                 :      522247 :   max_digits = buf_size - 1 - 1 - 2 - max_digits - 1;
    1665                 :      522247 :   gcc_assert (max_digits <= buf_size);
    1666                 :      522247 :   if (digits > max_digits)
    1667                 :             :     digits = max_digits;
    1668                 :             : 
    1669                 :      522247 :   one = real_digit (1);
    1670                 :      522247 :   ten = ten_to_ptwo (0);
    1671                 :             : 
    1672                 :      522247 :   sign = r.sign;
    1673                 :      522247 :   r.sign = 0;
    1674                 :             : 
    1675                 :      522247 :   dec_exp = 0;
    1676                 :      522247 :   pten = *one;
    1677                 :             : 
    1678                 :      522247 :   cmp_one = do_compare (&r, one, 0);
    1679                 :      522247 :   if (cmp_one > 0)
    1680                 :             :     {
    1681                 :      174870 :       int m;
    1682                 :             : 
    1683                 :             :       /* Number is greater than one.  Convert significand to an integer
    1684                 :             :          and strip trailing decimal zeros.  */
    1685                 :             : 
    1686                 :      174870 :       u = r;
    1687                 :      174870 :       SET_REAL_EXP (&u, SIGNIFICAND_BITS - 1);
    1688                 :             : 
    1689                 :             :       /* Largest M, such that 10**2**M fits within SIGNIFICAND_BITS.  */
    1690                 :      349740 :       m = floor_log2 (max_digits);
    1691                 :             : 
    1692                 :             :       /* Iterate over the bits of the possible powers of 10 that might
    1693                 :             :          be present in U and eliminate them.  That is, if we find that
    1694                 :             :          10**2**M divides U evenly, keep the division and increase
    1695                 :             :          DEC_EXP by 2**M.  */
    1696                 :     1090843 :       do
    1697                 :             :         {
    1698                 :     1090843 :           REAL_VALUE_TYPE t;
    1699                 :             : 
    1700                 :     1090843 :           do_divide (&t, &u, ten_to_ptwo (m));
    1701                 :     1090843 :           do_fix_trunc (&v, &t);
    1702                 :     2181686 :           if (cmp_significands (&v, &t) == 0)
    1703                 :             :             {
    1704                 :       76994 :               u = t;
    1705                 :       76994 :               dec_exp += 1 << m;
    1706                 :             :             }
    1707                 :             :         }
    1708                 :     1090843 :       while (--m >= 0);
    1709                 :             : 
    1710                 :             :       /* Revert the scaling to integer that we performed earlier.  */
    1711                 :      174870 :       SET_REAL_EXP (&u, REAL_EXP (&u) + REAL_EXP (&r)
    1712                 :             :                     - (SIGNIFICAND_BITS - 1));
    1713                 :      174870 :       r = u;
    1714                 :             : 
    1715                 :             :       /* Find power of 10.  Do this by dividing out 10**2**M when
    1716                 :             :          this is larger than the current remainder.  Fill PTEN with
    1717                 :             :          the power of 10 that we compute.  */
    1718                 :      174870 :       if (REAL_EXP (&r) > 0)
    1719                 :             :         {
    1720                 :      317165 :           m = floor_log2 ((int)(REAL_EXP (&r) * M_LOG10_2)) + 1;
    1721                 :     1395067 :           do
    1722                 :             :             {
    1723                 :     1395067 :               const REAL_VALUE_TYPE *ptentwo = ten_to_ptwo (m);
    1724                 :     1395067 :               if (do_compare (&u, ptentwo, 0) >= 0)
    1725                 :             :                 {
    1726                 :      550384 :                   do_divide (&u, &u, ptentwo);
    1727                 :      550384 :                   do_multiply (&pten, &pten, ptentwo);
    1728                 :      550384 :                   dec_exp += 1 << m;
    1729                 :             :                 }
    1730                 :             :             }
    1731                 :     1395067 :           while (--m >= 0);
    1732                 :             :         }
    1733                 :             :       else
    1734                 :             :         /* We managed to divide off enough tens in the above reduction
    1735                 :             :            loop that we've now got a negative exponent.  Fall into the
    1736                 :             :            less-than-one code to compute the proper value for PTEN.  */
    1737                 :             :         cmp_one = -1;
    1738                 :             :     }
    1739                 :      518818 :   if (cmp_one < 0)
    1740                 :             :     {
    1741                 :      303202 :       int m;
    1742                 :             : 
    1743                 :             :       /* Number is less than one.  Pad significand with leading
    1744                 :             :          decimal zeros.  */
    1745                 :             : 
    1746                 :      303202 :       v = r;
    1747                 :    28608668 :       while (1)
    1748                 :             :         {
    1749                 :             :           /* Stop if we'd shift bits off the bottom.  */
    1750                 :    14455935 :           if (v.sig[0] & 7)
    1751                 :             :             break;
    1752                 :             : 
    1753                 :    14332535 :           do_multiply (&u, &v, ten);
    1754                 :             : 
    1755                 :             :           /* Stop if we're now >= 1 or zero.  */
    1756                 :    14332535 :           if (REAL_EXP (&u) > 0 || u.cl == rvc_zero)
    1757                 :             :             break;
    1758                 :             : 
    1759                 :    14152733 :           v = u;
    1760                 :    14152733 :           dec_exp -= 1;
    1761                 :             :         }
    1762                 :      303202 :       r = v;
    1763                 :             : 
    1764                 :             :       /* Find power of 10.  Do this by multiplying in P=10**2**M when
    1765                 :             :          the current remainder is smaller than 1/P.  Fill PTEN with the
    1766                 :             :          power of 10 that we compute.  */
    1767                 :      426602 :       m = floor_log2 ((int)(-REAL_EXP (&r) * M_LOG10_2)) + 1;
    1768                 :     1598797 :       do
    1769                 :             :         {
    1770                 :     1598797 :           const REAL_VALUE_TYPE *ptentwo = ten_to_ptwo (m);
    1771                 :     1598797 :           const REAL_VALUE_TYPE *ptenmtwo = ten_to_mptwo (m);
    1772                 :             : 
    1773                 :     1598797 :           if (do_compare (&v, ptenmtwo, 0) <= 0)
    1774                 :             :             {
    1775                 :      644212 :               do_multiply (&v, &v, ptentwo);
    1776                 :      644212 :               do_multiply (&pten, &pten, ptentwo);
    1777                 :      644212 :               dec_exp -= 1 << m;
    1778                 :             :             }
    1779                 :             :         }
    1780                 :     1598797 :       while (--m >= 0);
    1781                 :             : 
    1782                 :             :       /* Invert the positive power of 10 that we've collected so far.  */
    1783                 :      303202 :       do_divide (&pten, one, &pten);
    1784                 :             :     }
    1785                 :             : 
    1786                 :      522247 :   p = str;
    1787                 :      522247 :   if (sign)
    1788                 :       18885 :     *p++ = '-';
    1789                 :      522247 :   first = p++;
    1790                 :             : 
    1791                 :             :   /* At this point, PTEN should contain the nearest power of 10 smaller
    1792                 :             :      than R, such that this division produces the first digit.
    1793                 :             : 
    1794                 :             :      Using a divide-step primitive that returns the complete integral
    1795                 :             :      remainder avoids the rounding error that would be produced if
    1796                 :             :      we were to use do_divide here and then simply multiply by 10 for
    1797                 :             :      each subsequent digit.  */
    1798                 :             : 
    1799                 :      522247 :   digit = rtd_divmod (&r, &pten);
    1800                 :             : 
    1801                 :             :   /* Be prepared for error in that division via underflow ...  */
    1802                 :      825449 :   if (digit == 0 && cmp_significand_0 (&r))
    1803                 :             :     {
    1804                 :             :       /* Multiply by 10 and try again.  */
    1805                 :      303202 :       do_multiply (&r, &r, ten);
    1806                 :      303202 :       digit = rtd_divmod (&r, &pten);
    1807                 :      303202 :       dec_exp -= 1;
    1808                 :      303202 :       gcc_assert (digit != 0);
    1809                 :             :     }
    1810                 :             : 
    1811                 :             :   /* ... or overflow.  */
    1812                 :      522247 :   if (digit == 10)
    1813                 :             :     {
    1814                 :           0 :       *p++ = '1';
    1815                 :           0 :       if (--digits > 0)
    1816                 :           0 :         *p++ = '0';
    1817                 :           0 :       dec_exp += 1;
    1818                 :             :     }
    1819                 :             :   else
    1820                 :             :     {
    1821                 :      522247 :       gcc_assert (digit <= 10);
    1822                 :      522247 :       *p++ = digit + '0';
    1823                 :             :     }
    1824                 :             : 
    1825                 :             :   /* Generate subsequent digits.  */
    1826                 :    20696524 :   while (--digits > 0)
    1827                 :             :     {
    1828                 :    20174277 :       do_multiply (&r, &r, ten);
    1829                 :    20174277 :       digit = rtd_divmod (&r, &pten);
    1830                 :    20174277 :       *p++ = digit + '0';
    1831                 :             :     }
    1832                 :      522247 :   last = p;
    1833                 :             : 
    1834                 :             :   /* Generate one more digit with which to do rounding.  */
    1835                 :      522247 :   do_multiply (&r, &r, ten);
    1836                 :      522247 :   digit = rtd_divmod (&r, &pten);
    1837                 :             : 
    1838                 :             :   /* Round the result.  */
    1839                 :      522247 :   if (fmt && fmt->round_towards_zero)
    1840                 :             :     {
    1841                 :             :       /* If the format uses round towards zero when parsing the string
    1842                 :             :          back in, we need to always round away from zero here.  */
    1843                 :           0 :       if (cmp_significand_0 (&r))
    1844                 :           0 :         digit++;
    1845                 :           0 :       round_up = digit > 0;
    1846                 :             :     }
    1847                 :             :   else
    1848                 :             :     {
    1849                 :      522247 :       if (digit == 5)
    1850                 :             :         {
    1851                 :             :           /* Round to nearest.  If R is nonzero there are additional
    1852                 :             :              nonzero digits to be extracted.  */
    1853                 :       55629 :           if (cmp_significand_0 (&r))
    1854                 :             :             digit++;
    1855                 :             :           /* Round to even.  */
    1856                 :       31007 :           else if ((p[-1] - '0') & 1)
    1857                 :       24634 :             digit++;
    1858                 :             :         }
    1859                 :             : 
    1860                 :      522247 :       round_up = digit > 5;
    1861                 :             :     }
    1862                 :             : 
    1863                 :      522247 :   if (round_up)
    1864                 :             :     {
    1865                 :      160721 :       while (p > first)
    1866                 :             :         {
    1867                 :      160721 :           digit = *--p;
    1868                 :      160721 :           if (digit == '9')
    1869                 :         491 :             *p = '0';
    1870                 :             :           else
    1871                 :             :             {
    1872                 :      160230 :               *p = digit + 1;
    1873                 :      160230 :               break;
    1874                 :             :             }
    1875                 :             :         }
    1876                 :             : 
    1877                 :             :       /* Carry out of the first digit.  This means we had all 9's and
    1878                 :             :          now have all 0's.  "Prepend" a 1 by overwriting the first 0.  */
    1879                 :      160230 :       if (p == first)
    1880                 :             :         {
    1881                 :           0 :           first[1] = '1';
    1882                 :           0 :           dec_exp++;
    1883                 :             :         }
    1884                 :             :     }
    1885                 :             : 
    1886                 :             :   /* Insert the decimal point.  */
    1887                 :      522247 :   first[0] = first[1];
    1888                 :      522247 :   first[1] = '.';
    1889                 :             : 
    1890                 :             :   /* If requested, drop trailing zeros.  Never crop past "1.0".  */
    1891                 :      522247 :   if (crop_trailing_zeros)
    1892                 :     4959117 :     while (last > first + 3 && last[-1] == '0')
    1893                 :     4866986 :       last--;
    1894                 :             : 
    1895                 :             :   /* Append the exponent.  */
    1896                 :      522247 :   sprintf (last, "e%+d", dec_exp);
    1897                 :             : 
    1898                 :             :   /* Verify that we can read the original value back in.  */
    1899                 :      522247 :   if (flag_checking && mode != VOIDmode)
    1900                 :             :     {
    1901                 :      430185 :       real_from_string (&r, str);
    1902                 :      430185 :       real_convert (&r, mode, &r);
    1903                 :      430185 :       gcc_assert (real_identical (&r, r_orig));
    1904                 :             :     }
    1905                 :             : }
    1906                 :             : 
    1907                 :             : /* Likewise, except always uses round-to-nearest.  */
    1908                 :             : 
    1909                 :             : void
    1910                 :      186134 : real_to_decimal (char *str, const REAL_VALUE_TYPE *r_orig, size_t buf_size,
    1911                 :             :                  size_t digits, int crop_trailing_zeros)
    1912                 :             : {
    1913                 :      186134 :   real_to_decimal_for_mode (str, r_orig, buf_size,
    1914                 :             :                             digits, crop_trailing_zeros, VOIDmode);
    1915                 :      186134 : }
    1916                 :             : 
    1917                 :             : DEBUG_FUNCTION void
    1918                 :           0 : debug (const REAL_VALUE_TYPE &r)
    1919                 :             : {
    1920                 :           0 :   char s[60];
    1921                 :           0 :   real_to_hexadecimal (s, &r, sizeof (s), 0, 1);
    1922                 :           0 :   fprintf (stderr, "%s\n", s);
    1923                 :           0 : }
    1924                 :             : 
    1925                 :             : /* Render R as a hexadecimal floating point constant.  Emit DIGITS
    1926                 :             :    significant digits in the result, bounded by BUF_SIZE.  If DIGITS is 0,
    1927                 :             :    choose the maximum for the representation.  If CROP_TRAILING_ZEROS,
    1928                 :             :    strip trailing zeros.  */
    1929                 :             : 
    1930                 :             : void
    1931                 :      617924 : real_to_hexadecimal (char *str, const REAL_VALUE_TYPE *r, size_t buf_size,
    1932                 :             :                      size_t digits, int crop_trailing_zeros)
    1933                 :             : {
    1934                 :      617924 :   int i, j, exp = REAL_EXP (r);
    1935                 :      617924 :   char *p, *first;
    1936                 :      617924 :   char exp_buf[16];
    1937                 :      617924 :   size_t max_digits;
    1938                 :             : 
    1939                 :      617924 :   switch (r->cl)
    1940                 :             :     {
    1941                 :       94109 :     case rvc_zero:
    1942                 :       94109 :       exp = 0;
    1943                 :       94109 :       break;
    1944                 :             :     case rvc_normal:
    1945                 :             :       break;
    1946                 :           0 :     case rvc_inf:
    1947                 :           0 :       strcpy (str, (r->sign ? "-Inf" : "+Inf"));
    1948                 :           4 :       return;
    1949                 :           4 :     case rvc_nan:
    1950                 :             :       /* ??? Print the significand as well, if not canonical?  */
    1951                 :           4 :       sprintf (str, "%c%cNaN", (r->sign ? '-' : '+'),
    1952                 :           4 :                (r->signalling ? 'S' : 'Q'));
    1953                 :           4 :       return;
    1954                 :           0 :     default:
    1955                 :           0 :       gcc_unreachable ();
    1956                 :             :     }
    1957                 :             : 
    1958                 :      617920 :   if (r->decimal)
    1959                 :             :     {
    1960                 :             :       /* Hexadecimal format for decimal floats is not interesting. */
    1961                 :           0 :       strcpy (str, "N/A");
    1962                 :           0 :       return;
    1963                 :             :     }
    1964                 :             : 
    1965                 :      617920 :   if (digits == 0)
    1966                 :      617920 :     digits = SIGNIFICAND_BITS / 4;
    1967                 :             : 
    1968                 :             :   /* Bound the number of digits printed by the size of the output buffer.  */
    1969                 :             : 
    1970                 :      617920 :   sprintf (exp_buf, "p%+d", exp);
    1971                 :      617920 :   max_digits = buf_size - strlen (exp_buf) - r->sign - 4 - 1;
    1972                 :      617920 :   gcc_assert (max_digits <= buf_size);
    1973                 :      617920 :   if (digits > max_digits)
    1974                 :             :     digits = max_digits;
    1975                 :             : 
    1976                 :      617920 :   p = str;
    1977                 :      617920 :   if (r->sign)
    1978                 :       92037 :     *p++ = '-';
    1979                 :      617920 :   *p++ = '0';
    1980                 :      617920 :   *p++ = 'x';
    1981                 :      617920 :   *p++ = '0';
    1982                 :      617920 :   *p++ = '.';
    1983                 :      617920 :   first = p;
    1984                 :             : 
    1985                 :     1853760 :   for (i = SIGSZ - 1; i >= 0; --i)
    1986                 :    30896000 :     for (j = HOST_BITS_PER_LONG - 4; j >= 0; j -= 4)
    1987                 :             :       {
    1988                 :    29660160 :         *p++ = "0123456789abcdef"[(r->sig[i] >> j) & 15];
    1989                 :    29660160 :         if (--digits == 0)
    1990                 :      617920 :           goto out;
    1991                 :             :       }
    1992                 :             : 
    1993                 :           0 :  out:
    1994                 :      617920 :   if (crop_trailing_zeros)
    1995                 :    26967869 :     while (p > first + 1 && p[-1] == '0')
    1996                 :    26349949 :       p--;
    1997                 :             : 
    1998                 :      617920 :   sprintf (p, "p%+d", exp);
    1999                 :             : }
    2000                 :             : 
    2001                 :             : /* Initialize R from a decimal or hexadecimal string.  The string is
    2002                 :             :    assumed to have been syntax checked already.  Return -1 if the
    2003                 :             :    value underflows, +1 if overflows, and 0 otherwise. */
    2004                 :             : 
    2005                 :             : int
    2006                 :    32539149 : real_from_string (REAL_VALUE_TYPE *r, const char *str)
    2007                 :             : {
    2008                 :    32539149 :   int exp = 0;
    2009                 :    32539149 :   bool sign = false;
    2010                 :             : 
    2011                 :    32539149 :   get_zero (r, 0);
    2012                 :             : 
    2013                 :    32539149 :   if (*str == '-')
    2014                 :             :     {
    2015                 :       81899 :       sign = true;
    2016                 :       81899 :       str++;
    2017                 :             :     }
    2018                 :    32457250 :   else if (*str == '+')
    2019                 :          25 :     str++;
    2020                 :             : 
    2021                 :    32539149 :   if (startswith (str, "QNaN"))
    2022                 :             :     {
    2023                 :          16 :       get_canonical_qnan (r, sign);
    2024                 :          16 :       return 0;
    2025                 :             :     }
    2026                 :    32539133 :   else if (startswith (str, "SNaN"))
    2027                 :             :     {
    2028                 :          16 :       get_canonical_snan (r, sign);
    2029                 :          16 :       return 0;
    2030                 :             :     }
    2031                 :    32539117 :   else if (startswith (str, "Inf"))
    2032                 :             :     {
    2033                 :          49 :       get_inf (r, sign);
    2034                 :          49 :       return 0;
    2035                 :             :     }
    2036                 :             : 
    2037                 :    32539068 :   if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
    2038                 :             :     {
    2039                 :             :       /* Hexadecimal floating point.  */
    2040                 :    26563675 :       int pos = SIGNIFICAND_BITS - 4, d;
    2041                 :             : 
    2042                 :    26563675 :       str += 2;
    2043                 :             : 
    2044                 :    48276876 :       while (*str == '0')
    2045                 :    21713201 :         str++;
    2046                 :    27976497 :       while (1)
    2047                 :             :         {
    2048                 :    27270086 :           d = hex_value (*str);
    2049                 :    27270086 :           if (d == _hex_bad)
    2050                 :             :             break;
    2051                 :      706411 :           if (pos >= 0)
    2052                 :             :             {
    2053                 :      706375 :               r->sig[pos / HOST_BITS_PER_LONG]
    2054                 :      706375 :                 |= (unsigned long) d << (pos % HOST_BITS_PER_LONG);
    2055                 :      706375 :               pos -= 4;
    2056                 :             :             }
    2057                 :          36 :           else if (d)
    2058                 :             :             /* Ensure correct rounding by setting last bit if there is
    2059                 :             :                a subsequent nonzero digit.  */
    2060                 :           8 :             r->sig[0] |= 1;
    2061                 :      706411 :           exp += 4;
    2062                 :      706411 :           str++;
    2063                 :             :         }
    2064                 :    26563675 :       if (*str == '.')
    2065                 :             :         {
    2066                 :    25921763 :           str++;
    2067                 :    25921763 :           if (pos == SIGNIFICAND_BITS - 4)
    2068                 :             :             {
    2069                 :    26932418 :               while (*str == '0')
    2070                 :     1055140 :                 str++, exp -= 4;
    2071                 :             :             }
    2072                 :   991701335 :           while (1)
    2073                 :             :             {
    2074                 :   508811549 :               d = hex_value (*str);
    2075                 :   508811549 :               if (d == _hex_bad)
    2076                 :             :                 break;
    2077                 :   482889786 :               if (pos >= 0)
    2078                 :             :                 {
    2079                 :   478659841 :                   r->sig[pos / HOST_BITS_PER_LONG]
    2080                 :   478659841 :                     |= (unsigned long) d << (pos % HOST_BITS_PER_LONG);
    2081                 :   478659841 :                   pos -= 4;
    2082                 :             :                 }
    2083                 :     4229945 :               else if (d)
    2084                 :             :                 /* Ensure correct rounding by setting last bit if there is
    2085                 :             :                    a subsequent nonzero digit.  */
    2086                 :      820838 :                 r->sig[0] |= 1;
    2087                 :   482889786 :               str++;
    2088                 :             :             }
    2089                 :             :         }
    2090                 :             : 
    2091                 :             :       /* If the mantissa is zero, ignore the exponent.  */
    2092                 :    53127350 :       if (!cmp_significand_0 (r))
    2093                 :       64664 :         goto is_a_zero;
    2094                 :             : 
    2095                 :    26499011 :       if (*str == 'p' || *str == 'P')
    2096                 :             :         {
    2097                 :    26499011 :           bool exp_neg = false;
    2098                 :             : 
    2099                 :    26499011 :           str++;
    2100                 :    26499011 :           if (*str == '-')
    2101                 :             :             {
    2102                 :     1398186 :               exp_neg = true;
    2103                 :     1398186 :               str++;
    2104                 :             :             }
    2105                 :    25100825 :           else if (*str == '+')
    2106                 :       19239 :             str++;
    2107                 :             : 
    2108                 :    26499011 :           d = 0;
    2109                 :   121336289 :           while (ISDIGIT (*str))
    2110                 :             :             {
    2111                 :    94837278 :               d *= 10;
    2112                 :    94837278 :               d += *str - '0';
    2113                 :    94837278 :               if (d > MAX_EXP)
    2114                 :             :                 {
    2115                 :             :                   /* Overflowed the exponent.  */
    2116                 :           0 :                   if (exp_neg)
    2117                 :           0 :                     goto underflow;
    2118                 :             :                   else
    2119                 :           0 :                     goto overflow;
    2120                 :             :                 }
    2121                 :    94837278 :               str++;
    2122                 :             :             }
    2123                 :    26499011 :           if (exp_neg)
    2124                 :     1398186 :             d = -d;
    2125                 :             : 
    2126                 :    26499011 :           exp += d;
    2127                 :             :         }
    2128                 :             : 
    2129                 :    26499011 :       r->cl = rvc_normal;
    2130                 :    26499011 :       SET_REAL_EXP (r, exp);
    2131                 :             : 
    2132                 :    26499011 :       normalize (r);
    2133                 :    26499011 :     }
    2134                 :             :   else
    2135                 :             :     {
    2136                 :             :       /* Decimal floating point.  */
    2137                 :             :       const char *cstr = str;
    2138                 :             :       bool inexact;
    2139                 :             : 
    2140                 :     9307869 :       while (*cstr == '0')
    2141                 :     3332476 :         cstr++;
    2142                 :     5975393 :       if (*cstr == '.')
    2143                 :             :         {
    2144                 :     3333504 :           cstr++;
    2145                 :     6093086 :           while (*cstr == '0')
    2146                 :     2759582 :             cstr++;
    2147                 :             :         }
    2148                 :             : 
    2149                 :             :       /* If the mantissa is zero, ignore the exponent.  */
    2150                 :     5975393 :       if (!ISDIGIT (*cstr))
    2151                 :     2333968 :         goto is_a_zero;
    2152                 :             : 
    2153                 :             :       /* Nonzero value, possibly overflowing or underflowing.  */
    2154                 :     3641425 :       auto_mpfr m (SIGNIFICAND_BITS);
    2155                 :     3641425 :       inexact = mpfr_strtofr (m, str, NULL, 10, MPFR_RNDZ);
    2156                 :             :       /* The result should never be a NaN, and because the rounding is
    2157                 :             :          toward zero should never be an infinity.  */
    2158                 :     3641425 :       gcc_assert (!mpfr_nan_p (m) && !mpfr_inf_p (m));
    2159                 :     3641425 :       if (mpfr_zero_p (m) || mpfr_get_exp (m) < -MAX_EXP + 4)
    2160                 :          42 :         goto underflow;
    2161                 :     3641383 :       else if (mpfr_get_exp (m) > MAX_EXP - 4)
    2162                 :           0 :         goto overflow;
    2163                 :             :       else
    2164                 :             :         {
    2165                 :     3641383 :           real_from_mpfr (r, m, NULL_TREE, MPFR_RNDZ);
    2166                 :             :           /* 1 to 3 bits may have been shifted off (with a sticky bit)
    2167                 :             :              because the hex digits used in real_from_mpfr did not
    2168                 :             :              start with a digit 8 to f, but the exponent bounds above
    2169                 :             :              should have avoided underflow or overflow.  */
    2170                 :     3641383 :           gcc_assert (r->cl == rvc_normal);
    2171                 :             :           /* Set a sticky bit if mpfr_strtofr was inexact.  */
    2172                 :     3641383 :           r->sig[0] |= inexact;
    2173                 :             :         }
    2174                 :     3641425 :     }
    2175                 :             : 
    2176                 :    30140394 :   r->sign = sign;
    2177                 :    30140394 :   return 0;
    2178                 :             : 
    2179                 :     2398632 :  is_a_zero:
    2180                 :     2398632 :   get_zero (r, sign);
    2181                 :     2398632 :   return 0;
    2182                 :             : 
    2183                 :          42 :  underflow:
    2184                 :          42 :   get_zero (r, sign);
    2185                 :          42 :   return -1;
    2186                 :             : 
    2187                 :           0 :  overflow:
    2188                 :           0 :   get_inf (r, sign);
    2189                 :           0 :   return 1;
    2190                 :             : }
    2191                 :             : 
    2192                 :             : /* Legacy.  Similar, but return the result directly.  */
    2193                 :             : 
    2194                 :             : REAL_VALUE_TYPE
    2195                 :        6207 : real_from_string2 (const char *s, format_helper fmt)
    2196                 :             : {
    2197                 :        6207 :   REAL_VALUE_TYPE r;
    2198                 :             : 
    2199                 :        6207 :   real_from_string (&r, s);
    2200                 :        6207 :   if (fmt)
    2201                 :        6207 :     real_convert (&r, fmt, &r);
    2202                 :             : 
    2203                 :        6207 :   return r;
    2204                 :             : }
    2205                 :             : 
    2206                 :             : /* Initialize R from string S and desired format FMT. */
    2207                 :             : 
    2208                 :             : void
    2209                 :     4426187 : real_from_string3 (REAL_VALUE_TYPE *r, const char *s, format_helper fmt)
    2210                 :             : {
    2211                 :     4426187 :   if (fmt.decimal_p ())
    2212                 :       17994 :     decimal_real_from_string (r, s);
    2213                 :             :   else
    2214                 :     4408193 :     real_from_string (r, s);
    2215                 :             : 
    2216                 :     4426187 :   if (fmt)
    2217                 :     4426187 :     real_convert (r, fmt, r);
    2218                 :     4426187 : }
    2219                 :             : 
    2220                 :             : /* Initialize R from the wide_int VAL_IN.  Round it to format FMT if
    2221                 :             :    FMT is nonnull.  */
    2222                 :             : 
    2223                 :             : void
    2224                 :    24587951 : real_from_integer (REAL_VALUE_TYPE *r, format_helper fmt,
    2225                 :             :                    const wide_int_ref &val_in, signop sgn)
    2226                 :             : {
    2227                 :    24587951 :   if (val_in == 0)
    2228                 :     4358420 :     get_zero (r, 0);
    2229                 :             :   else
    2230                 :             :     {
    2231                 :    20229531 :       unsigned int len = val_in.get_precision ();
    2232                 :    20229531 :       int i, j, e = 0;
    2233                 :    20229531 :       int maxbitlen = MAX_BITSIZE_MODE_ANY_INT + HOST_BITS_PER_WIDE_INT;
    2234                 :    20229531 :       const unsigned int realmax = (SIGNIFICAND_BITS / HOST_BITS_PER_WIDE_INT
    2235                 :             :                                     * HOST_BITS_PER_WIDE_INT);
    2236                 :             : 
    2237                 :    20229531 :       memset (r, 0, sizeof (*r));
    2238                 :    20229531 :       r->cl = rvc_normal;
    2239                 :    20229531 :       r->sign = wi::neg_p (val_in, sgn);
    2240                 :             : 
    2241                 :             :       /* We have to ensure we can negate the largest negative number.  */
    2242                 :    20229531 :       wide_int val = wide_int::from (val_in, maxbitlen, sgn);
    2243                 :             : 
    2244                 :    20229531 :       if (r->sign)
    2245                 :      311618 :         val = -val;
    2246                 :             : 
    2247                 :             :       /* Ensure a multiple of HOST_BITS_PER_WIDE_INT, ceiling, as elt
    2248                 :             :          won't work with precisions that are not a multiple of
    2249                 :             :          HOST_BITS_PER_WIDE_INT.  */
    2250                 :    20229531 :       len += HOST_BITS_PER_WIDE_INT - 1;
    2251                 :             : 
    2252                 :             :       /* Ensure we can represent the largest negative number.  */
    2253                 :    20229531 :       len += 1;
    2254                 :             : 
    2255                 :    20229531 :       len = len/HOST_BITS_PER_WIDE_INT * HOST_BITS_PER_WIDE_INT;
    2256                 :             : 
    2257                 :             :       /* Cap the size to the size allowed by real.h.  */
    2258                 :    20229531 :       if (len > realmax)
    2259                 :             :         {
    2260                 :         117 :           HOST_WIDE_INT cnt_l_z;
    2261                 :         117 :           cnt_l_z = wi::clz (val);
    2262                 :             : 
    2263                 :         117 :           if (maxbitlen - cnt_l_z > realmax)
    2264                 :             :             {
    2265                 :          10 :               e = maxbitlen - cnt_l_z - realmax;
    2266                 :             : 
    2267                 :             :               /* This value is too large, we must shift it right to
    2268                 :             :                  preserve all the bits we can, and then bump the
    2269                 :             :                  exponent up by that amount.  */
    2270                 :          10 :               val = wi::lrshift (val, e);
    2271                 :             :             }
    2272                 :             :           len = realmax;
    2273                 :             :         }
    2274                 :             : 
    2275                 :             :       /* Clear out top bits so elt will work with precisions that aren't
    2276                 :             :          a multiple of HOST_BITS_PER_WIDE_INT.  */
    2277                 :    20229531 :       val = wide_int::from (val, len, sgn);
    2278                 :    20229531 :       len = len / HOST_BITS_PER_WIDE_INT;
    2279                 :             : 
    2280                 :    20229531 :       SET_REAL_EXP (r, len * HOST_BITS_PER_WIDE_INT + e);
    2281                 :             : 
    2282                 :    20229531 :       j = SIGSZ - 1;
    2283                 :    20229531 :       if (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT)
    2284                 :    41633172 :         for (i = len - 1; i >= 0; i--)
    2285                 :             :           {
    2286                 :    21411800 :             r->sig[j--] = val.elt (i);
    2287                 :    21411800 :             if (j < 0)
    2288                 :             :               break;
    2289                 :             :           }
    2290                 :             :       else
    2291                 :             :         {
    2292                 :             :           gcc_assert (HOST_BITS_PER_LONG*2 == HOST_BITS_PER_WIDE_INT);
    2293                 :             :           for (i = len - 1; i >= 0; i--)
    2294                 :             :             {
    2295                 :             :               HOST_WIDE_INT e = val.elt (i);
    2296                 :             :               r->sig[j--] = e >> (HOST_BITS_PER_LONG - 1) >> 1;
    2297                 :             :               if (j < 0)
    2298                 :             :                 break;
    2299                 :             :               r->sig[j--] = e;
    2300                 :             :               if (j < 0)
    2301                 :             :                 break;
    2302                 :             :             }
    2303                 :             :         }
    2304                 :             : 
    2305                 :    20229531 :       normalize (r);
    2306                 :    20229531 :     }
    2307                 :             : 
    2308                 :    24587951 :   if (fmt.decimal_p ())
    2309                 :       10510 :     decimal_from_integer (r);
    2310                 :    24587951 :   if (fmt)
    2311                 :    24416269 :     real_convert (r, fmt, r);
    2312                 :    24587951 : }
    2313                 :             : 
    2314                 :             : /* Render R, an integral value, as a floating point constant with no
    2315                 :             :    specified exponent.  */
    2316                 :             : 
    2317                 :             : static void
    2318                 :       10510 : decimal_integer_string (char *str, const REAL_VALUE_TYPE *r_orig,
    2319                 :             :                         size_t buf_size)
    2320                 :             : {
    2321                 :       10510 :   int dec_exp, digit, digits;
    2322                 :       10510 :   REAL_VALUE_TYPE r, pten;
    2323                 :       10510 :   char *p;
    2324                 :       10510 :   bool sign;
    2325                 :             : 
    2326                 :       10510 :   r = *r_orig;
    2327                 :             : 
    2328                 :       10510 :   if (r.cl == rvc_zero)
    2329                 :             :     {
    2330                 :        2132 :       strcpy (str, "0.");
    2331                 :        2132 :       return;
    2332                 :             :     }
    2333                 :             : 
    2334                 :        8378 :   sign = r.sign;
    2335                 :        8378 :   r.sign = 0;
    2336                 :             : 
    2337                 :        8378 :   dec_exp = REAL_EXP (&r) * M_LOG10_2;
    2338                 :        8378 :   digits = dec_exp + 1;
    2339                 :        8378 :   gcc_assert ((digits + 2) < (int)buf_size);
    2340                 :             : 
    2341                 :        8378 :   pten = *real_digit (1);
    2342                 :        8378 :   times_pten (&pten, dec_exp);
    2343                 :             : 
    2344                 :        8378 :   p = str;
    2345                 :        8378 :   if (sign)
    2346                 :        1190 :     *p++ = '-';
    2347                 :             : 
    2348                 :        8378 :   digit = rtd_divmod (&r, &pten);
    2349                 :        8378 :   gcc_assert (digit >= 0 && digit <= 9);
    2350                 :        8378 :   *p++ = digit + '0';
    2351                 :       45949 :   while (--digits > 0)
    2352                 :             :     {
    2353                 :       37571 :       times_pten (&r, 1);
    2354                 :       37571 :       digit = rtd_divmod (&r, &pten);
    2355                 :       37571 :       *p++ = digit + '0';
    2356                 :             :     }
    2357                 :        8378 :   *p++ = '.';
    2358                 :        8378 :   *p++ = '\0';
    2359                 :             : }
    2360                 :             : 
    2361                 :             : /* Convert a real with an integral value to decimal float.  */
    2362                 :             : 
    2363                 :             : static void
    2364                 :       10510 : decimal_from_integer (REAL_VALUE_TYPE *r)
    2365                 :             : {
    2366                 :       10510 :   char str[256];
    2367                 :             : 
    2368                 :       10510 :   decimal_integer_string (str, r, sizeof (str) - 1);
    2369                 :       10510 :   decimal_real_from_string (r, str);
    2370                 :       10510 : }
    2371                 :             : 
    2372                 :             : /* Returns 10**2**N.  */
    2373                 :             : 
    2374                 :             : static const REAL_VALUE_TYPE *
    2375                 :     4972713 : ten_to_ptwo (int n)
    2376                 :             : {
    2377                 :     4972713 :   static REAL_VALUE_TYPE tens[EXP_BITS];
    2378                 :             : 
    2379                 :     4972713 :   gcc_assert (n >= 0);
    2380                 :     4972713 :   gcc_assert (n < EXP_BITS);
    2381                 :             : 
    2382                 :     4972713 :   if (tens[n].cl == rvc_zero)
    2383                 :             :     {
    2384                 :      202065 :       if (n < (HOST_BITS_PER_WIDE_INT == 64 ? 5 : 4))
    2385                 :             :         {
    2386                 :             :           HOST_WIDE_INT t = 10;
    2387                 :             :           int i;
    2388                 :             : 
    2389                 :      225675 :           for (i = 0; i < n; ++i)
    2390                 :      150110 :             t *= t;
    2391                 :             : 
    2392                 :       75565 :           real_from_integer (&tens[n], VOIDmode, t, UNSIGNED);
    2393                 :             :         }
    2394                 :             :       else
    2395                 :             :         {
    2396                 :      126500 :           const REAL_VALUE_TYPE *t = ten_to_ptwo (n - 1);
    2397                 :      126500 :           do_multiply (&tens[n], t, t);
    2398                 :             :         }
    2399                 :             :     }
    2400                 :             : 
    2401                 :     4972713 :   return &tens[n];
    2402                 :             : }
    2403                 :             : 
    2404                 :             : /* Returns 10**(-2**N).  */
    2405                 :             : 
    2406                 :             : static const REAL_VALUE_TYPE *
    2407                 :     1598797 : ten_to_mptwo (int n)
    2408                 :             : {
    2409                 :     1598797 :   static REAL_VALUE_TYPE tens[EXP_BITS];
    2410                 :             : 
    2411                 :     1598797 :   gcc_assert (n >= 0);
    2412                 :     1598797 :   gcc_assert (n < EXP_BITS);
    2413                 :             : 
    2414                 :     1598797 :   if (tens[n].cl == rvc_zero)
    2415                 :      192895 :     do_divide (&tens[n], real_digit (1), ten_to_ptwo (n));
    2416                 :             : 
    2417                 :     1598797 :   return &tens[n];
    2418                 :             : }
    2419                 :             : 
    2420                 :             : /* Returns N.  */
    2421                 :             : 
    2422                 :             : static const REAL_VALUE_TYPE *
    2423                 :     1797556 : real_digit (int n)
    2424                 :             : {
    2425                 :     1797556 :   static REAL_VALUE_TYPE num[10];
    2426                 :             : 
    2427                 :     1797556 :   gcc_assert (n >= 0);
    2428                 :     1797556 :   gcc_assert (n <= 9);
    2429                 :             : 
    2430                 :     1797556 :   if (n > 0 && num[n].cl == rvc_zero)
    2431                 :       16947 :     real_from_integer (&num[n], VOIDmode, n, UNSIGNED);
    2432                 :             : 
    2433                 :     1797556 :   return &num[n];
    2434                 :             : }
    2435                 :             : 
    2436                 :             : /* Multiply R by 10**EXP.  */
    2437                 :             : 
    2438                 :             : static void
    2439                 :       45949 : times_pten (REAL_VALUE_TYPE *r, int exp)
    2440                 :             : {
    2441                 :       45949 :   REAL_VALUE_TYPE pten, *rr;
    2442                 :       45949 :   bool negative = (exp < 0);
    2443                 :       45949 :   int i;
    2444                 :             : 
    2445                 :       45949 :   if (negative)
    2446                 :             :     {
    2447                 :           0 :       exp = -exp;
    2448                 :           0 :       pten = *real_digit (1);
    2449                 :           0 :       rr = &pten;
    2450                 :             :     }
    2451                 :             :   else
    2452                 :             :     rr = r;
    2453                 :             : 
    2454                 :       98398 :   for (i = 0; exp > 0; ++i, exp >>= 1)
    2455                 :       52449 :     if (exp & 1)
    2456                 :       46364 :       do_multiply (rr, rr, ten_to_ptwo (i));
    2457                 :             : 
    2458                 :       45949 :   if (negative)
    2459                 :           0 :     do_divide (r, r, &pten);
    2460                 :       45949 : }
    2461                 :             : 
    2462                 :             : /* Returns the special REAL_VALUE_TYPE corresponding to 'e'.  */
    2463                 :             : 
    2464                 :             : const REAL_VALUE_TYPE *
    2465                 :          72 : dconst_e_ptr (void)
    2466                 :             : {
    2467                 :          72 :   static REAL_VALUE_TYPE value;
    2468                 :             : 
    2469                 :             :   /* Initialize mathematical constants for constant folding builtins.
    2470                 :             :      These constants need to be given to at least 160 bits precision.  */
    2471                 :          72 :   if (value.cl == rvc_zero)
    2472                 :             :     {
    2473                 :           6 :       auto_mpfr m (SIGNIFICAND_BITS);
    2474                 :           6 :       mpfr_set_ui (m, 1, MPFR_RNDN);
    2475                 :           6 :       mpfr_exp (m, m, MPFR_RNDN);
    2476                 :           6 :       real_from_mpfr (&value, m, NULL_TREE, MPFR_RNDN);
    2477                 :             : 
    2478                 :           6 :     }
    2479                 :          72 :   return &value;
    2480                 :             : }
    2481                 :             : 
    2482                 :             : /* Returns the special REAL_VALUE_TYPE corresponding to 'pi'.  */
    2483                 :             : 
    2484                 :             : const REAL_VALUE_TYPE *
    2485                 :         719 : dconst_pi_ptr (void)
    2486                 :             : {
    2487                 :         719 :   static REAL_VALUE_TYPE value;
    2488                 :             : 
    2489                 :             :   /* Initialize mathematical constants for constant folding builtins.
    2490                 :             :      These constants need to be given to at least 160 bits precision.  */
    2491                 :         719 :   if (value.cl == rvc_zero)
    2492                 :             :     {
    2493                 :          46 :       auto_mpfr m (SIGNIFICAND_BITS);
    2494                 :          46 :       mpfr_set_si (m, -1, MPFR_RNDN);
    2495                 :          46 :       mpfr_acos (m, m, MPFR_RNDN);
    2496                 :          46 :       real_from_mpfr (&value, m, NULL_TREE, MPFR_RNDN);
    2497                 :             : 
    2498                 :          46 :     }
    2499                 :         719 :   return &value;
    2500                 :             : }
    2501                 :             : 
    2502                 :             : /* Returns a cached REAL_VALUE_TYPE corresponding to 1/n, for various n.  */
    2503                 :             : 
    2504                 :             : #define CACHED_FRACTION(NAME, N)                                        \
    2505                 :             :   const REAL_VALUE_TYPE *                                               \
    2506                 :             :   NAME (void)                                                           \
    2507                 :             :   {                                                                     \
    2508                 :             :     static REAL_VALUE_TYPE value;                                       \
    2509                 :             :                                                                         \
    2510                 :             :     /* Initialize mathematical constants for constant folding builtins. \
    2511                 :             :        These constants need to be given to at least 160 bits            \
    2512                 :             :        precision.  */                                                   \
    2513                 :             :     if (value.cl == rvc_zero)                                           \
    2514                 :             :       real_arithmetic (&value, RDIV_EXPR, &dconst1, real_digit (N));    \
    2515                 :             :     return &value;                                                  \
    2516                 :             :   }
    2517                 :             : 
    2518                 :        1836 : CACHED_FRACTION (dconst_third_ptr, 3)
    2519                 :          36 : CACHED_FRACTION (dconst_quarter_ptr, 4)
    2520                 :          72 : CACHED_FRACTION (dconst_sixth_ptr, 6)
    2521                 :          36 : CACHED_FRACTION (dconst_ninth_ptr, 9)
    2522                 :             : 
    2523                 :             : /* Returns the special REAL_VALUE_TYPE corresponding to sqrt(2).  */
    2524                 :             : 
    2525                 :             : const REAL_VALUE_TYPE *
    2526                 :          21 : dconst_sqrt2_ptr (void)
    2527                 :             : {
    2528                 :          21 :   static REAL_VALUE_TYPE value;
    2529                 :             : 
    2530                 :             :   /* Initialize mathematical constants for constant folding builtins.
    2531                 :             :      These constants need to be given to at least 160 bits precision.  */
    2532                 :          21 :   if (value.cl == rvc_zero)
    2533                 :             :     {
    2534                 :           2 :       auto_mpfr m (SIGNIFICAND_BITS);
    2535                 :           2 :       mpfr_sqrt_ui (m, 2, MPFR_RNDN);
    2536                 :           2 :       real_from_mpfr (&value, m, NULL_TREE, MPFR_RNDN);
    2537                 :           2 :     }
    2538                 :          21 :   return &value;
    2539                 :             : }
    2540                 :             : 
    2541                 :             : /* Fills R with Inf with SIGN.  */
    2542                 :             : 
    2543                 :             : void
    2544                 :      709191 : real_inf (REAL_VALUE_TYPE *r, bool sign)
    2545                 :             : {
    2546                 :      709191 :   get_inf (r, sign);
    2547                 :      709191 : }
    2548                 :             : 
    2549                 :             : /* Fills R with a NaN whose significand is described by STR.  If QUIET,
    2550                 :             :    we force a QNaN, else we force an SNaN.  The string, if not empty,
    2551                 :             :    is parsed as a number and placed in the significand.  Return true
    2552                 :             :    if the string was successfully parsed.  */
    2553                 :             : 
    2554                 :             : bool
    2555                 :      375762 : real_nan (REAL_VALUE_TYPE *r, const char *str, int quiet,
    2556                 :             :           format_helper fmt)
    2557                 :             : {
    2558                 :      375762 :   if (*str == 0)
    2559                 :             :     {
    2560                 :      375297 :       if (quiet)
    2561                 :      230739 :         get_canonical_qnan (r, 0);
    2562                 :             :       else
    2563                 :      144558 :         get_canonical_snan (r, 0);
    2564                 :             :     }
    2565                 :             :   else
    2566                 :             :     {
    2567                 :         465 :       int base = 10, d;
    2568                 :             : 
    2569                 :         465 :       memset (r, 0, sizeof (*r));
    2570                 :         465 :       r->cl = rvc_nan;
    2571                 :             : 
    2572                 :             :       /* Parse akin to strtol into the significand of R.  */
    2573                 :             : 
    2574                 :         465 :       while (ISSPACE (*str))
    2575                 :           0 :         str++;
    2576                 :         465 :       if (*str == '-')
    2577                 :           0 :         str++;
    2578                 :         465 :       else if (*str == '+')
    2579                 :           0 :         str++;
    2580                 :         465 :       if (*str == '0')
    2581                 :             :         {
    2582                 :         435 :           str++;
    2583                 :         435 :           if (*str == 'x' || *str == 'X')
    2584                 :             :             {
    2585                 :         240 :               base = 16;
    2586                 :         240 :               str++;
    2587                 :             :             }
    2588                 :             :           else
    2589                 :         465 :             base = 8;
    2590                 :             :         }
    2591                 :             : 
    2592                 :        1167 :       while ((d = hex_value (*str)) < base)
    2593                 :             :         {
    2594                 :         702 :           REAL_VALUE_TYPE u;
    2595                 :             : 
    2596                 :         702 :           switch (base)
    2597                 :             :             {
    2598                 :           0 :             case 8:
    2599                 :           0 :               lshift_significand (r, r, 3);
    2600                 :           0 :               break;
    2601                 :         702 :             case 16:
    2602                 :         702 :               lshift_significand (r, r, 4);
    2603                 :         702 :               break;
    2604                 :           0 :             case 10:
    2605                 :           0 :               lshift_significand_1 (&u, r);
    2606                 :           0 :               lshift_significand (r, r, 3);
    2607                 :           0 :               add_significands (r, r, &u);
    2608                 :           0 :               break;
    2609                 :           0 :             default:
    2610                 :           0 :               gcc_unreachable ();
    2611                 :             :             }
    2612                 :             : 
    2613                 :         702 :           get_zero (&u, 0);
    2614                 :         702 :           u.sig[0] = d;
    2615                 :         702 :           add_significands (r, r, &u);
    2616                 :             : 
    2617                 :         702 :           str++;
    2618                 :             :         }
    2619                 :             : 
    2620                 :             :       /* Must have consumed the entire string for success.  */
    2621                 :         465 :       if (*str != 0)
    2622                 :             :         return false;
    2623                 :             : 
    2624                 :             :       /* Shift the significand into place such that the bits
    2625                 :             :          are in the most significant bits for the format.  */
    2626                 :         435 :       lshift_significand (r, r, SIGNIFICAND_BITS - fmt->pnan);
    2627                 :             : 
    2628                 :             :       /* Our MSB is always unset for NaNs.  */
    2629                 :         435 :       r->sig[SIGSZ-1] &= ~SIG_MSB;
    2630                 :             : 
    2631                 :             :       /* Force quiet or signaling NaN.  */
    2632                 :         435 :       r->signalling = !quiet;
    2633                 :             :     }
    2634                 :             : 
    2635                 :             :   return true;
    2636                 :             : }
    2637                 :             : 
    2638                 :             : /* Fills R with the largest finite value representable in mode MODE.
    2639                 :             :    If SIGN is nonzero, R is set to the most negative finite value.  */
    2640                 :             : 
    2641                 :             : void
    2642                 :       78390 : real_maxval (REAL_VALUE_TYPE *r, int sign, machine_mode mode)
    2643                 :             : {
    2644                 :       78390 :   const struct real_format *fmt;
    2645                 :       78390 :   int np2;
    2646                 :             : 
    2647                 :       78390 :   fmt = REAL_MODE_FORMAT (mode);
    2648                 :       78390 :   gcc_assert (fmt);
    2649                 :       78390 :   memset (r, 0, sizeof (*r));
    2650                 :             : 
    2651                 :       78390 :   if (fmt->b == 10)
    2652                 :          95 :     decimal_real_maxval (r, sign, mode);
    2653                 :             :   else
    2654                 :             :     {
    2655                 :       78295 :       r->cl = rvc_normal;
    2656                 :       78295 :       r->sign = sign;
    2657                 :       78295 :       SET_REAL_EXP (r, fmt->emax);
    2658                 :             : 
    2659                 :       78295 :       np2 = SIGNIFICAND_BITS - fmt->p;
    2660                 :       78295 :       memset (r->sig, -1, SIGSZ * sizeof (unsigned long));
    2661                 :       78295 :       clear_significand_below (r, np2);
    2662                 :             : 
    2663                 :       78295 :       if (fmt->pnan < fmt->p)
    2664                 :             :         /* This is an IBM extended double format made up of two IEEE
    2665                 :             :            doubles.  The value of the long double is the sum of the
    2666                 :             :            values of the two parts.  The most significant part is
    2667                 :             :            required to be the value of the long double rounded to the
    2668                 :             :            nearest double.  Rounding means we need a slightly smaller
    2669                 :             :            value for LDBL_MAX.  */
    2670                 :           0 :         clear_significand_bit (r, SIGNIFICAND_BITS - fmt->pnan - 1);
    2671                 :             :     }
    2672                 :       78390 : }
    2673                 :             : 
    2674                 :             : /* Fills R with 2**N.  */
    2675                 :             : 
    2676                 :             : void
    2677                 :        6206 : real_2expN (REAL_VALUE_TYPE *r, int n, format_helper fmt)
    2678                 :             : {
    2679                 :        6206 :   memset (r, 0, sizeof (*r));
    2680                 :             : 
    2681                 :        6206 :   n++;
    2682                 :        6206 :   if (n > MAX_EXP)
    2683                 :           0 :     r->cl = rvc_inf;
    2684                 :        6206 :   else if (n < -MAX_EXP)
    2685                 :             :     ;
    2686                 :             :   else
    2687                 :             :     {
    2688                 :        6206 :       r->cl = rvc_normal;
    2689                 :        6206 :       SET_REAL_EXP (r, n);
    2690                 :        6206 :       r->sig[SIGSZ-1] = SIG_MSB;
    2691                 :             :     }
    2692                 :        6206 :   if (fmt.decimal_p ())
    2693                 :           0 :     decimal_real_convert (r, fmt, r);
    2694                 :        6206 : }
    2695                 :             : 
    2696                 :             : 
    2697                 :             : static void
    2698                 :    53261723 : round_for_format (const struct real_format *fmt, REAL_VALUE_TYPE *r)
    2699                 :             : {
    2700                 :    53261723 :   int p2, np2, i, w;
    2701                 :    53261723 :   int emin2m1, emax2;
    2702                 :    53261723 :   bool round_up = false;
    2703                 :             : 
    2704                 :    53261723 :   if (r->decimal)
    2705                 :             :     {
    2706                 :      440249 :       if (fmt->b == 10)
    2707                 :             :         {
    2708                 :      440249 :           decimal_round_for_format (fmt, r);
    2709                 :      440249 :           return;
    2710                 :             :         }
    2711                 :             :       /* FIXME. We can come here via fp_easy_constant
    2712                 :             :          (e.g. -O0 on '_Decimal32 x = 1.0 + 2.0dd'), but have not
    2713                 :             :          investigated whether this convert needs to be here, or
    2714                 :             :          something else is missing. */
    2715                 :           0 :       decimal_real_convert (r, REAL_MODE_FORMAT (DFmode), r);
    2716                 :             :     }
    2717                 :             : 
    2718                 :    52821474 :   p2 = fmt->p;
    2719                 :    52821474 :   emin2m1 = fmt->emin - 1;
    2720                 :    52821474 :   emax2 = fmt->emax;
    2721                 :             : 
    2722                 :    52821474 :   np2 = SIGNIFICAND_BITS - p2;
    2723                 :    52821474 :   switch (r->cl)
    2724                 :             :     {
    2725                 :       29102 :     underflow:
    2726                 :       29102 :       get_zero (r, r->sign);
    2727                 :             :       /* FALLTHRU */
    2728                 :     7748926 :     case rvc_zero:
    2729                 :     7748926 :       if (!fmt->has_signed_zero)
    2730                 :           0 :         r->sign = 0;
    2731                 :             :       return;
    2732                 :             : 
    2733                 :     2496935 :     overflow:
    2734                 :     2496935 :       get_inf (r, r->sign);
    2735                 :             :     case rvc_inf:
    2736                 :             :       return;
    2737                 :             : 
    2738                 :      124938 :     case rvc_nan:
    2739                 :      124938 :       clear_significand_below (r, np2);
    2740                 :      124938 :       return;
    2741                 :             : 
    2742                 :    35675864 :     case rvc_normal:
    2743                 :    35675864 :       break;
    2744                 :             : 
    2745                 :           0 :     default:
    2746                 :           0 :       gcc_unreachable ();
    2747                 :             :     }
    2748                 :             : 
    2749                 :             :   /* Check the range of the exponent.  If we're out of range,
    2750                 :             :      either underflow or overflow.  */
    2751                 :    35675864 :   if (REAL_EXP (r) > emax2)
    2752                 :     2493510 :     goto overflow;
    2753                 :    33182354 :   else if (REAL_EXP (r) <= emin2m1)
    2754                 :             :     {
    2755                 :      380485 :       int diff;
    2756                 :             : 
    2757                 :      380485 :       if (!fmt->has_denorm)
    2758                 :             :         {
    2759                 :             :           /* Don't underflow completely until we've had a chance to round.  */
    2760                 :           0 :           if (REAL_EXP (r) < emin2m1)
    2761                 :           0 :             goto underflow;
    2762                 :             :         }
    2763                 :             :       else
    2764                 :             :         {
    2765                 :      380485 :           diff = emin2m1 - REAL_EXP (r) + 1;
    2766                 :      380485 :           if (diff > p2)
    2767                 :       29102 :             goto underflow;
    2768                 :             : 
    2769                 :             :           /* De-normalize the significand.  */
    2770                 :      351383 :           r->sig[0] |= sticky_rshift_significand (r, r, diff);
    2771                 :      351383 :           SET_REAL_EXP (r, REAL_EXP (r) + diff);
    2772                 :             :         }
    2773                 :             :     }
    2774                 :             : 
    2775                 :    33153252 :   if (!fmt->round_towards_zero)
    2776                 :             :     {
    2777                 :             :       /* There are P2 true significand bits, followed by one guard bit,
    2778                 :             :          followed by one sticky bit, followed by stuff.  Fold nonzero
    2779                 :             :          stuff into the sticky bit.  */
    2780                 :    33153252 :       unsigned long sticky;
    2781                 :    33153252 :       bool guard, lsb;
    2782                 :             : 
    2783                 :    33153252 :       sticky = 0;
    2784                 :    85971856 :       for (i = 0, w = (np2 - 1) / HOST_BITS_PER_LONG; i < w; ++i)
    2785                 :    52818604 :         sticky |= r->sig[i];
    2786                 :    33153252 :       sticky |= r->sig[w]
    2787                 :    33153252 :                 & (((unsigned long)1 << ((np2 - 1) % HOST_BITS_PER_LONG)) - 1);
    2788                 :             : 
    2789                 :    33153252 :       guard = test_significand_bit (r, np2 - 1);
    2790                 :    33153252 :       lsb = test_significand_bit (r, np2);
    2791                 :             : 
    2792                 :             :       /* Round to even.  */
    2793                 :    33153252 :       round_up = guard && (sticky || lsb);
    2794                 :             :     }
    2795                 :             : 
    2796                 :     2664318 :   if (round_up)
    2797                 :             :     {
    2798                 :     2664318 :       REAL_VALUE_TYPE u;
    2799                 :     2664318 :       get_zero (&u, 0);
    2800                 :     2664318 :       set_significand_bit (&u, np2);
    2801                 :             : 
    2802                 :     2664318 :       if (add_significands (r, r, &u))
    2803                 :             :         {
    2804                 :             :           /* Overflow.  Means the significand had been all ones, and
    2805                 :             :              is now all zeros.  Need to increase the exponent, and
    2806                 :             :              possibly re-normalize it.  */
    2807                 :      195695 :           SET_REAL_EXP (r, REAL_EXP (r) + 1);
    2808                 :      195695 :           if (REAL_EXP (r) > emax2)
    2809                 :        3425 :             goto overflow;
    2810                 :      192270 :           r->sig[SIGSZ-1] = SIG_MSB;
    2811                 :             :         }
    2812                 :             :     }
    2813                 :             : 
    2814                 :             :   /* Catch underflow that we deferred until after rounding.  */
    2815                 :    33149827 :   if (REAL_EXP (r) <= emin2m1)
    2816                 :           0 :     goto underflow;
    2817                 :             : 
    2818                 :             :   /* Clear out trailing garbage.  */
    2819                 :    33149827 :   clear_significand_below (r, np2);
    2820                 :             : }
    2821                 :             : 
    2822                 :             : /* Extend or truncate to a new format.  */
    2823                 :             : 
    2824                 :             : void
    2825                 :    50977857 : real_convert (REAL_VALUE_TYPE *r, format_helper fmt,
    2826                 :             :               const REAL_VALUE_TYPE *a)
    2827                 :             : {
    2828                 :    50977857 :   *r = *a;
    2829                 :             : 
    2830                 :    50977857 :   if (a->decimal || fmt->b == 10)
    2831                 :      398574 :     decimal_real_convert (r, fmt, a);
    2832                 :             : 
    2833                 :    50977857 :   round_for_format (fmt, r);
    2834                 :             : 
    2835                 :             :   /* Make resulting NaN value to be qNaN. The caller has the
    2836                 :             :      responsibility to avoid the operation if flag_signaling_nans
    2837                 :             :      is on.  */
    2838                 :    50977857 :   if (r->cl == rvc_nan)
    2839                 :       38918 :     r->signalling = 0;
    2840                 :             : 
    2841                 :             :   /* round_for_format de-normalizes denormals.  Undo just that part.  */
    2842                 :    50977857 :   if (r->cl == rvc_normal)
    2843                 :    31975020 :     normalize (r);
    2844                 :    50977857 : }
    2845                 :             : 
    2846                 :             : /* Legacy.  Likewise, except return the struct directly.  */
    2847                 :             : 
    2848                 :             : REAL_VALUE_TYPE
    2849                 :      269650 : real_value_truncate (format_helper fmt, REAL_VALUE_TYPE a)
    2850                 :             : {
    2851                 :      269650 :   REAL_VALUE_TYPE r;
    2852                 :      269650 :   real_convert (&r, fmt, &a);
    2853                 :      269650 :   return r;
    2854                 :             : }
    2855                 :             : 
    2856                 :             : /* Return true if truncating to FMT is exact.  */
    2857                 :             : 
    2858                 :             : bool
    2859                 :     2818788 : exact_real_truncate (format_helper fmt, const REAL_VALUE_TYPE *a)
    2860                 :             : {
    2861                 :     2818788 :   REAL_VALUE_TYPE t;
    2862                 :     2818788 :   int emin2m1;
    2863                 :             : 
    2864                 :             :   /* Don't allow conversion to denormals.  */
    2865                 :     2818788 :   emin2m1 = fmt->emin - 1;
    2866                 :     2818788 :   if (REAL_EXP (a) <= emin2m1)
    2867                 :             :     return false;
    2868                 :             : 
    2869                 :             :   /* After conversion to the new format, the value must be identical.  */
    2870                 :     2461120 :   real_convert (&t, fmt, a);
    2871                 :     2461120 :   return real_identical (&t, a);
    2872                 :             : }
    2873                 :             : 
    2874                 :             : /* Write R to the given target format.  Place the words of the result
    2875                 :             :    in target word order in BUF.  There are always 32 bits in each
    2876                 :             :    long, no matter the size of the host long.
    2877                 :             : 
    2878                 :             :    Legacy: return word 0 for implementing REAL_VALUE_TO_TARGET_SINGLE.  */
    2879                 :             : 
    2880                 :             : long
    2881                 :     2283866 : real_to_target (long *buf, const REAL_VALUE_TYPE *r_orig,
    2882                 :             :                 format_helper fmt)
    2883                 :             : {
    2884                 :     2283866 :   REAL_VALUE_TYPE r;
    2885                 :     2283866 :   long buf1;
    2886                 :             : 
    2887                 :     2283866 :   r = *r_orig;
    2888                 :     2283866 :   round_for_format (fmt, &r);
    2889                 :             : 
    2890                 :     2283866 :   if (!buf)
    2891                 :      194260 :     buf = &buf1;
    2892                 :     2283866 :   (*fmt->encode) (fmt, buf, &r);
    2893                 :             : 
    2894                 :     2283866 :   return *buf;
    2895                 :             : }
    2896                 :             : 
    2897                 :             : /* Read R from the given target format.  Read the words of the result
    2898                 :             :    in target word order in BUF.  There are always 32 bits in each
    2899                 :             :    long, no matter the size of the host long.  */
    2900                 :             : 
    2901                 :             : void
    2902                 :      210514 : real_from_target (REAL_VALUE_TYPE *r, const long *buf, format_helper fmt)
    2903                 :             : {
    2904                 :      210514 :   (*fmt->decode) (fmt, r, buf);
    2905                 :      210514 : }
    2906                 :             : 
    2907                 :             : /* Return the number of bits of the largest binary value that the
    2908                 :             :    significand of FMT will hold.  */
    2909                 :             : /* ??? Legacy.  Should get access to real_format directly.  */
    2910                 :             : 
    2911                 :             : int
    2912                 :      144863 : significand_size (format_helper fmt)
    2913                 :             : {
    2914                 :      144863 :   if (fmt == NULL)
    2915                 :             :     return 0;
    2916                 :             : 
    2917                 :      144863 :   if (fmt->b == 10)
    2918                 :             :     {
    2919                 :             :       /* Return the size in bits of the largest binary value that can be
    2920                 :             :          held by the decimal coefficient for this format.  This is one more
    2921                 :             :          than the number of bits required to hold the largest coefficient
    2922                 :             :          of this format.  */
    2923                 :        9060 :       double log2_10 = 3.3219281;
    2924                 :        9060 :       return fmt->p * log2_10;
    2925                 :             :     }
    2926                 :      135803 :   return fmt->p;
    2927                 :             : }
    2928                 :             : 
    2929                 :             : /* Return a hash value for the given real value.  */
    2930                 :             : /* ??? The "unsigned int" return value is intended to be hashval_t,
    2931                 :             :    but I didn't want to pull hashtab.h into real.h.  */
    2932                 :             : 
    2933                 :             : unsigned int
    2934                 :    43380406 : real_hash (const REAL_VALUE_TYPE *r)
    2935                 :             : {
    2936                 :    43380406 :   unsigned int h;
    2937                 :    43380406 :   size_t i;
    2938                 :             : 
    2939                 :    43380406 :   h = r->cl | (r->sign << 2);
    2940                 :    43380406 :   switch (r->cl)
    2941                 :             :     {
    2942                 :             :     case rvc_zero:
    2943                 :             :     case rvc_inf:
    2944                 :             :       return h;
    2945                 :             : 
    2946                 :    29872619 :     case rvc_normal:
    2947                 :    29872619 :       h |= (unsigned int)REAL_EXP (r) << 3;
    2948                 :    29872619 :       break;
    2949                 :             : 
    2950                 :      423914 :     case rvc_nan:
    2951                 :      423914 :       if (r->signalling)
    2952                 :        8202 :         h ^= (unsigned int)-1;
    2953                 :      423914 :       if (r->canonical)
    2954                 :             :         return h;
    2955                 :             :       break;
    2956                 :             : 
    2957                 :           0 :     default:
    2958                 :           0 :       gcc_unreachable ();
    2959                 :             :     }
    2960                 :             : 
    2961                 :             :   if (sizeof (unsigned long) > sizeof (unsigned int))
    2962                 :   120537548 :     for (i = 0; i < SIGSZ; ++i)
    2963                 :             :       {
    2964                 :    90403161 :         unsigned long s = r->sig[i];
    2965                 :    90403161 :         h ^= s ^ (s >> (HOST_BITS_PER_LONG / 2));
    2966                 :             :       }
    2967                 :             :   else
    2968                 :             :     for (i = 0; i < SIGSZ; ++i)
    2969                 :             :       h ^= r->sig[i];
    2970                 :             : 
    2971                 :             :   return h;
    2972                 :             : }
    2973                 :             : 
    2974                 :             : /* IEEE single-precision format.  */
    2975                 :             : 
    2976                 :             : static void encode_ieee_single (const struct real_format *fmt,
    2977                 :             :                                 long *, const REAL_VALUE_TYPE *);
    2978                 :             : static void decode_ieee_single (const struct real_format *,
    2979                 :             :                                 REAL_VALUE_TYPE *, const long *);
    2980                 :             : 
    2981                 :             : static void
    2982                 :     1141717 : encode_ieee_single (const struct real_format *fmt, long *buf,
    2983                 :             :                     const REAL_VALUE_TYPE *r)
    2984                 :             : {
    2985                 :     1141717 :   unsigned long image, sig, exp;
    2986                 :     1141717 :   unsigned long sign = r->sign;
    2987                 :             : 
    2988                 :     1141717 :   image = sign << 31;
    2989                 :     1141717 :   sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 24)) & 0x7fffff;
    2990                 :             : 
    2991                 :     1141717 :   switch (r->cl)
    2992                 :             :     {
    2993                 :             :     case rvc_zero:
    2994                 :             :       break;
    2995                 :             : 
    2996                 :        7336 :     case rvc_inf:
    2997                 :        7336 :       if (fmt->has_inf)
    2998                 :        7336 :         image |= 255 << 23;
    2999                 :             :       else
    3000                 :           0 :         image |= 0x7fffffff;
    3001                 :             :       break;
    3002                 :             : 
    3003                 :       38364 :     case rvc_nan:
    3004                 :       38364 :       if (fmt->has_nans)
    3005                 :             :         {
    3006                 :       38364 :           if (r->canonical)
    3007                 :        2713 :             sig = (fmt->canonical_nan_lsbs_set ? (1 << 22) - 1 : 0);
    3008                 :       38364 :           if (r->signalling == fmt->qnan_msb_set)
    3009                 :         213 :             sig &= ~(1 << 22);
    3010                 :             :           else
    3011                 :       38151 :             sig |= 1 << 22;
    3012                 :       38364 :           if (sig == 0)
    3013                 :         203 :             sig = 1 << 21;
    3014                 :             : 
    3015                 :       38364 :           image |= 255 << 23;
    3016                 :       38364 :           image |= sig;
    3017                 :             :         }
    3018                 :             :       else
    3019                 :           0 :         image |= 0x7fffffff;
    3020                 :             :       break;
    3021                 :             : 
    3022                 :      877296 :     case rvc_normal:
    3023                 :             :       /* Recall that IEEE numbers are interpreted as 1.F x 2**exp,
    3024                 :             :          whereas the intermediate representation is 0.F x 2**exp.
    3025                 :             :          Which means we're off by one.  */
    3026                 :      877296 :       if (real_isdenormal (r))
    3027                 :             :         exp = 0;
    3028                 :             :       else
    3029                 :      870339 :       exp = REAL_EXP (r) + 127 - 1;
    3030                 :      877296 :       image |= exp << 23;
    3031                 :      877296 :       image |= sig;
    3032                 :      877296 :       break;
    3033                 :             : 
    3034                 :           0 :     default:
    3035                 :           0 :       gcc_unreachable ();
    3036                 :             :     }
    3037                 :             : 
    3038                 :     1141717 :   buf[0] = image;
    3039                 :     1141717 : }
    3040                 :             : 
    3041                 :             : static void
    3042                 :       95724 : decode_ieee_single (const struct real_format *fmt, REAL_VALUE_TYPE *r,
    3043                 :             :                     const long *buf)
    3044                 :             : {
    3045                 :       95724 :   unsigned long image = buf[0] & 0xffffffff;
    3046                 :       95724 :   bool sign = (image >> 31) & 1;
    3047                 :       95724 :   int exp = (image >> 23) & 0xff;
    3048                 :             : 
    3049                 :       95724 :   memset (r, 0, sizeof (*r));
    3050                 :       95724 :   image <<= HOST_BITS_PER_LONG - 24;
    3051                 :       95724 :   image &= ~SIG_MSB;
    3052                 :             : 
    3053                 :       95724 :   if (exp == 0)
    3054                 :             :     {
    3055                 :       41014 :       if (image && fmt->has_denorm)
    3056                 :             :         {
    3057                 :        5147 :           r->cl = rvc_normal;
    3058                 :        5147 :           r->sign = sign;
    3059                 :        5147 :           SET_REAL_EXP (r, -126);
    3060                 :        5147 :           r->sig[SIGSZ-1] = image << 1;
    3061                 :        5147 :           normalize (r);
    3062                 :             :         }
    3063                 :       35867 :       else if (fmt->has_signed_zero)
    3064                 :       35867 :         r->sign = sign;
    3065                 :             :     }
    3066                 :       54710 :   else if (exp == 255 && (fmt->has_nans || fmt->has_inf))
    3067                 :             :     {
    3068                 :       30045 :       if (image)
    3069                 :             :         {
    3070                 :       29687 :           r->cl = rvc_nan;
    3071                 :       29687 :           r->sign = sign;
    3072                 :       29687 :           r->signalling = (((image >> (HOST_BITS_PER_LONG - 2)) & 1)
    3073                 :       29687 :                            ^ fmt->qnan_msb_set);
    3074                 :       29687 :           r->sig[SIGSZ-1] = image;
    3075                 :             :         }
    3076                 :             :       else
    3077                 :             :         {
    3078                 :         358 :           r->cl = rvc_inf;
    3079                 :         358 :           r->sign = sign;
    3080                 :             :         }
    3081                 :             :     }
    3082                 :             :   else
    3083                 :             :     {
    3084                 :       24665 :       r->cl = rvc_normal;
    3085                 :       24665 :       r->sign = sign;
    3086                 :       24665 :       SET_REAL_EXP (r, exp - 127 + 1);
    3087                 :       24665 :       r->sig[SIGSZ-1] = image | SIG_MSB;
    3088                 :             :     }
    3089                 :       95724 : }
    3090                 :             : 
    3091                 :             : const struct real_format ieee_single_format =
    3092                 :             :   {
    3093                 :             :     encode_ieee_single,
    3094                 :             :     decode_ieee_single,
    3095                 :             :     2,
    3096                 :             :     24,
    3097                 :             :     24,
    3098                 :             :     -125,
    3099                 :             :     128,
    3100                 :             :     31,
    3101                 :             :     31,
    3102                 :             :     32,
    3103                 :             :     false,
    3104                 :             :     true,
    3105                 :             :     true,
    3106                 :             :     true,
    3107                 :             :     true,
    3108                 :             :     true,
    3109                 :             :     true,
    3110                 :             :     false,
    3111                 :             :     "ieee_single"
    3112                 :             :   };
    3113                 :             : 
    3114                 :             : const struct real_format mips_single_format =
    3115                 :             :   {
    3116                 :             :     encode_ieee_single,
    3117                 :             :     decode_ieee_single,
    3118                 :             :     2,
    3119                 :             :     24,
    3120                 :             :     24,
    3121                 :             :     -125,
    3122                 :             :     128,
    3123                 :             :     31,
    3124                 :             :     31,
    3125                 :             :     32,
    3126                 :             :     false,
    3127                 :             :     true,
    3128                 :             :     true,
    3129                 :             :     true,
    3130                 :             :     true,
    3131                 :             :     true,
    3132                 :             :     false,
    3133                 :             :     true,
    3134                 :             :     "mips_single"
    3135                 :             :   };
    3136                 :             : 
    3137                 :             : const struct real_format motorola_single_format =
    3138                 :             :   {
    3139                 :             :     encode_ieee_single,
    3140                 :             :     decode_ieee_single,
    3141                 :             :     2,
    3142                 :             :     24,
    3143                 :             :     24,
    3144                 :             :     -125,
    3145                 :             :     128,
    3146                 :             :     31,
    3147                 :             :     31,
    3148                 :             :     32,
    3149                 :             :     false,
    3150                 :             :     true,
    3151                 :             :     true,
    3152                 :             :     true,
    3153                 :             :     true,
    3154                 :             :     true,
    3155                 :             :     true,
    3156                 :             :     true,
    3157                 :             :     "motorola_single"
    3158                 :             :   };
    3159                 :             : 
    3160                 :             : /*  SPU Single Precision (Extended-Range Mode) format is the same as IEEE
    3161                 :             :     single precision with the following differences:
    3162                 :             :       - Infinities are not supported.  Instead MAX_FLOAT or MIN_FLOAT
    3163                 :             :         are generated.
    3164                 :             :       - NaNs are not supported.
    3165                 :             :       - The range of non-zero numbers in binary is
    3166                 :             :         (001)[1.]000...000 to (255)[1.]111...111.
    3167                 :             :       - Denormals can be represented, but are treated as +0.0 when
    3168                 :             :         used as an operand and are never generated as a result.
    3169                 :             :       - -0.0 can be represented, but a zero result is always +0.0.
    3170                 :             :       - the only supported rounding mode is trunction (towards zero).  */
    3171                 :             : const struct real_format spu_single_format =
    3172                 :             :   {
    3173                 :             :     encode_ieee_single,
    3174                 :             :     decode_ieee_single,
    3175                 :             :     2,
    3176                 :             :     24,
    3177                 :             :     24,
    3178                 :             :     -125,
    3179                 :             :     129,
    3180                 :             :     31,
    3181                 :             :     31,
    3182                 :             :     0,
    3183                 :             :     true,
    3184                 :             :     false,
    3185                 :             :     false,
    3186                 :             :     false,
    3187                 :             :     true,
    3188                 :             :     true,
    3189                 :             :     false,
    3190                 :             :     false,
    3191                 :             :     "spu_single"
    3192                 :             :   };
    3193                 :             : 
    3194                 :             : /* IEEE double-precision format.  */
    3195                 :             : 
    3196                 :             : static void encode_ieee_double (const struct real_format *fmt,
    3197                 :             :                                 long *, const REAL_VALUE_TYPE *);
    3198                 :             : static void decode_ieee_double (const struct real_format *,
    3199                 :             :                                 REAL_VALUE_TYPE *, const long *);
    3200                 :             : 
    3201                 :             : static void
    3202                 :      870797 : encode_ieee_double (const struct real_format *fmt, long *buf,
    3203                 :             :                     const REAL_VALUE_TYPE *r)
    3204                 :             : {
    3205                 :      870797 :   unsigned long image_lo, image_hi, sig_lo, sig_hi, exp;
    3206                 :      870797 :   unsigned long sign = r->sign;
    3207                 :             : 
    3208                 :      870797 :   image_hi = sign << 31;
    3209                 :      870797 :   image_lo = 0;
    3210                 :             : 
    3211                 :      870797 :   if (HOST_BITS_PER_LONG == 64)
    3212                 :             :     {
    3213                 :      870797 :       sig_hi = r->sig[SIGSZ-1];
    3214                 :      870797 :       sig_lo = (sig_hi >> (64 - 53)) & 0xffffffff;
    3215                 :      870797 :       sig_hi = (sig_hi >> (64 - 53 + 1) >> 31) & 0xfffff;
    3216                 :             :     }
    3217                 :             :   else
    3218                 :             :     {
    3219                 :             :       sig_hi = r->sig[SIGSZ-1];
    3220                 :             :       sig_lo = r->sig[SIGSZ-2];
    3221                 :             :       sig_lo = (sig_hi << 21) | (sig_lo >> 11);
    3222                 :             :       sig_hi = (sig_hi >> 11) & 0xfffff;
    3223                 :             :     }
    3224                 :             : 
    3225                 :      870797 :   switch (r->cl)
    3226                 :             :     {
    3227                 :             :     case rvc_zero:
    3228                 :             :       break;
    3229                 :             : 
    3230                 :        9111 :     case rvc_inf:
    3231                 :        9111 :       if (fmt->has_inf)
    3232                 :        9111 :         image_hi |= 2047 << 20;
    3233                 :             :       else
    3234                 :             :         {
    3235                 :           0 :           image_hi |= 0x7fffffff;
    3236                 :           0 :           image_lo = 0xffffffff;
    3237                 :             :         }
    3238                 :             :       break;
    3239                 :             : 
    3240                 :       41744 :     case rvc_nan:
    3241                 :       41744 :       if (fmt->has_nans)
    3242                 :             :         {
    3243                 :       41744 :           if (r->canonical)
    3244                 :             :             {
    3245                 :        2193 :               if (fmt->canonical_nan_lsbs_set)
    3246                 :             :                 {
    3247                 :             :                   sig_hi = (1 << 19) - 1;
    3248                 :             :                   sig_lo = 0xffffffff;
    3249                 :             :                 }
    3250                 :             :               else
    3251                 :             :                 {
    3252                 :        2193 :                   sig_hi = 0;
    3253                 :        2193 :                   sig_lo = 0;
    3254                 :             :                 }
    3255                 :             :             }
    3256                 :       41744 :           if (r->signalling == fmt->qnan_msb_set)
    3257                 :         271 :             sig_hi &= ~(1 << 19);
    3258                 :             :           else
    3259                 :       41473 :             sig_hi |= 1 << 19;
    3260                 :       41744 :           if (sig_hi == 0 && sig_lo == 0)
    3261                 :         266 :             sig_hi = 1 << 18;
    3262                 :             : 
    3263                 :       41744 :           image_hi |= 2047 << 20;
    3264                 :       41744 :           image_hi |= sig_hi;
    3265                 :       41744 :           image_lo = sig_lo;
    3266                 :             :         }
    3267                 :             :       else
    3268                 :             :         {
    3269                 :           0 :           image_hi |= 0x7fffffff;
    3270                 :           0 :           image_lo = 0xffffffff;
    3271                 :             :         }
    3272                 :             :       break;
    3273                 :             : 
    3274                 :      507919 :     case rvc_normal:
    3275                 :             :       /* Recall that IEEE numbers are interpreted as 1.F x 2**exp,
    3276                 :             :          whereas the intermediate representation is 0.F x 2**exp.
    3277                 :             :          Which means we're off by one.  */
    3278                 :      507919 :       if (real_isdenormal (r))
    3279                 :             :         exp = 0;
    3280                 :             :       else
    3281                 :      503024 :         exp = REAL_EXP (r) + 1023 - 1;
    3282                 :      507919 :       image_hi |= exp << 20;
    3283                 :      507919 :       image_hi |= sig_hi;
    3284                 :      507919 :       image_lo = sig_lo;
    3285                 :      507919 :       break;
    3286                 :             : 
    3287                 :           0 :     default:
    3288                 :           0 :       gcc_unreachable ();
    3289                 :             :     }
    3290                 :             : 
    3291                 :      870797 :   if (FLOAT_WORDS_BIG_ENDIAN)
    3292                 :             :     buf[0] = image_hi, buf[1] = image_lo;
    3293                 :             :   else
    3294                 :      870797 :     buf[0] = image_lo, buf[1] = image_hi;
    3295                 :      870797 : }
    3296                 :             : 
    3297                 :             : static void
    3298                 :       85595 : decode_ieee_double (const struct real_format *fmt, REAL_VALUE_TYPE *r,
    3299                 :             :                     const long *buf)
    3300                 :             : {
    3301                 :       85595 :   unsigned long image_hi, image_lo;
    3302                 :       85595 :   bool sign;
    3303                 :       85595 :   int exp;
    3304                 :             : 
    3305                 :       85595 :   if (FLOAT_WORDS_BIG_ENDIAN)
    3306                 :             :     image_hi = buf[0], image_lo = buf[1];
    3307                 :             :   else
    3308                 :       85595 :     image_lo = buf[0], image_hi = buf[1];
    3309                 :       85595 :   image_lo &= 0xffffffff;
    3310                 :       85595 :   image_hi &= 0xffffffff;
    3311                 :             : 
    3312                 :       85595 :   sign = (image_hi >> 31) & 1;
    3313                 :       85595 :   exp = (image_hi >> 20) & 0x7ff;
    3314                 :             : 
    3315                 :       85595 :   memset (r, 0, sizeof (*r));
    3316                 :             : 
    3317                 :       85595 :   image_hi <<= 32 - 21;
    3318                 :       85595 :   image_hi |= image_lo >> 21;
    3319                 :       85595 :   image_hi &= 0x7fffffff;
    3320                 :       85595 :   image_lo <<= 32 - 21;
    3321                 :             : 
    3322                 :       85595 :   if (exp == 0)
    3323                 :             :     {
    3324                 :       36792 :       if ((image_hi || image_lo) && fmt->has_denorm)
    3325                 :             :         {
    3326                 :        2979 :           r->cl = rvc_normal;
    3327                 :        2979 :           r->sign = sign;
    3328                 :        2979 :           SET_REAL_EXP (r, -1022);
    3329                 :        2979 :           if (HOST_BITS_PER_LONG == 32)
    3330                 :             :             {
    3331                 :             :               image_hi = (image_hi << 1) | (image_lo >> 31);
    3332                 :             :               image_lo <<= 1;
    3333                 :             :               r->sig[SIGSZ-1] = image_hi;
    3334                 :             :               r->sig[SIGSZ-2] = image_lo;
    3335                 :             :             }
    3336                 :             :           else
    3337                 :             :             {
    3338                 :        2979 :               image_hi = (image_hi << 31 << 2) | (image_lo << 1);
    3339                 :        2979 :               r->sig[SIGSZ-1] = image_hi;
    3340                 :             :             }
    3341                 :        2979 :           normalize (r);
    3342                 :             :         }
    3343                 :       33813 :       else if (fmt->has_signed_zero)
    3344                 :       33813 :         r->sign = sign;
    3345                 :             :     }
    3346                 :       48803 :   else if (exp == 2047 && (fmt->has_nans || fmt->has_inf))
    3347                 :             :     {
    3348                 :       30934 :       if (image_hi || image_lo)
    3349                 :             :         {
    3350                 :       29550 :           r->cl = rvc_nan;
    3351                 :       29550 :           r->sign = sign;
    3352                 :       29550 :           r->signalling = ((image_hi >> 30) & 1) ^ fmt->qnan_msb_set;
    3353                 :       29550 :           if (HOST_BITS_PER_LONG == 32)
    3354                 :             :             {
    3355                 :             :               r->sig[SIGSZ-1] = image_hi;
    3356                 :             :               r->sig[SIGSZ-2] = image_lo;
    3357                 :             :             }
    3358                 :             :           else
    3359                 :       29550 :             r->sig[SIGSZ-1] = (image_hi << 31 << 1) | image_lo;
    3360                 :             :         }
    3361                 :             :       else
    3362                 :             :         {
    3363                 :        1384 :           r->cl = rvc_inf;
    3364                 :        1384 :           r->sign = sign;
    3365                 :             :         }
    3366                 :             :     }
    3367                 :             :   else
    3368                 :             :     {
    3369                 :       17869 :       r->cl = rvc_normal;
    3370                 :       17869 :       r->sign = sign;
    3371                 :       17869 :       SET_REAL_EXP (r, exp - 1023 + 1);
    3372                 :       17869 :       if (HOST_BITS_PER_LONG == 32)
    3373                 :             :         {
    3374                 :             :           r->sig[SIGSZ-1] = image_hi | SIG_MSB;
    3375                 :             :           r->sig[SIGSZ-2] = image_lo;
    3376                 :             :         }
    3377                 :             :       else
    3378                 :       17869 :         r->sig[SIGSZ-1] = (image_hi << 31 << 1) | image_lo | SIG_MSB;
    3379                 :             :     }
    3380                 :       85595 : }
    3381                 :             : 
    3382                 :             : const struct real_format ieee_double_format =
    3383                 :             :   {
    3384                 :             :     encode_ieee_double,
    3385                 :             :     decode_ieee_double,
    3386                 :             :     2,
    3387                 :             :     53,
    3388                 :             :     53,
    3389                 :             :     -1021,
    3390                 :             :     1024,
    3391                 :             :     63,
    3392                 :             :     63,
    3393                 :             :     64,
    3394                 :             :     false,
    3395                 :             :     true,
    3396                 :             :     true,
    3397                 :             :     true,
    3398                 :             :     true,
    3399                 :             :     true,
    3400                 :             :     true,
    3401                 :             :     false,
    3402                 :             :     "ieee_double"
    3403                 :             :   };
    3404                 :             : 
    3405                 :             : const struct real_format mips_double_format =
    3406                 :             :   {
    3407                 :             :     encode_ieee_double,
    3408                 :             :     decode_ieee_double,
    3409                 :             :     2,
    3410                 :             :     53,
    3411                 :             :     53,
    3412                 :             :     -1021,
    3413                 :             :     1024,
    3414                 :             :     63,
    3415                 :             :     63,
    3416                 :             :     64,
    3417                 :             :     false,
    3418                 :             :     true,
    3419                 :             :     true,
    3420                 :             :     true,
    3421                 :             :     true,
    3422                 :             :     true,
    3423                 :             :     false,
    3424                 :             :     true,
    3425                 :             :     "mips_double"
    3426                 :             :   };
    3427                 :             : 
    3428                 :             : const struct real_format motorola_double_format =
    3429                 :             :   {
    3430                 :             :     encode_ieee_double,
    3431                 :             :     decode_ieee_double,
    3432                 :             :     2,
    3433                 :             :     53,
    3434                 :             :     53,
    3435                 :             :     -1021,
    3436                 :             :     1024,
    3437                 :             :     63,
    3438                 :             :     63,
    3439                 :             :     64,
    3440                 :             :     false,
    3441                 :             :     true,
    3442                 :             :     true,
    3443                 :             :     true,
    3444                 :             :     true,
    3445                 :             :     true,
    3446                 :             :     true,
    3447                 :             :     true,
    3448                 :             :     "motorola_double"
    3449                 :             :   };
    3450                 :             : 
    3451                 :             : /* IEEE extended real format.  This comes in three flavors: Intel's as
    3452                 :             :    a 12 byte image, Intel's as a 16 byte image, and Motorola's.  Intel
    3453                 :             :    12- and 16-byte images may be big- or little endian; Motorola's is
    3454                 :             :    always big endian.  */
    3455                 :             : 
    3456                 :             : /* Helper subroutine which converts from the internal format to the
    3457                 :             :    12-byte little-endian Intel format.  Functions below adjust this
    3458                 :             :    for the other possible formats.  */
    3459                 :             : static void
    3460                 :       55268 : encode_ieee_extended (const struct real_format *fmt, long *buf,
    3461                 :             :                       const REAL_VALUE_TYPE *r)
    3462                 :             : {
    3463                 :       55268 :   unsigned long image_hi, sig_hi, sig_lo;
    3464                 :             : 
    3465                 :       55268 :   image_hi = r->sign << 15;
    3466                 :       55268 :   sig_hi = sig_lo = 0;
    3467                 :             : 
    3468                 :       55268 :   switch (r->cl)
    3469                 :             :     {
    3470                 :             :     case rvc_zero:
    3471                 :             :       break;
    3472                 :             : 
    3473                 :        1045 :     case rvc_inf:
    3474                 :        1045 :       if (fmt->has_inf)
    3475                 :             :         {
    3476                 :        1045 :           image_hi |= 32767;
    3477                 :             : 
    3478                 :             :           /* Intel requires the explicit integer bit to be set, otherwise
    3479                 :             :              it considers the value a "pseudo-infinity".  Motorola docs
    3480                 :             :              say it doesn't care.  */
    3481                 :        1045 :           sig_hi = 0x80000000;
    3482                 :             :         }
    3483                 :             :       else
    3484                 :             :         {
    3485                 :           0 :           image_hi |= 32767;
    3486                 :           0 :           sig_lo = sig_hi = 0xffffffff;
    3487                 :             :         }
    3488                 :             :       break;
    3489                 :             : 
    3490                 :        2187 :     case rvc_nan:
    3491                 :        2187 :       if (fmt->has_nans)
    3492                 :             :         {
    3493                 :        2187 :           image_hi |= 32767;
    3494                 :        2187 :           if (r->canonical)
    3495                 :             :             {
    3496                 :         894 :               if (fmt->canonical_nan_lsbs_set)
    3497                 :             :                 {
    3498                 :           0 :                   sig_hi = (1 << 30) - 1;
    3499                 :           0 :                   sig_lo = 0xffffffff;
    3500                 :             :                 }
    3501                 :             :             }
    3502                 :        1293 :           else if (HOST_BITS_PER_LONG == 32)
    3503                 :             :             {
    3504                 :             :               sig_hi = r->sig[SIGSZ-1];
    3505                 :             :               sig_lo = r->sig[SIGSZ-2];
    3506                 :             :             }
    3507                 :             :           else
    3508                 :             :             {
    3509                 :        1293 :               sig_lo = r->sig[SIGSZ-1];
    3510                 :        1293 :               sig_hi = sig_lo >> 31 >> 1;
    3511                 :        1293 :               sig_lo &= 0xffffffff;
    3512                 :             :             }
    3513                 :        2187 :           if (r->signalling == fmt->qnan_msb_set)
    3514                 :         148 :             sig_hi &= ~(1 << 30);
    3515                 :             :           else
    3516                 :        2039 :             sig_hi |= 1 << 30;
    3517                 :        2187 :           if ((sig_hi & 0x7fffffff) == 0 && sig_lo == 0)
    3518                 :         146 :             sig_hi = 1 << 29;
    3519                 :             : 
    3520                 :             :           /* Intel requires the explicit integer bit to be set, otherwise
    3521                 :             :              it considers the value a "pseudo-nan".  Motorola docs say it
    3522                 :             :              doesn't care.  */
    3523                 :        2187 :           sig_hi |= 0x80000000;
    3524                 :             :         }
    3525                 :             :       else
    3526                 :             :         {
    3527                 :           0 :           image_hi |= 32767;
    3528                 :           0 :           sig_lo = sig_hi = 0xffffffff;
    3529                 :             :         }
    3530                 :             :       break;
    3531                 :             : 
    3532                 :       42292 :     case rvc_normal:
    3533                 :       42292 :       {
    3534                 :       42292 :         int exp = REAL_EXP (r);
    3535                 :             : 
    3536                 :             :         /* Recall that IEEE numbers are interpreted as 1.F x 2**exp,
    3537                 :             :            whereas the intermediate representation is 0.F x 2**exp.
    3538                 :             :            Which means we're off by one.
    3539                 :             : 
    3540                 :             :            Except for Motorola, which consider exp=0 and explicit
    3541                 :             :            integer bit set to continue to be normalized.  In theory
    3542                 :             :            this discrepancy has been taken care of by the difference
    3543                 :             :            in fmt->emin in round_for_format.  */
    3544                 :             : 
    3545                 :       42292 :         if (real_isdenormal (r))
    3546                 :             :           exp = 0;
    3547                 :             :         else
    3548                 :             :           {
    3549                 :       42018 :             exp += 16383 - 1;
    3550                 :       42018 :             gcc_assert (exp >= 0);
    3551                 :             :           }
    3552                 :       42292 :         image_hi |= exp;
    3553                 :             : 
    3554                 :       42292 :         if (HOST_BITS_PER_LONG == 32)
    3555                 :             :           {
    3556                 :             :             sig_hi = r->sig[SIGSZ-1];
    3557                 :             :             sig_lo = r->sig[SIGSZ-2];
    3558                 :             :           }
    3559                 :             :         else
    3560                 :             :           {
    3561                 :       42292 :             sig_lo = r->sig[SIGSZ-1];
    3562                 :       42292 :             sig_hi = sig_lo >> 31 >> 1;
    3563                 :       42292 :             sig_lo &= 0xffffffff;
    3564                 :             :           }
    3565                 :             :       }
    3566                 :       42292 :       break;
    3567                 :             : 
    3568                 :           0 :     default:
    3569                 :           0 :       gcc_unreachable ();
    3570                 :             :     }
    3571                 :             : 
    3572                 :       55268 :   buf[0] = sig_lo, buf[1] = sig_hi, buf[2] = image_hi;
    3573                 :       55268 : }
    3574                 :             : 
    3575                 :             : /* Convert from the internal format to the 12-byte Motorola format
    3576                 :             :    for an IEEE extended real.  */
    3577                 :             : static void
    3578                 :           0 : encode_ieee_extended_motorola (const struct real_format *fmt, long *buf,
    3579                 :             :                                const REAL_VALUE_TYPE *r)
    3580                 :             : {
    3581                 :           0 :   long intermed[3];
    3582                 :           0 :   encode_ieee_extended (fmt, intermed, r);
    3583                 :             : 
    3584                 :           0 :   if (r->cl == rvc_inf)
    3585                 :             :     /* For infinity clear the explicit integer bit again, so that the
    3586                 :             :        format matches the canonical infinity generated by the FPU.  */
    3587                 :           0 :     intermed[1] = 0;
    3588                 :             : 
    3589                 :             :   /* Motorola chips are assumed always to be big-endian.  Also, the
    3590                 :             :      padding in a Motorola extended real goes between the exponent and
    3591                 :             :      the mantissa.  At this point the mantissa is entirely within
    3592                 :             :      elements 0 and 1 of intermed, and the exponent entirely within
    3593                 :             :      element 2, so all we have to do is swap the order around, and
    3594                 :             :      shift element 2 left 16 bits.  */
    3595                 :           0 :   buf[0] = intermed[2] << 16;
    3596                 :           0 :   buf[1] = intermed[1];
    3597                 :           0 :   buf[2] = intermed[0];
    3598                 :           0 : }
    3599                 :             : 
    3600                 :             : /* Convert from the internal format to the 12-byte Intel format for
    3601                 :             :    an IEEE extended real.  */
    3602                 :             : static void
    3603                 :       55268 : encode_ieee_extended_intel_96 (const struct real_format *fmt, long *buf,
    3604                 :             :                                const REAL_VALUE_TYPE *r)
    3605                 :             : {
    3606                 :       55268 :   if (FLOAT_WORDS_BIG_ENDIAN)
    3607                 :             :     {
    3608                 :             :       /* All the padding in an Intel-format extended real goes at the high
    3609                 :             :          end, which in this case is after the mantissa, not the exponent.
    3610                 :             :          Therefore we must shift everything down 16 bits.  */
    3611                 :             :       long intermed[3];
    3612                 :             :       encode_ieee_extended (fmt, intermed, r);
    3613                 :             :       buf[0] = ((intermed[2] << 16) | ((unsigned long)(intermed[1] & 0xFFFF0000) >> 16));
    3614                 :             :       buf[1] = ((intermed[1] << 16) | ((unsigned long)(intermed[0] & 0xFFFF0000) >> 16));
    3615                 :             :       buf[2] =  (intermed[0] << 16);
    3616                 :             :     }
    3617                 :             :   else
    3618                 :             :     /* encode_ieee_extended produces what we want directly.  */
    3619                 :        3335 :     encode_ieee_extended (fmt, buf, r);
    3620                 :        3335 : }
    3621                 :             : 
    3622                 :             : /* Convert from the internal format to the 16-byte Intel format for
    3623                 :             :    an IEEE extended real.  */
    3624                 :             : static void
    3625                 :       51933 : encode_ieee_extended_intel_128 (const struct real_format *fmt, long *buf,
    3626                 :             :                                 const REAL_VALUE_TYPE *r)
    3627                 :             : {
    3628                 :             :   /* All the padding in an Intel-format extended real goes at the high end.  */
    3629                 :       51933 :   encode_ieee_extended_intel_96 (fmt, buf, r);
    3630                 :       51933 :   buf[3] = 0;
    3631                 :       51933 : }
    3632                 :             : 
    3633                 :             : /* As above, we have a helper function which converts from 12-byte
    3634                 :             :    little-endian Intel format to internal format.  Functions below
    3635                 :             :    adjust for the other possible formats.  */
    3636                 :             : static void
    3637                 :        2351 : decode_ieee_extended (const struct real_format *fmt, REAL_VALUE_TYPE *r,
    3638                 :             :                       const long *buf)
    3639                 :             : {
    3640                 :        2351 :   unsigned long image_hi, sig_hi, sig_lo;
    3641                 :        2351 :   bool sign;
    3642                 :        2351 :   int exp;
    3643                 :             : 
    3644                 :        2351 :   sig_lo = buf[0], sig_hi = buf[1], image_hi = buf[2];
    3645                 :        2351 :   sig_lo &= 0xffffffff;
    3646                 :        2351 :   sig_hi &= 0xffffffff;
    3647                 :        2351 :   image_hi &= 0xffffffff;
    3648                 :             : 
    3649                 :        2351 :   sign = (image_hi >> 15) & 1;
    3650                 :        2351 :   exp = image_hi & 0x7fff;
    3651                 :             : 
    3652                 :        2351 :   memset (r, 0, sizeof (*r));
    3653                 :             : 
    3654                 :        2351 :   if (exp == 0)
    3655                 :             :     {
    3656                 :         122 :       if ((sig_hi || sig_lo) && fmt->has_denorm)
    3657                 :             :         {
    3658                 :          14 :           r->cl = rvc_normal;
    3659                 :          14 :           r->sign = sign;
    3660                 :             : 
    3661                 :             :           /* When the IEEE format contains a hidden bit, we know that
    3662                 :             :              it's zero at this point, and so shift up the significand
    3663                 :             :              and decrease the exponent to match.  In this case, Motorola
    3664                 :             :              defines the explicit integer bit to be valid, so we don't
    3665                 :             :              know whether the msb is set or not.  */
    3666                 :          14 :           SET_REAL_EXP (r, fmt->emin);
    3667                 :          14 :           if (HOST_BITS_PER_LONG == 32)
    3668                 :             :             {
    3669                 :             :               r->sig[SIGSZ-1] = sig_hi;
    3670                 :             :               r->sig[SIGSZ-2] = sig_lo;
    3671                 :             :             }
    3672                 :             :           else
    3673                 :          14 :             r->sig[SIGSZ-1] = (sig_hi << 31 << 1) | sig_lo;
    3674                 :             : 
    3675                 :          14 :           normalize (r);
    3676                 :             :         }
    3677                 :         108 :       else if (fmt->has_signed_zero)
    3678                 :         108 :         r->sign = sign;
    3679                 :             :     }
    3680                 :        2229 :   else if (exp == 32767 && (fmt->has_nans || fmt->has_inf))
    3681                 :             :     {
    3682                 :             :       /* See above re "pseudo-infinities" and "pseudo-nans".
    3683                 :             :          Short summary is that the MSB will likely always be
    3684                 :             :          set, and that we don't care about it.  */
    3685                 :        1337 :       sig_hi &= 0x7fffffff;
    3686                 :             : 
    3687                 :        1337 :       if (sig_hi || sig_lo)
    3688                 :             :         {
    3689                 :        1265 :           r->cl = rvc_nan;
    3690                 :        1265 :           r->sign = sign;
    3691                 :        1265 :           r->signalling = ((sig_hi >> 30) & 1) ^ fmt->qnan_msb_set;
    3692                 :        1265 :           if (HOST_BITS_PER_LONG == 32)
    3693                 :             :             {
    3694                 :             :               r->sig[SIGSZ-1] = sig_hi;
    3695                 :             :               r->sig[SIGSZ-2] = sig_lo;
    3696                 :             :             }
    3697                 :             :           else
    3698                 :        1265 :             r->sig[SIGSZ-1] = (sig_hi << 31 << 1) | sig_lo;
    3699                 :             :         }
    3700                 :             :       else
    3701                 :             :         {
    3702                 :          72 :           r->cl = rvc_inf;
    3703                 :          72 :           r->sign = sign;
    3704                 :             :         }
    3705                 :             :     }
    3706                 :             :   else
    3707                 :             :     {
    3708                 :         892 :       r->cl = rvc_normal;
    3709                 :         892 :       r->sign = sign;
    3710                 :         892 :       SET_REAL_EXP (r, exp - 16383 + 1);
    3711                 :         892 :       if (HOST_BITS_PER_LONG == 32)
    3712                 :             :         {
    3713                 :             :           r->sig[SIGSZ-1] = sig_hi;
    3714                 :             :           r->sig[SIGSZ-2] = sig_lo;
    3715                 :             :         }
    3716                 :             :       else
    3717                 :         892 :         r->sig[SIGSZ-1] = (sig_hi << 31 << 1) | sig_lo;
    3718                 :             :     }
    3719                 :        2351 : }
    3720                 :             : 
    3721                 :             : /* Convert from the internal format to the 12-byte Motorola format
    3722                 :             :    for an IEEE extended real.  */
    3723                 :             : static void
    3724                 :           0 : decode_ieee_extended_motorola (const struct real_format *fmt, REAL_VALUE_TYPE *r,
    3725                 :             :                                const long *buf)
    3726                 :             : {
    3727                 :           0 :   long intermed[3];
    3728                 :             : 
    3729                 :             :   /* Motorola chips are assumed always to be big-endian.  Also, the
    3730                 :             :      padding in a Motorola extended real goes between the exponent and
    3731                 :             :      the mantissa; remove it.  */
    3732                 :           0 :   intermed[0] = buf[2];
    3733                 :           0 :   intermed[1] = buf[1];
    3734                 :           0 :   intermed[2] = (unsigned long)buf[0] >> 16;
    3735                 :             : 
    3736                 :           0 :   decode_ieee_extended (fmt, r, intermed);
    3737                 :           0 : }
    3738                 :             : 
    3739                 :             : /* Convert from the internal format to the 12-byte Intel format for
    3740                 :             :    an IEEE extended real.  */
    3741                 :             : static void
    3742                 :        2351 : decode_ieee_extended_intel_96 (const struct real_format *fmt, REAL_VALUE_TYPE *r,
    3743                 :             :                                const long *buf)
    3744                 :             : {
    3745                 :        2351 :   if (FLOAT_WORDS_BIG_ENDIAN)
    3746                 :             :     {
    3747                 :             :       /* All the padding in an Intel-format extended real goes at the high
    3748                 :             :          end, which in this case is after the mantissa, not the exponent.
    3749                 :             :          Therefore we must shift everything up 16 bits.  */
    3750                 :             :       long intermed[3];
    3751                 :             : 
    3752                 :             :       intermed[0] = (((unsigned long)buf[2] >> 16) | (buf[1] << 16));
    3753                 :             :       intermed[1] = (((unsigned long)buf[1] >> 16) | (buf[0] << 16));
    3754                 :             :       intermed[2] =  ((unsigned long)buf[0] >> 16);
    3755                 :             : 
    3756                 :             :       decode_ieee_extended (fmt, r, intermed);
    3757                 :             :     }
    3758                 :             :   else
    3759                 :             :     /* decode_ieee_extended produces what we want directly.  */
    3760                 :           0 :     decode_ieee_extended (fmt, r, buf);
    3761                 :           0 : }
    3762                 :             : 
    3763                 :             : /* Convert from the internal format to the 16-byte Intel format for
    3764                 :             :    an IEEE extended real.  */
    3765                 :             : static void
    3766                 :        2351 : decode_ieee_extended_intel_128 (const struct real_format *fmt, REAL_VALUE_TYPE *r,
    3767                 :             :                                 const long *buf)
    3768                 :             : {
    3769                 :             :   /* All the padding in an Intel-format extended real goes at the high end.  */
    3770                 :        2351 :   decode_ieee_extended_intel_96 (fmt, r, buf);
    3771                 :        2351 : }
    3772                 :             : 
    3773                 :             : const struct real_format ieee_extended_motorola_format =
    3774                 :             :   {
    3775                 :             :     encode_ieee_extended_motorola,
    3776                 :             :     decode_ieee_extended_motorola,
    3777                 :             :     2,
    3778                 :             :     64,
    3779                 :             :     64,
    3780                 :             :     -16382,
    3781                 :             :     16384,
    3782                 :             :     95,
    3783                 :             :     95,
    3784                 :             :     0,
    3785                 :             :     false,
    3786                 :             :     true,
    3787                 :             :     true,
    3788                 :             :     true,
    3789                 :             :     true,
    3790                 :             :     true,
    3791                 :             :     true,
    3792                 :             :     true,
    3793                 :             :     "ieee_extended_motorola"
    3794                 :             :   };
    3795                 :             : 
    3796                 :             : const struct real_format ieee_extended_intel_96_format =
    3797                 :             :   {
    3798                 :             :     encode_ieee_extended_intel_96,
    3799                 :             :     decode_ieee_extended_intel_96,
    3800                 :             :     2,
    3801                 :             :     64,
    3802                 :             :     64,
    3803                 :             :     -16381,
    3804                 :             :     16384,
    3805                 :             :     79,
    3806                 :             :     79,
    3807                 :             :     65,
    3808                 :             :     false,
    3809                 :             :     true,
    3810                 :             :     true,
    3811                 :             :     true,
    3812                 :             :     true,
    3813                 :             :     true,
    3814                 :             :     true,
    3815                 :             :     false,
    3816                 :             :     "ieee_extended_intel_96"
    3817                 :             :   };
    3818                 :             : 
    3819                 :             : const struct real_format ieee_extended_intel_128_format =
    3820                 :             :   {
    3821                 :             :     encode_ieee_extended_intel_128,
    3822                 :             :     decode_ieee_extended_intel_128,
    3823                 :             :     2,
    3824                 :             :     64,
    3825                 :             :     64,
    3826                 :             :     -16381,
    3827                 :             :     16384,
    3828                 :             :     79,
    3829                 :             :     79,
    3830                 :             :     65,
    3831                 :             :     false,
    3832                 :             :     true,
    3833                 :             :     true,
    3834                 :             :     true,
    3835                 :             :     true,
    3836                 :             :     true,
    3837                 :             :     true,
    3838                 :             :     false,
    3839                 :             :     "ieee_extended_intel_128"
    3840                 :             :   };
    3841                 :             : 
    3842                 :             : /* The following caters to i386 systems that set the rounding precision
    3843                 :             :    to 53 bits instead of 64, e.g. FreeBSD.  */
    3844                 :             : const struct real_format ieee_extended_intel_96_round_53_format =
    3845                 :             :   {
    3846                 :             :     encode_ieee_extended_intel_96,
    3847                 :             :     decode_ieee_extended_intel_96,
    3848                 :             :     2,
    3849                 :             :     53,
    3850                 :             :     53,
    3851                 :             :     -16381,
    3852                 :             :     16384,
    3853                 :             :     79,
    3854                 :             :     79,
    3855                 :             :     33,
    3856                 :             :     false,
    3857                 :             :     true,
    3858                 :             :     true,
    3859                 :             :     true,
    3860                 :             :     true,
    3861                 :             :     true,
    3862                 :             :     true,
    3863                 :             :     false,
    3864                 :             :     "ieee_extended_intel_96_round_53"
    3865                 :             :   };
    3866                 :             : 
    3867                 :             : /* IBM 128-bit extended precision format: a pair of IEEE double precision
    3868                 :             :    numbers whose sum is equal to the extended precision value.  The number
    3869                 :             :    with greater magnitude is first.  This format has the same magnitude
    3870                 :             :    range as an IEEE double precision value, but effectively 106 bits of
    3871                 :             :    significand precision.  Infinity and NaN are represented by their IEEE
    3872                 :             :    double precision value stored in the first number, the second number is
    3873                 :             :    +0.0 or -0.0 for Infinity and don't-care for NaN.  */
    3874                 :             : 
    3875                 :             : static void encode_ibm_extended (const struct real_format *fmt,
    3876                 :             :                                  long *, const REAL_VALUE_TYPE *);
    3877                 :             : static void decode_ibm_extended (const struct real_format *,
    3878                 :             :                                  REAL_VALUE_TYPE *, const long *);
    3879                 :             : 
    3880                 :             : static void
    3881                 :           0 : encode_ibm_extended (const struct real_format *fmt, long *buf,
    3882                 :             :                      const REAL_VALUE_TYPE *r)
    3883                 :             : {
    3884                 :           0 :   REAL_VALUE_TYPE u, normr, v;
    3885                 :           0 :   const struct real_format *base_fmt;
    3886                 :             : 
    3887                 :           0 :   base_fmt = fmt->qnan_msb_set ? &ieee_double_format : &mips_double_format;
    3888                 :             : 
    3889                 :             :   /* Renormalize R before doing any arithmetic on it.  */
    3890                 :           0 :   normr = *r;
    3891                 :           0 :   if (normr.cl == rvc_normal)
    3892                 :           0 :     normalize (&normr);
    3893                 :             : 
    3894                 :             :   /* u = IEEE double precision portion of significand.  */
    3895                 :           0 :   u = normr;
    3896                 :           0 :   round_for_format (base_fmt, &u);
    3897                 :           0 :   encode_ieee_double (base_fmt, &buf[0], &u);
    3898                 :             : 
    3899                 :           0 :   if (u.cl == rvc_normal)
    3900                 :             :     {
    3901                 :           0 :       do_add (&v, &normr, &u, 1);
    3902                 :             :       /* Call round_for_format since we might need to denormalize.  */
    3903                 :           0 :       round_for_format (base_fmt, &v);
    3904                 :           0 :       encode_ieee_double (base_fmt, &buf[2], &v);
    3905                 :             :     }
    3906                 :             :   else
    3907                 :             :     {
    3908                 :             :       /* Inf, NaN, 0 are all representable as doubles, so the
    3909                 :             :          least-significant part can be 0.0.  */
    3910                 :           0 :       buf[2] = 0;
    3911                 :           0 :       buf[3] = 0;
    3912                 :             :     }
    3913                 :           0 : }
    3914                 :             : 
    3915                 :             : static void
    3916                 :           0 : decode_ibm_extended (const struct real_format *fmt ATTRIBUTE_UNUSED, REAL_VALUE_TYPE *r,
    3917                 :             :                      const long *buf)
    3918                 :             : {
    3919                 :           0 :   REAL_VALUE_TYPE u, v;
    3920                 :           0 :   const struct real_format *base_fmt;
    3921                 :             : 
    3922                 :           0 :   base_fmt = fmt->qnan_msb_set ? &ieee_double_format : &mips_double_format;
    3923                 :           0 :   decode_ieee_double (base_fmt, &u, &buf[0]);
    3924                 :             : 
    3925                 :           0 :   if (u.cl != rvc_zero && u.cl != rvc_inf && u.cl != rvc_nan)
    3926                 :             :     {
    3927                 :           0 :       decode_ieee_double (base_fmt, &v, &buf[2]);
    3928                 :           0 :       do_add (r, &u, &v, 0);
    3929                 :             :     }
    3930                 :             :   else
    3931                 :           0 :     *r = u;
    3932                 :           0 : }
    3933                 :             : 
    3934                 :             : const struct real_format ibm_extended_format =
    3935                 :             :   {
    3936                 :             :     encode_ibm_extended,
    3937                 :             :     decode_ibm_extended,
    3938                 :             :     2,
    3939                 :             :     53 + 53,
    3940                 :             :     53,
    3941                 :             :     -1021 + 53,
    3942                 :             :     1024,
    3943                 :             :     127,
    3944                 :             :     -1,
    3945                 :             :     0,
    3946                 :             :     false,
    3947                 :             :     true,
    3948                 :             :     true,
    3949                 :             :     true,
    3950                 :             :     true,
    3951                 :             :     true,
    3952                 :             :     true,
    3953                 :             :     false,
    3954                 :             :     "ibm_extended"
    3955                 :             :   };
    3956                 :             : 
    3957                 :             : const struct real_format mips_extended_format =
    3958                 :             :   {
    3959                 :             :     encode_ibm_extended,
    3960                 :             :     decode_ibm_extended,
    3961                 :             :     2,
    3962                 :             :     53 + 53,
    3963                 :             :     53,
    3964                 :             :     -1021 + 53,
    3965                 :             :     1024,
    3966                 :             :     127,
    3967                 :             :     -1,
    3968                 :             :     0,
    3969                 :             :     false,
    3970                 :             :     true,
    3971                 :             :     true,
    3972                 :             :     true,
    3973                 :             :     true,
    3974                 :             :     true,
    3975                 :             :     false,
    3976                 :             :     true,
    3977                 :             :     "mips_extended"
    3978                 :             :   };
    3979                 :             : 
    3980                 :             : 
    3981                 :             : /* IEEE quad precision format.  */
    3982                 :             : 
    3983                 :             : static void encode_ieee_quad (const struct real_format *fmt,
    3984                 :             :                               long *, const REAL_VALUE_TYPE *);
    3985                 :             : static void decode_ieee_quad (const struct real_format *,
    3986                 :             :                               REAL_VALUE_TYPE *, const long *);
    3987                 :             : 
    3988                 :             : static void
    3989                 :       93719 : encode_ieee_quad (const struct real_format *fmt, long *buf,
    3990                 :             :                   const REAL_VALUE_TYPE *r)
    3991                 :             : {
    3992                 :       93719 :   unsigned long image3, image2, image1, image0, exp;
    3993                 :       93719 :   unsigned long sign = r->sign;
    3994                 :       93719 :   REAL_VALUE_TYPE u;
    3995                 :             : 
    3996                 :       93719 :   image3 = sign << 31;
    3997                 :       93719 :   image2 = 0;
    3998                 :       93719 :   image1 = 0;
    3999                 :       93719 :   image0 = 0;
    4000                 :             : 
    4001                 :       93719 :   rshift_significand (&u, r, SIGNIFICAND_BITS - 113);
    4002                 :             : 
    4003                 :       93719 :   switch (r->cl)
    4004                 :             :     {
    4005                 :             :     case rvc_zero:
    4006                 :             :       break;
    4007                 :             : 
    4008                 :         994 :     case rvc_inf:
    4009                 :         994 :       if (fmt->has_inf)
    4010                 :         994 :         image3 |= 32767 << 16;
    4011                 :             :       else
    4012                 :             :         {
    4013                 :           0 :           image3 |= 0x7fffffff;
    4014                 :           0 :           image2 = 0xffffffff;
    4015                 :           0 :           image1 = 0xffffffff;
    4016                 :           0 :           image0 = 0xffffffff;
    4017                 :             :         }
    4018                 :             :       break;
    4019                 :             : 
    4020                 :        2772 :     case rvc_nan:
    4021                 :        2772 :       if (fmt->has_nans)
    4022                 :             :         {
    4023                 :        2772 :           image3 |= 32767 << 16;
    4024                 :             : 
    4025                 :        2772 :           if (r->canonical)
    4026                 :             :             {
    4027                 :         509 :               if (fmt->canonical_nan_lsbs_set)
    4028                 :             :                 {
    4029                 :           0 :                   image3 |= 0x7fff;
    4030                 :           0 :                   image2 = image1 = image0 = 0xffffffff;
    4031                 :             :                 }
    4032                 :             :             }
    4033                 :        2263 :           else if (HOST_BITS_PER_LONG == 32)
    4034                 :             :             {
    4035                 :             :               image0 = u.sig[0];
    4036                 :             :               image1 = u.sig[1];
    4037                 :             :               image2 = u.sig[2];
    4038                 :             :               image3 |= u.sig[3] & 0xffff;
    4039                 :             :             }
    4040                 :             :           else
    4041                 :             :             {
    4042                 :        2263 :               image0 = u.sig[0];
    4043                 :        2263 :               image1 = image0 >> 31 >> 1;
    4044                 :        2263 :               image2 = u.sig[1];
    4045                 :        2263 :               image3 |= (image2 >> 31 >> 1) & 0xffff;
    4046                 :        2263 :               image0 &= 0xffffffff;
    4047                 :        2263 :               image2 &= 0xffffffff;
    4048                 :             :             }
    4049                 :        2772 :           if (r->signalling == fmt->qnan_msb_set)
    4050                 :         133 :             image3 &= ~0x8000;
    4051                 :             :           else
    4052                 :        2639 :             image3 |= 0x8000;
    4053                 :        2772 :           if (((image3 & 0xffff) | image2 | image1 | image0) == 0)
    4054                 :         108 :             image3 |= 0x4000;
    4055                 :             :         }
    4056                 :             :       else
    4057                 :             :         {
    4058                 :           0 :           image3 |= 0x7fffffff;
    4059                 :           0 :           image2 = 0xffffffff;
    4060                 :           0 :           image1 = 0xffffffff;
    4061                 :           0 :           image0 = 0xffffffff;
    4062                 :             :         }
    4063                 :             :       break;
    4064                 :             : 
    4065                 :       85042 :     case rvc_normal:
    4066                 :             :       /* Recall that IEEE numbers are interpreted as 1.F x 2**exp,
    4067                 :             :          whereas the intermediate representation is 0.F x 2**exp.
    4068                 :             :          Which means we're off by one.  */
    4069                 :       85042 :       if (real_isdenormal (r))
    4070                 :             :         exp = 0;
    4071                 :             :       else
    4072                 :       84126 :         exp = REAL_EXP (r) + 16383 - 1;
    4073                 :       85042 :       image3 |= exp << 16;
    4074                 :             : 
    4075                 :       85042 :       if (HOST_BITS_PER_LONG == 32)
    4076                 :             :         {
    4077                 :             :           image0 = u.sig[0];
    4078                 :             :           image1 = u.sig[1];
    4079                 :             :           image2 = u.sig[2];
    4080                 :             :           image3 |= u.sig[3] & 0xffff;
    4081                 :             :         }
    4082                 :             :       else
    4083                 :             :         {
    4084                 :       85042 :           image0 = u.sig[0];
    4085                 :       85042 :           image1 = image0 >> 31 >> 1;
    4086                 :       85042 :           image2 = u.sig[1];
    4087                 :       85042 :           image3 |= (image2 >> 31 >> 1) & 0xffff;
    4088                 :       85042 :           image0 &= 0xffffffff;
    4089                 :       85042 :           image2 &= 0xffffffff;
    4090                 :             :         }
    4091                 :       85042 :       break;
    4092                 :             : 
    4093                 :           0 :     default:
    4094                 :           0 :       gcc_unreachable ();
    4095                 :             :     }
    4096                 :             : 
    4097                 :       93719 :   if (FLOAT_WORDS_BIG_ENDIAN)
    4098                 :             :     {
    4099                 :             :       buf[0] = image3;
    4100                 :             :       buf[1] = image2;
    4101                 :             :       buf[2] = image1;
    4102                 :             :       buf[3] = image0;
    4103                 :             :     }
    4104                 :             :   else
    4105                 :             :     {
    4106                 :       93719 :       buf[0] = image0;
    4107                 :       93719 :       buf[1] = image1;
    4108                 :       93719 :       buf[2] = image2;
    4109                 :       93719 :       buf[3] = image3;
    4110                 :             :     }
    4111                 :       93719 : }
    4112                 :             : 
    4113                 :             : static void
    4114                 :        4113 : decode_ieee_quad (const struct real_format *fmt, REAL_VALUE_TYPE *r,
    4115                 :             :                   const long *buf)
    4116                 :             : {
    4117                 :        4113 :   unsigned long image3, image2, image1, image0;
    4118                 :        4113 :   bool sign;
    4119                 :        4113 :   int exp;
    4120                 :             : 
    4121                 :        4113 :   if (FLOAT_WORDS_BIG_ENDIAN)
    4122                 :             :     {
    4123                 :             :       image3 = buf[0];
    4124                 :             :       image2 = buf[1];
    4125                 :             :       image1 = buf[2];
    4126                 :             :       image0 = buf[3];
    4127                 :             :     }
    4128                 :             :   else
    4129                 :             :     {
    4130                 :        4113 :       image0 = buf[0];
    4131                 :        4113 :       image1 = buf[1];
    4132                 :        4113 :       image2 = buf[2];
    4133                 :        4113 :       image3 = buf[3];
    4134                 :             :     }
    4135                 :        4113 :   image0 &= 0xffffffff;
    4136                 :        4113 :   image1 &= 0xffffffff;
    4137                 :        4113 :   image2 &= 0xffffffff;
    4138                 :             : 
    4139                 :        4113 :   sign = (image3 >> 31) & 1;
    4140                 :        4113 :   exp = (image3 >> 16) & 0x7fff;
    4141                 :        4113 :   image3 &= 0xffff;
    4142                 :             : 
    4143                 :        4113 :   memset (r, 0, sizeof (*r));
    4144                 :             : 
    4145                 :        4113 :   if (exp == 0)
    4146                 :             :     {
    4147                 :        1312 :       if ((image3 | image2 | image1 | image0) && fmt->has_denorm)
    4148                 :             :         {
    4149                 :         400 :           r->cl = rvc_normal;
    4150                 :         400 :           r->sign = sign;
    4151                 :             : 
    4152                 :         400 :           SET_REAL_EXP (r, -16382 + (SIGNIFICAND_BITS - 112));
    4153                 :         400 :           if (HOST_BITS_PER_LONG == 32)
    4154                 :             :             {
    4155                 :             :               r->sig[0] = image0;
    4156                 :             :               r->sig[1] = image1;
    4157                 :             :               r->sig[2] = image2;
    4158                 :             :               r->sig[3] = image3;
    4159                 :             :             }
    4160                 :             :           else
    4161                 :             :             {
    4162                 :         400 :               r->sig[0] = (image1 << 31 << 1) | image0;
    4163                 :         400 :               r->sig[1] = (image3 << 31 << 1) | image2;
    4164                 :             :             }
    4165                 :             : 
    4166                 :         400 :           normalize (r);
    4167                 :             :         }
    4168                 :         912 :       else if (fmt->has_signed_zero)
    4169                 :         912 :         r->sign = sign;
    4170                 :             :     }
    4171                 :        2801 :   else if (exp == 32767 && (fmt->has_nans || fmt->has_inf))
    4172                 :             :     {
    4173                 :        1941 :       if (image3 | image2 | image1 | image0)
    4174                 :             :         {
    4175                 :        1937 :           r->cl = rvc_nan;
    4176                 :        1937 :           r->sign = sign;
    4177                 :        1937 :           r->signalling = ((image3 >> 15) & 1) ^ fmt->qnan_msb_set;
    4178                 :             : 
    4179                 :        1937 :           if (HOST_BITS_PER_LONG == 32)
    4180                 :             :             {
    4181                 :             :               r->sig[0] = image0;
    4182                 :             :               r->sig[1] = image1;
    4183                 :             :               r->sig[2] = image2;
    4184                 :             :               r->sig[3] = image3;
    4185                 :             :             }
    4186                 :             :           else
    4187                 :             :             {
    4188                 :        1937 :               r->sig[0] = (image1 << 31 << 1) | image0;
    4189                 :        1937 :               r->sig[1] = (image3 << 31 << 1) | image2;
    4190                 :             :             }
    4191                 :        1937 :           lshift_significand (r, r, SIGNIFICAND_BITS - 113);
    4192                 :             :         }
    4193                 :             :       else
    4194                 :             :         {
    4195                 :           4 :           r->cl = rvc_inf;
    4196                 :           4 :           r->sign = sign;
    4197                 :             :         }
    4198                 :             :     }
    4199                 :             :   else
    4200                 :             :     {
    4201                 :         860 :       r->cl = rvc_normal;
    4202                 :         860 :       r->sign = sign;
    4203                 :         860 :       SET_REAL_EXP (r, exp - 16383 + 1);
    4204                 :             : 
    4205                 :         860 :       if (HOST_BITS_PER_LONG == 32)
    4206                 :             :         {
    4207                 :             :           r->sig[0] = image0;
    4208                 :             :           r->sig[1] = image1;
    4209                 :             :           r->sig[2] = image2;
    4210                 :             :           r->sig[3] = image3;
    4211                 :             :         }
    4212                 :             :       else
    4213                 :             :         {
    4214                 :         860 :           r->sig[0] = (image1 << 31 << 1) | image0;
    4215                 :         860 :           r->sig[1] = (image3 << 31 << 1) | image2;
    4216                 :             :         }
    4217                 :         860 :       lshift_significand (r, r, SIGNIFICAND_BITS - 113);
    4218                 :         860 :       r->sig[SIGSZ-1] |= SIG_MSB;
    4219                 :             :     }
    4220                 :        4113 : }
    4221                 :             : 
    4222                 :             : const struct real_format ieee_quad_format =
    4223                 :             :   {
    4224                 :             :     encode_ieee_quad,
    4225                 :             :     decode_ieee_quad,
    4226                 :             :     2,
    4227                 :             :     113,
    4228                 :             :     113,
    4229                 :             :     -16381,
    4230                 :             :     16384,
    4231                 :             :     127,
    4232                 :             :     127,
    4233                 :             :     128,
    4234                 :             :     false,
    4235                 :             :     true,
    4236                 :             :     true,
    4237                 :             :     true,
    4238                 :             :     true,
    4239                 :             :     true,
    4240                 :             :     true,
    4241                 :             :     false,
    4242                 :             :     "ieee_quad"
    4243                 :             :   };
    4244                 :             : 
    4245                 :             : const struct real_format mips_quad_format =
    4246                 :             :   {
    4247                 :             :     encode_ieee_quad,
    4248                 :             :     decode_ieee_quad,
    4249                 :             :     2,
    4250                 :             :     113,
    4251                 :             :     113,
    4252                 :             :     -16381,
    4253                 :             :     16384,
    4254                 :             :     127,
    4255                 :             :     127,
    4256                 :             :     128,
    4257                 :             :     false,
    4258                 :             :     true,
    4259                 :             :     true,
    4260                 :             :     true,
    4261                 :             :     true,
    4262                 :             :     true,
    4263                 :             :     false,
    4264                 :             :     true,
    4265                 :             :     "mips_quad"
    4266                 :             :   };
    4267                 :             : 
    4268                 :             : /* Descriptions of VAX floating point formats can be found beginning at
    4269                 :             : 
    4270                 :             :    http://h71000.www7.hp.com/doc/73FINAL/4515/4515pro_013.html#f_floating_point_format
    4271                 :             : 
    4272                 :             :    The thing to remember is that they're almost IEEE, except for word
    4273                 :             :    order, exponent bias, and the lack of infinities, nans, and denormals.
    4274                 :             : 
    4275                 :             :    We don't implement the H_floating format here, simply because neither
    4276                 :             :    the VAX or Alpha ports use it.  */
    4277                 :             : 
    4278                 :             : static void encode_vax_f (const struct real_format *fmt,
    4279                 :             :                           long *, const REAL_VALUE_TYPE *);
    4280                 :             : static void decode_vax_f (const struct real_format *,
    4281                 :             :                           REAL_VALUE_TYPE *, const long *);
    4282                 :             : static void encode_vax_d (const struct real_format *fmt,
    4283                 :             :                           long *, const REAL_VALUE_TYPE *);
    4284                 :             : static void decode_vax_d (const struct real_format *,
    4285                 :             :                           REAL_VALUE_TYPE *, const long *);
    4286                 :             : static void encode_vax_g (const struct real_format *fmt,
    4287                 :             :                           long *, const REAL_VALUE_TYPE *);
    4288                 :             : static void decode_vax_g (const struct real_format *,
    4289                 :             :                           REAL_VALUE_TYPE *, const long *);
    4290                 :             : 
    4291                 :             : static void
    4292                 :           0 : encode_vax_f (const struct real_format *fmt ATTRIBUTE_UNUSED, long *buf,
    4293                 :             :               const REAL_VALUE_TYPE *r)
    4294                 :             : {
    4295                 :           0 :   unsigned long sign, exp, sig, image;
    4296                 :             : 
    4297                 :           0 :   sign = r->sign << 15;
    4298                 :             : 
    4299                 :           0 :   switch (r->cl)
    4300                 :             :     {
    4301                 :             :     case rvc_zero:
    4302                 :             :       image = 0;
    4303                 :             :       break;
    4304                 :             : 
    4305                 :           0 :     case rvc_inf:
    4306                 :           0 :     case rvc_nan:
    4307                 :           0 :       image = 0xffff7fff | sign;
    4308                 :           0 :       break;
    4309                 :             : 
    4310                 :           0 :     case rvc_normal:
    4311                 :           0 :       sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 24)) & 0x7fffff;
    4312                 :           0 :       exp = REAL_EXP (r) + 128;
    4313                 :             : 
    4314                 :           0 :       image = (sig << 16) & 0xffff0000;
    4315                 :           0 :       image |= sign;
    4316                 :           0 :       image |= exp << 7;
    4317                 :           0 :       image |= sig >> 16;
    4318                 :           0 :       break;
    4319                 :             : 
    4320                 :           0 :     default:
    4321                 :           0 :       gcc_unreachable ();
    4322                 :             :     }
    4323                 :             : 
    4324                 :           0 :   buf[0] = image;
    4325                 :           0 : }
    4326                 :             : 
    4327                 :             : static void
    4328                 :           0 : decode_vax_f (const struct real_format *fmt ATTRIBUTE_UNUSED,
    4329                 :             :               REAL_VALUE_TYPE *r, const long *buf)
    4330                 :             : {
    4331                 :           0 :   unsigned long image = buf[0] & 0xffffffff;
    4332                 :           0 :   int exp = (image >> 7) & 0xff;
    4333                 :             : 
    4334                 :           0 :   memset (r, 0, sizeof (*r));
    4335                 :             : 
    4336                 :           0 :   if (exp != 0)
    4337                 :             :     {
    4338                 :           0 :       r->cl = rvc_normal;
    4339                 :           0 :       r->sign = (image >> 15) & 1;
    4340                 :           0 :       SET_REAL_EXP (r, exp - 128);
    4341                 :             : 
    4342                 :           0 :       image = ((image & 0x7f) << 16) | ((image >> 16) & 0xffff);
    4343                 :           0 :       r->sig[SIGSZ-1] = (image << (HOST_BITS_PER_LONG - 24)) | SIG_MSB;
    4344                 :             :     }
    4345                 :           0 : }
    4346                 :             : 
    4347                 :             : static void
    4348                 :           0 : encode_vax_d (const struct real_format *fmt ATTRIBUTE_UNUSED, long *buf,
    4349                 :             :               const REAL_VALUE_TYPE *r)
    4350                 :             : {
    4351                 :           0 :   unsigned long image0, image1, sign = r->sign << 15;
    4352                 :             : 
    4353                 :           0 :   switch (r->cl)
    4354                 :             :     {
    4355                 :             :     case rvc_zero:
    4356                 :             :       image0 = image1 = 0;
    4357                 :             :       break;
    4358                 :             : 
    4359                 :           0 :     case rvc_inf:
    4360                 :           0 :     case rvc_nan:
    4361                 :           0 :       image0 = 0xffff7fff | sign;
    4362                 :           0 :       image1 = 0xffffffff;
    4363                 :           0 :       break;
    4364                 :             : 
    4365                 :           0 :     case rvc_normal:
    4366                 :             :       /* Extract the significand into straight hi:lo.  */
    4367                 :           0 :       if (HOST_BITS_PER_LONG == 64)
    4368                 :             :         {
    4369                 :           0 :           image0 = r->sig[SIGSZ-1];
    4370                 :           0 :           image1 = (image0 >> (64 - 56)) & 0xffffffff;
    4371                 :           0 :           image0 = (image0 >> (64 - 56 + 1) >> 31) & 0x7fffff;
    4372                 :             :         }
    4373                 :             :       else
    4374                 :             :         {
    4375                 :             :           image0 = r->sig[SIGSZ-1];
    4376                 :             :           image1 = r->sig[SIGSZ-2];
    4377                 :             :           image1 = (image0 << 24) | (image1 >> 8);
    4378                 :             :           image0 = (image0 >> 8) & 0xffffff;
    4379                 :             :         }
    4380                 :             : 
    4381                 :             :       /* Rearrange the half-words of the significand to match the
    4382                 :             :          external format.  */
    4383                 :           0 :       image0 = ((image0 << 16) | (image0 >> 16)) & 0xffff007f;
    4384                 :           0 :       image1 = ((image1 << 16) | (image1 >> 16)) & 0xffffffff;
    4385                 :             : 
    4386                 :             :       /* Add the sign and exponent.  */
    4387                 :           0 :       image0 |= sign;
    4388                 :           0 :       image0 |= (REAL_EXP (r) + 128) << 7;
    4389                 :           0 :       break;
    4390                 :             : 
    4391                 :           0 :     default:
    4392                 :           0 :       gcc_unreachable ();
    4393                 :             :     }
    4394                 :             : 
    4395                 :           0 :   if (FLOAT_WORDS_BIG_ENDIAN)
    4396                 :             :     buf[0] = image1, buf[1] = image0;
    4397                 :             :   else
    4398                 :           0 :     buf[0] = image0, buf[1] = image1;
    4399                 :           0 : }
    4400                 :             : 
    4401                 :             : static void
    4402                 :           0 : decode_vax_d (const struct real_format *fmt ATTRIBUTE_UNUSED,
    4403                 :             :               REAL_VALUE_TYPE *r, const long *buf)
    4404                 :             : {
    4405                 :           0 :   unsigned long image0, image1;
    4406                 :           0 :   int exp;
    4407                 :             : 
    4408                 :           0 :   if (FLOAT_WORDS_BIG_ENDIAN)
    4409                 :             :     image1 = buf[0], image0 = buf[1];
    4410                 :             :   else
    4411                 :           0 :     image0 = buf[0], image1 = buf[1];
    4412                 :           0 :   image0 &= 0xffffffff;
    4413                 :           0 :   image1 &= 0xffffffff;
    4414                 :             : 
    4415                 :           0 :   exp = (image0 >> 7) & 0xff;
    4416                 :             : 
    4417                 :           0 :   memset (r, 0, sizeof (*r));
    4418                 :             : 
    4419                 :           0 :   if (exp != 0)
    4420                 :             :     {
    4421                 :           0 :       r->cl = rvc_normal;
    4422                 :           0 :       r->sign = (image0 >> 15) & 1;
    4423                 :           0 :       SET_REAL_EXP (r, exp - 128);
    4424                 :             : 
    4425                 :             :       /* Rearrange the half-words of the external format into
    4426                 :             :          proper ascending order.  */
    4427                 :           0 :       image0 = ((image0 & 0x7f) << 16) | ((image0 >> 16) & 0xffff);
    4428                 :           0 :       image1 = ((image1 & 0xffff) << 16) | ((image1 >> 16) & 0xffff);
    4429                 :             : 
    4430                 :           0 :       if (HOST_BITS_PER_LONG == 64)
    4431                 :             :         {
    4432                 :           0 :           image0 = (image0 << 31 << 1) | image1;
    4433                 :           0 :           image0 <<= 64 - 56;
    4434                 :           0 :           image0 |= SIG_MSB;
    4435                 :           0 :           r->sig[SIGSZ-1] = image0;
    4436                 :             :         }
    4437                 :             :       else
    4438                 :             :         {
    4439                 :             :           r->sig[SIGSZ-1] = image0;
    4440                 :             :           r->sig[SIGSZ-2] = image1;
    4441                 :             :           lshift_significand (r, r, 2*HOST_BITS_PER_LONG - 56);
    4442                 :             :           r->sig[SIGSZ-1] |= SIG_MSB;
    4443                 :             :         }
    4444                 :             :     }
    4445                 :           0 : }
    4446                 :             : 
    4447                 :             : static void
    4448                 :           0 : encode_vax_g (const struct real_format *fmt ATTRIBUTE_UNUSED, long *buf,
    4449                 :             :               const REAL_VALUE_TYPE *r)
    4450                 :             : {
    4451                 :           0 :   unsigned long image0, image1, sign = r->sign << 15;
    4452                 :             : 
    4453                 :           0 :   switch (r->cl)
    4454                 :             :     {
    4455                 :             :     case rvc_zero:
    4456                 :             :       image0 = image1 = 0;
    4457                 :             :       break;
    4458                 :             : 
    4459                 :           0 :     case rvc_inf:
    4460                 :           0 :     case rvc_nan:
    4461                 :           0 :       image0 = 0xffff7fff | sign;
    4462                 :           0 :       image1 = 0xffffffff;
    4463                 :           0 :       break;
    4464                 :             : 
    4465                 :           0 :     case rvc_normal:
    4466                 :             :       /* Extract the significand into straight hi:lo.  */
    4467                 :           0 :       if (HOST_BITS_PER_LONG == 64)
    4468                 :             :         {
    4469                 :           0 :           image0 = r->sig[SIGSZ-1];
    4470                 :           0 :           image1 = (image0 >> (64 - 53)) & 0xffffffff;
    4471                 :           0 :           image0 = (image0 >> (64 - 53 + 1) >> 31) & 0xfffff;
    4472                 :             :         }
    4473                 :             :       else
    4474                 :             :         {
    4475                 :             :           image0 = r->sig[SIGSZ-1];
    4476                 :             :           image1 = r->sig[SIGSZ-2];
    4477                 :             :           image1 = (image0 << 21) | (image1 >> 11);
    4478                 :             :           image0 = (image0 >> 11) & 0xfffff;
    4479                 :             :         }
    4480                 :             : 
    4481                 :             :       /* Rearrange the half-words of the significand to match the
    4482                 :             :          external format.  */
    4483                 :           0 :       image0 = ((image0 << 16) | (image0 >> 16)) & 0xffff000f;
    4484                 :           0 :       image1 = ((image1 << 16) | (image1 >> 16)) & 0xffffffff;
    4485                 :             : 
    4486                 :             :       /* Add the sign and exponent.  */
    4487                 :           0 :       image0 |= sign;
    4488                 :           0 :       image0 |= (REAL_EXP (r) + 1024) << 4;
    4489                 :           0 :       break;
    4490                 :             : 
    4491                 :           0 :     default:
    4492                 :           0 :       gcc_unreachable ();
    4493                 :             :     }
    4494                 :             : 
    4495                 :           0 :   if (FLOAT_WORDS_BIG_ENDIAN)
    4496                 :             :     buf[0] = image1, buf[1] = image0;
    4497                 :             :   else
    4498                 :           0 :     buf[0] = image0, buf[1] = image1;
    4499                 :           0 : }
    4500                 :             : 
    4501                 :             : static void
    4502                 :           0 : decode_vax_g (const struct real_format *fmt ATTRIBUTE_UNUSED,
    4503                 :             :               REAL_VALUE_TYPE *r, const long *buf)
    4504                 :             : {
    4505                 :           0 :   unsigned long image0, image1;
    4506                 :           0 :   int exp;
    4507                 :             : 
    4508                 :           0 :   if (FLOAT_WORDS_BIG_ENDIAN)
    4509                 :             :     image1 = buf[0], image0 = buf[1];
    4510                 :             :   else
    4511                 :           0 :     image0 = buf[0], image1 = buf[1];
    4512                 :           0 :   image0 &= 0xffffffff;
    4513                 :           0 :   image1 &= 0xffffffff;
    4514                 :             : 
    4515                 :           0 :   exp = (image0 >> 4) & 0x7ff;
    4516                 :             : 
    4517                 :           0 :   memset (r, 0, sizeof (*r));
    4518                 :             : 
    4519                 :           0 :   if (exp != 0)
    4520                 :             :     {
    4521                 :           0 :       r->cl = rvc_normal;
    4522                 :           0 :       r->sign = (image0 >> 15) & 1;
    4523                 :           0 :       SET_REAL_EXP (r, exp - 1024);
    4524                 :             : 
    4525                 :             :       /* Rearrange the half-words of the external format into
    4526                 :             :          proper ascending order.  */
    4527                 :           0 :       image0 = ((image0 & 0xf) << 16) | ((image0 >> 16) & 0xffff);
    4528                 :           0 :       image1 = ((image1 & 0xffff) << 16) | ((image1 >> 16) & 0xffff);
    4529                 :             : 
    4530                 :           0 :       if (HOST_BITS_PER_LONG == 64)
    4531                 :             :         {
    4532                 :           0 :           image0 = (image0 << 31 << 1) | image1;
    4533                 :           0 :           image0 <<= 64 - 53;
    4534                 :           0 :           image0 |= SIG_MSB;
    4535                 :           0 :           r->sig[SIGSZ-1] = image0;
    4536                 :             :         }
    4537                 :             :       else
    4538                 :             :         {
    4539                 :             :           r->sig[SIGSZ-1] = image0;
    4540                 :             :           r->sig[SIGSZ-2] = image1;
    4541                 :             :           lshift_significand (r, r, 64 - 53);
    4542                 :             :           r->sig[SIGSZ-1] |= SIG_MSB;
    4543                 :             :         }
    4544                 :             :     }
    4545                 :           0 : }
    4546                 :             : 
    4547                 :             : const struct real_format vax_f_format =
    4548                 :             :   {
    4549                 :             :     encode_vax_f,
    4550                 :             :     decode_vax_f,
    4551                 :             :     2,
    4552                 :             :     24,
    4553                 :             :     24,
    4554                 :             :     -127,
    4555                 :             :     127,
    4556                 :             :     15,
    4557                 :             :     15,
    4558                 :             :     0,
    4559                 :             :     false,
    4560                 :             :     false,
    4561                 :             :     false,
    4562                 :             :     false,
    4563                 :             :     false,
    4564                 :             :     false,
    4565                 :             :     false,
    4566                 :             :     false,
    4567                 :             :     "vax_f"
    4568                 :             :   };
    4569                 :             : 
    4570                 :             : const struct real_format vax_d_format =
    4571                 :             :   {
    4572                 :             :     encode_vax_d,
    4573                 :             :     decode_vax_d,
    4574                 :             :     2,
    4575                 :             :     56,
    4576                 :             :     56,
    4577                 :             :     -127,
    4578                 :             :     127,
    4579                 :             :     15,
    4580                 :             :     15,
    4581                 :             :     0,
    4582                 :             :     false,
    4583                 :             :     false,
    4584                 :             :     false,
    4585                 :             :     false,
    4586                 :             :     false,
    4587                 :             :     false,
    4588                 :             :     false,
    4589                 :             :     false,
    4590                 :             :     "vax_d"
    4591                 :             :   };
    4592                 :             : 
    4593                 :             : const struct real_format vax_g_format =
    4594                 :             :   {
    4595                 :             :     encode_vax_g,
    4596                 :             :     decode_vax_g,
    4597                 :             :     2,
    4598                 :             :     53,
    4599                 :             :     53,
    4600                 :             :     -1023,
    4601                 :             :     1023,
    4602                 :             :     15,
    4603                 :             :     15,
    4604                 :             :     0,
    4605                 :             :     false,
    4606                 :             :     false,
    4607                 :             :     false,
    4608                 :             :     false,
    4609                 :             :     false,
    4610                 :             :     false,
    4611                 :             :     false,
    4612                 :             :     false,
    4613                 :             :     "vax_g"
    4614                 :             :   };
    4615                 :             : 
    4616                 :             : /* Encode real R into a single precision DFP value in BUF.  */
    4617                 :             : static void
    4618                 :       12138 : encode_decimal_single (const struct real_format *fmt ATTRIBUTE_UNUSED,
    4619                 :             :                        long *buf ATTRIBUTE_UNUSED,
    4620                 :             :                        const REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED)
    4621                 :             : {
    4622                 :       12138 :   encode_decimal32 (fmt, buf, r);
    4623                 :       12138 : }
    4624                 :             : 
    4625                 :             : /* Decode a single precision DFP value in BUF into a real R.  */
    4626                 :             : static void
    4627                 :         845 : decode_decimal_single (const struct real_format *fmt ATTRIBUTE_UNUSED,
    4628                 :             :                        REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED,
    4629                 :             :                        const long *buf ATTRIBUTE_UNUSED)
    4630                 :             : {
    4631                 :         845 :   decode_decimal32 (fmt, r, buf);
    4632                 :         845 : }
    4633                 :             : 
    4634                 :             : /* Encode real R into a double precision DFP value in BUF.  */
    4635                 :             : static void
    4636                 :       13913 : encode_decimal_double (const struct real_format *fmt ATTRIBUTE_UNUSED,
    4637                 :             :                        long *buf ATTRIBUTE_UNUSED,
    4638                 :             :                        const REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED)
    4639                 :             : {
    4640                 :       13913 :   encode_decimal64 (fmt, buf, r);
    4641                 :       13913 : }
    4642                 :             : 
    4643                 :             : /* Decode a double precision DFP value in BUF into a real R.  */
    4644                 :             : static void
    4645                 :        3031 : decode_decimal_double (const struct real_format *fmt ATTRIBUTE_UNUSED,
    4646                 :             :                        REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED,
    4647                 :             :                        const long *buf ATTRIBUTE_UNUSED)
    4648                 :             : {
    4649                 :        3031 :   decode_decimal64 (fmt, r, buf);
    4650                 :        3031 : }
    4651                 :             : 
    4652                 :             : /* Encode real R into a quad precision DFP value in BUF.  */
    4653                 :             : static void
    4654                 :       16319 : encode_decimal_quad (const struct real_format *fmt ATTRIBUTE_UNUSED,
    4655                 :             :                      long *buf ATTRIBUTE_UNUSED,
    4656                 :             :                      const REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED)
    4657                 :             : {
    4658                 :       16319 :   encode_decimal128 (fmt, buf, r);
    4659                 :       16319 : }
    4660                 :             : 
    4661                 :             : /* Decode a quad precision DFP value in BUF into a real R.  */
    4662                 :             : static void
    4663                 :        5592 : decode_decimal_quad (const struct real_format *fmt ATTRIBUTE_UNUSED,
    4664                 :             :                      REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED,
    4665                 :             :                      const long *buf ATTRIBUTE_UNUSED)
    4666                 :             : {
    4667                 :        5592 :   decode_decimal128 (fmt, r, buf);
    4668                 :        5592 : }
    4669                 :             : 
    4670                 :             : /* Single precision decimal floating point (IEEE 754). */
    4671                 :             : const struct real_format decimal_single_format =
    4672                 :             :   {
    4673                 :             :     encode_decimal_single,
    4674                 :             :     decode_decimal_single,
    4675                 :             :     10,
    4676                 :             :     7,
    4677                 :             :     7,
    4678                 :             :     -94,
    4679                 :             :     97,
    4680                 :             :     31,
    4681                 :             :     31,
    4682                 :             :     32,
    4683                 :             :     false,
    4684                 :             :     true,
    4685                 :             :     true,
    4686                 :             :     true,
    4687                 :             :     true,
    4688                 :             :     true,
    4689                 :             :     true,
    4690                 :             :     false,
    4691                 :             :     "decimal_single"
    4692                 :             :   };
    4693                 :             : 
    4694                 :             : /* Double precision decimal floating point (IEEE 754). */
    4695                 :             : const struct real_format decimal_double_format =
    4696                 :             :   {
    4697                 :             :     encode_decimal_double,
    4698                 :             :     decode_decimal_double,
    4699                 :             :     10,
    4700                 :             :     16,
    4701                 :             :     16,
    4702                 :             :     -382,
    4703                 :             :     385,
    4704                 :             :     63,
    4705                 :             :     63,
    4706                 :             :     64,
    4707                 :             :     false,
    4708                 :             :     true,
    4709                 :             :     true,
    4710                 :             :     true,
    4711                 :             :     true,
    4712                 :             :     true,
    4713                 :             :     true,
    4714                 :             :     false,
    4715                 :             :     "decimal_double"
    4716                 :             :   };
    4717                 :             : 
    4718                 :             : /* Quad precision decimal floating point (IEEE 754). */
    4719                 :             : const struct real_format decimal_quad_format =
    4720                 :             :   {
    4721                 :             :     encode_decimal_quad,
    4722                 :             :     decode_decimal_quad,
    4723                 :             :     10,
    4724                 :             :     34,
    4725                 :             :     34,
    4726                 :             :     -6142,
    4727                 :             :     6145,
    4728                 :             :     127,
    4729                 :             :     127,
    4730                 :             :     128,
    4731                 :             :     false,
    4732                 :             :     true,
    4733                 :             :     true,
    4734                 :             :     true,
    4735                 :             :     true,
    4736                 :             :     true,
    4737                 :             :     true,
    4738                 :             :     false,
    4739                 :             :     "decimal_quad"
    4740                 :             :   };
    4741                 :             : 
    4742                 :             : /* Encode half-precision floats.  This routine is used both for the IEEE
    4743                 :             :    ARM alternative encodings.  */
    4744                 :             : static void
    4745                 :       76964 : encode_ieee_half (const struct real_format *fmt, long *buf,
    4746                 :             :                   const REAL_VALUE_TYPE *r)
    4747                 :             : {
    4748                 :       76964 :   unsigned long image, sig, exp;
    4749                 :       76964 :   unsigned long sign = r->sign;
    4750                 :             : 
    4751                 :       76964 :   image = sign << 15;
    4752                 :       76964 :   sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 11)) & 0x3ff;
    4753                 :             : 
    4754                 :       76964 :   switch (r->cl)
    4755                 :             :     {
    4756                 :             :     case rvc_zero:
    4757                 :             :       break;
    4758                 :             : 
    4759                 :         521 :     case rvc_inf:
    4760                 :         521 :       if (fmt->has_inf)
    4761                 :         521 :         image |= 31 << 10;
    4762                 :             :       else
    4763                 :           0 :         image |= 0x7fff;
    4764                 :             :       break;
    4765                 :             : 
    4766                 :        1233 :     case rvc_nan:
    4767                 :        1233 :       if (fmt->has_nans)
    4768                 :             :         {
    4769                 :        1233 :           if (r->canonical)
    4770                 :         118 :             sig = (fmt->canonical_nan_lsbs_set ? (1 << 9) - 1 : 0);
    4771                 :        1233 :           if (r->signalling == fmt->qnan_msb_set)
    4772                 :          65 :             sig &= ~(1 << 9);
    4773                 :             :           else
    4774                 :        1168 :             sig |= 1 << 9;
    4775                 :        1233 :           if (sig == 0)
    4776                 :          32 :             sig = 1 << 8;
    4777                 :             : 
    4778                 :        1233 :           image |= 31 << 10;
    4779                 :        1233 :           image |= sig;
    4780                 :             :         }
    4781                 :             :       else
    4782                 :           0 :         image |= 0x3ff;
    4783                 :             :       break;
    4784                 :             : 
    4785                 :       57900 :     case rvc_normal:
    4786                 :             :       /* Recall that IEEE numbers are interpreted as 1.F x 2**exp,
    4787                 :             :          whereas the intermediate representation is 0.F x 2**exp.
    4788                 :             :          Which means we're off by one.  */
    4789                 :       57900 :       if (real_isdenormal (r))
    4790                 :             :         exp = 0;
    4791                 :             :       else
    4792                 :       54543 :         exp = REAL_EXP (r) + 15 - 1;
    4793                 :       57900 :       image |= exp << 10;
    4794                 :       57900 :       image |= sig;
    4795                 :       57900 :       break;
    4796                 :             : 
    4797                 :           0 :     default:
    4798                 :           0 :       gcc_unreachable ();
    4799                 :             :     }
    4800                 :             : 
    4801                 :       76964 :   buf[0] = image;
    4802                 :       76964 : }
    4803                 :             : 
    4804                 :             : /* Decode half-precision floats.  This routine is used both for the IEEE
    4805                 :             :    ARM alternative encodings.  */
    4806                 :             : static void
    4807                 :       11858 : decode_ieee_half (const struct real_format *fmt, REAL_VALUE_TYPE *r,
    4808                 :             :                   const long *buf)
    4809                 :             : {
    4810                 :       11858 :   unsigned long image = buf[0] & 0xffff;
    4811                 :       11858 :   bool sign = (image >> 15) & 1;
    4812                 :       11858 :   int exp = (image >> 10) & 0x1f;
    4813                 :             : 
    4814                 :       11858 :   memset (r, 0, sizeof (*r));
    4815                 :       11858 :   image <<= HOST_BITS_PER_LONG - 11;
    4816                 :       11858 :   image &= ~SIG_MSB;
    4817                 :             : 
    4818                 :       11858 :   if (exp == 0)
    4819                 :             :     {
    4820                 :        9760 :       if (image && fmt->has_denorm)
    4821                 :             :         {
    4822                 :        1886 :           r->cl = rvc_normal;
    4823                 :        1886 :           r->sign = sign;
    4824                 :        1886 :           SET_REAL_EXP (r, -14);
    4825                 :        1886 :           r->sig[SIGSZ-1] = image << 1;
    4826                 :        1886 :           normalize (r);
    4827                 :             :         }
    4828                 :        7874 :       else if (fmt->has_signed_zero)
    4829                 :        7874 :         r->sign = sign;
    4830                 :             :     }
    4831                 :        2098 :   else if (exp == 31 && (fmt->has_nans || fmt->has_inf))
    4832                 :             :     {
    4833                 :        1322 :       if (image)
    4834                 :             :         {
    4835                 :        1204 :           r->cl = rvc_nan;
    4836                 :        1204 :           r->sign = sign;
    4837                 :        1204 :           r->signalling = (((image >> (HOST_BITS_PER_LONG - 2)) & 1)
    4838                 :        1204 :                            ^ fmt->qnan_msb_set);
    4839                 :        1204 :           r->sig[SIGSZ-1] = image;
    4840                 :             :         }
    4841                 :             :       else
    4842                 :             :         {
    4843                 :         118 :           r->cl = rvc_inf;
    4844                 :         118 :           r->sign = sign;
    4845                 :             :         }
    4846                 :             :     }
    4847                 :             :   else
    4848                 :             :     {
    4849                 :         776 :       r->cl = rvc_normal;
    4850                 :         776 :       r->sign = sign;
    4851                 :         776 :       SET_REAL_EXP (r, exp - 15 + 1);
    4852                 :         776 :       r->sig[SIGSZ-1] = image | SIG_MSB;
    4853                 :             :     }
    4854                 :       11858 : }
    4855                 :             : 
    4856                 :             : /* Encode arm_bfloat types.  */
    4857                 :             : static void
    4858                 :        3031 : encode_arm_bfloat_half (const struct real_format *fmt, long *buf,
    4859                 :             :                     const REAL_VALUE_TYPE *r)
    4860                 :             : {
    4861                 :        3031 :   unsigned long image, sig, exp;
    4862                 :        3031 :   unsigned long sign = r->sign;
    4863                 :             : 
    4864                 :        3031 :   image = sign << 15;
    4865                 :        3031 :   sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 8)) & 0x7f;
    4866                 :             : 
    4867                 :        3031 :   switch (r->cl)
    4868                 :             :     {
    4869                 :             :     case rvc_zero:
    4870                 :             :       break;
    4871                 :             : 
    4872                 :         216 :     case rvc_inf:
    4873                 :         216 :       if (fmt->has_inf)
    4874                 :         216 :         image |= 255 << 7;
    4875                 :             :       else
    4876                 :           0 :         image |= 0x7fff;
    4877                 :             :       break;
    4878                 :             : 
    4879                 :          70 :     case rvc_nan:
    4880                 :          70 :       if (fmt->has_nans)
    4881                 :             :         {
    4882                 :          70 :           if (r->canonical)
    4883                 :          58 :             sig = (fmt->canonical_nan_lsbs_set ? (1 << 6) - 1 : 0);
    4884                 :          70 :           if (r->signalling == fmt->qnan_msb_set)
    4885                 :          35 :             sig &= ~(1 << 6);
    4886                 :             :           else
    4887                 :          35 :             sig |= 1 << 6;
    4888                 :          70 :           if (sig == 0)
    4889                 :          30 :             sig = 1 << 5;
    4890                 :             : 
    4891                 :          70 :           image |= 255 << 7;
    4892                 :          70 :           image |= sig;
    4893                 :             :         }
    4894                 :             :       else
    4895                 :           0 :         image |= 0x7fff;
    4896                 :             :       break;
    4897                 :             : 
    4898                 :        1345 :     case rvc_normal:
    4899                 :        1345 :       if (real_isdenormal (r))
    4900                 :             :         exp = 0;
    4901                 :             :       else
    4902                 :        1309 :       exp = REAL_EXP (r) + 127 - 1;
    4903                 :        1345 :       image |= exp << 7;
    4904                 :        1345 :       image |= sig;
    4905                 :        1345 :       break;
    4906                 :             : 
    4907                 :           0 :     default:
    4908                 :           0 :       gcc_unreachable ();
    4909                 :             :     }
    4910                 :             : 
    4911                 :        3031 :   buf[0] = image;
    4912                 :        3031 : }
    4913                 :             : 
    4914                 :             : /* Decode arm_bfloat types.  */
    4915                 :             : static void
    4916                 :        1405 : decode_arm_bfloat_half (const struct real_format *fmt, REAL_VALUE_TYPE *r,
    4917                 :             :                     const long *buf)
    4918                 :             : {
    4919                 :        1405 :   unsigned long image = buf[0] & 0xffff;
    4920                 :        1405 :   bool sign = (image >> 15) & 1;
    4921                 :        1405 :   int exp = (image >> 7) & 0xff;
    4922                 :             : 
    4923                 :        1405 :   memset (r, 0, sizeof (*r));
    4924                 :        1405 :   image <<= HOST_BITS_PER_LONG - 8;
    4925                 :        1405 :   image &= ~SIG_MSB;
    4926                 :             : 
    4927                 :        1405 :   if (exp == 0)
    4928                 :             :     {
    4929                 :        1085 :       if (image && fmt->has_denorm)
    4930                 :             :         {
    4931                 :          14 :           r->cl = rvc_normal;
    4932                 :          14 :           r->sign = sign;
    4933                 :          14 :           SET_REAL_EXP (r, -126);
    4934                 :          14 :           r->sig[SIGSZ-1] = image << 1;
    4935                 :          14 :           normalize (r);
    4936                 :             :         }
    4937                 :        1071 :       else if (fmt->has_signed_zero)
    4938                 :        1071 :         r->sign = sign;
    4939                 :             :     }
    4940                 :         320 :   else if (exp == 255 && (fmt->has_nans || fmt->has_inf))
    4941                 :             :     {
    4942                 :          84 :       if (image)
    4943                 :             :         {
    4944                 :           6 :           r->cl = rvc_nan;
    4945                 :           6 :           r->sign = sign;
    4946                 :           6 :           r->signalling = (((image >> (HOST_BITS_PER_LONG - 2)) & 1)
    4947                 :           6 :                            ^ fmt->qnan_msb_set);
    4948                 :           6 :           r->sig[SIGSZ-1] = image;
    4949                 :             :         }
    4950                 :             :       else
    4951                 :             :         {
    4952                 :          78 :           r->cl = rvc_inf;
    4953                 :          78 :           r->sign = sign;
    4954                 :             :         }
    4955                 :             :     }
    4956                 :             :   else
    4957                 :             :     {
    4958                 :         236 :       r->cl = rvc_normal;
    4959                 :         236 :       r->sign = sign;
    4960                 :         236 :       SET_REAL_EXP (r, exp - 127 + 1);
    4961                 :         236 :       r->sig[SIGSZ-1] = image | SIG_MSB;
    4962                 :             :     }
    4963                 :        1405 : }
    4964                 :             : 
    4965                 :             : /* Half-precision format, as specified in IEEE 754R.  */
    4966                 :             : const struct real_format ieee_half_format =
    4967                 :             :   {
    4968                 :             :     encode_ieee_half,
    4969                 :             :     decode_ieee_half,
    4970                 :             :     2,
    4971                 :             :     11,
    4972                 :             :     11,
    4973                 :             :     -13,
    4974                 :             :     16,
    4975                 :             :     15,
    4976                 :             :     15,
    4977                 :             :     16,
    4978                 :             :     false,
    4979                 :             :     true,
    4980                 :             :     true,
    4981                 :             :     true,
    4982                 :             :     true,
    4983                 :             :     true,
    4984                 :             :     true,
    4985                 :             :     false,
    4986                 :             :     "ieee_half"
    4987                 :             :   };
    4988                 :             : 
    4989                 :             : /* ARM's alternative half-precision format, similar to IEEE but with
    4990                 :             :    no reserved exponent value for NaNs and infinities; rather, it just
    4991                 :             :    extends the range of exponents by one.  */
    4992                 :             : const struct real_format arm_half_format =
    4993                 :             :   {
    4994                 :             :     encode_ieee_half,
    4995                 :             :     decode_ieee_half,
    4996                 :             :     2,
    4997                 :             :     11,
    4998                 :             :     11,
    4999                 :             :     -13,
    5000                 :             :     17,
    5001                 :             :     15,
    5002                 :             :     15,
    5003                 :             :     0,
    5004                 :             :     false,
    5005                 :             :     true,
    5006                 :             :     false,
    5007                 :             :     false,
    5008                 :             :     true,
    5009                 :             :     true,
    5010                 :             :     false,
    5011                 :             :     false,
    5012                 :             :     "arm_half"
    5013                 :             :   };
    5014                 :             : 
    5015                 :             : /* ARM Bfloat half-precision format.  This format resembles a truncated
    5016                 :             :    (16-bit) version of the 32-bit IEEE 754 single-precision floating-point
    5017                 :             :    format.  */
    5018                 :             : const struct real_format arm_bfloat_half_format =
    5019                 :             :   {
    5020                 :             :     encode_arm_bfloat_half,
    5021                 :             :     decode_arm_bfloat_half,
    5022                 :             :     2,
    5023                 :             :     8,
    5024                 :             :     8,
    5025                 :             :     -125,
    5026                 :             :     128,
    5027                 :             :     15,
    5028                 :             :     15,
    5029                 :             :     0,
    5030                 :             :     false,
    5031                 :             :     true,
    5032                 :             :     true,
    5033                 :             :     true,
    5034                 :             :     true,
    5035                 :             :     true,
    5036                 :             :     true,
    5037                 :             :     false,
    5038                 :             :     "arm_bfloat_half"
    5039                 :             :   };
    5040                 :             : 
    5041                 :             : 
    5042                 :             : /* A synthetic "format" for internal arithmetic.  It's the size of the
    5043                 :             :    internal significand minus the two bits needed for proper rounding.
    5044                 :             :    The encode and decode routines exist only to satisfy our paranoia
    5045                 :             :    harness.  */
    5046                 :             : 
    5047                 :             : static void encode_internal (const struct real_format *fmt,
    5048                 :             :                              long *, const REAL_VALUE_TYPE *);
    5049                 :             : static void decode_internal (const struct real_format *,
    5050                 :             :                              REAL_VALUE_TYPE *, const long *);
    5051                 :             : 
    5052                 :             : static void
    5053                 :           0 : encode_internal (const struct real_format *fmt ATTRIBUTE_UNUSED, long *buf,
    5054                 :             :                  const REAL_VALUE_TYPE *r)
    5055                 :             : {
    5056                 :           0 :   memcpy (buf, r, sizeof (*r));
    5057                 :           0 : }
    5058                 :             : 
    5059                 :             : static void
    5060                 :           0 : decode_internal (const struct real_format *fmt ATTRIBUTE_UNUSED,
    5061                 :             :                  REAL_VALUE_TYPE *r, const long *buf)
    5062                 :             : {
    5063                 :           0 :   memcpy (r, buf, sizeof (*r));
    5064                 :           0 : }
    5065                 :             : 
    5066                 :             : const struct real_format real_internal_format =
    5067                 :             :   {
    5068                 :             :     encode_internal,
    5069                 :             :     decode_internal,
    5070                 :             :     2,
    5071                 :             :     SIGNIFICAND_BITS - 2,
    5072                 :             :     SIGNIFICAND_BITS - 2,
    5073                 :             :     -MAX_EXP,
    5074                 :             :     MAX_EXP,
    5075                 :             :     -1,
    5076                 :             :     -1,
    5077                 :             :     0,
    5078                 :             :     false,
    5079                 :             :     false,
    5080                 :             :     true,
    5081                 :             :     true,
    5082                 :             :     false,
    5083                 :             :     true,
    5084                 :             :     true,
    5085                 :             :     false,
    5086                 :             :     "real_internal"
    5087                 :             :   };
    5088                 :             : 
    5089                 :             : /* Calculate X raised to the integer exponent N in format FMT and store
    5090                 :             :    the result in R.  Return true if the result may be inexact due to
    5091                 :             :    loss of precision.  The algorithm is the classic "left-to-right binary
    5092                 :             :    method" described in section 4.6.3 of Donald Knuth's "Seminumerical
    5093                 :             :    Algorithms", "The Art of Computer Programming", Volume 2.  */
    5094                 :             : 
    5095                 :             : bool
    5096                 :        1976 : real_powi (REAL_VALUE_TYPE *r, format_helper fmt,
    5097                 :             :            const REAL_VALUE_TYPE *x, HOST_WIDE_INT n)
    5098                 :             : {
    5099                 :        1976 :   unsigned HOST_WIDE_INT bit;
    5100                 :        1976 :   REAL_VALUE_TYPE t;
    5101                 :        1976 :   bool inexact = false;
    5102                 :        1976 :   bool init = false;
    5103                 :        1976 :   bool neg;
    5104                 :        1976 :   int i;
    5105                 :             : 
    5106                 :        1976 :   if (n == 0)
    5107                 :             :     {
    5108                 :          29 :       *r = dconst1;
    5109                 :          29 :       return false;
    5110                 :             :     }
    5111                 :        1947 :   else if (n < 0)
    5112                 :             :     {
    5113                 :             :       /* Don't worry about overflow, from now on n is unsigned.  */
    5114                 :         933 :       neg = true;
    5115                 :         933 :       n = -n;
    5116                 :             :     }
    5117                 :             :   else
    5118                 :             :     neg = false;
    5119                 :             : 
    5120                 :        1947 :   t = *x;
    5121                 :        1947 :   bit = HOST_WIDE_INT_1U << (HOST_BITS_PER_WIDE_INT - 1);
    5122                 :      126555 :   for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
    5123                 :             :     {
    5124                 :      124608 :       if (init)
    5125                 :             :         {
    5126                 :       83571 :           inexact |= do_multiply (&t, &t, &t);
    5127                 :       83571 :           if (n & bit)
    5128                 :        2011 :             inexact |= do_multiply (&t, &t, x);
    5129                 :             :         }
    5130                 :       41037 :       else if (n & bit)
    5131                 :        1947 :         init = true;
    5132                 :      124608 :       bit >>= 1;
    5133                 :             :     }
    5134                 :             : 
    5135                 :        1947 :   if (neg)
    5136                 :         933 :     inexact |= do_divide (&t, &dconst1, &t);
    5137                 :             : 
    5138                 :        1947 :   real_convert (r, fmt, &t);
    5139                 :        1947 :   return inexact;
    5140                 :             : }
    5141                 :             : 
    5142                 :             : /* Round X to the nearest integer not larger in absolute value, i.e.
    5143                 :             :    towards zero, placing the result in R in format FMT.  */
    5144                 :             : 
    5145                 :             : void
    5146                 :       37528 : real_trunc (REAL_VALUE_TYPE *r, format_helper fmt,
    5147                 :             :             const REAL_VALUE_TYPE *x)
    5148                 :             : {
    5149                 :       37528 :   do_fix_trunc (r, x);
    5150                 :       37528 :   if (fmt)
    5151                 :        7005 :     real_convert (r, fmt, r);
    5152                 :       37528 : }
    5153                 :             : 
    5154                 :             : /* Round X to the largest integer not greater in value, i.e. round
    5155                 :             :    down, placing the result in R in format FMT.  */
    5156                 :             : 
    5157                 :             : void
    5158                 :        1102 : real_floor (REAL_VALUE_TYPE *r, format_helper fmt,
    5159                 :             :             const REAL_VALUE_TYPE *x)
    5160                 :             : {
    5161                 :        1102 :   REAL_VALUE_TYPE t;
    5162                 :             : 
    5163                 :        1102 :   do_fix_trunc (&t, x);
    5164                 :        1102 :   if (! real_identical (&t, x) && x->sign)
    5165                 :         272 :     do_add (&t, &t, &dconstm1, 0);
    5166                 :        1102 :   if (fmt)
    5167                 :        1102 :     real_convert (r, fmt, &t);
    5168                 :             :   else
    5169                 :           0 :     *r = t;
    5170                 :        1102 : }
    5171                 :             : 
    5172                 :             : /* Round X to the smallest integer not less then argument, i.e. round
    5173                 :             :    up, placing the result in R in format FMT.  */
    5174                 :             : 
    5175                 :             : void
    5176                 :       39071 : real_ceil (REAL_VALUE_TYPE *r, format_helper fmt,
    5177                 :             :            const REAL_VALUE_TYPE *x)
    5178                 :             : {
    5179                 :       39071 :   REAL_VALUE_TYPE t;
    5180                 :             : 
    5181                 :       39071 :   do_fix_trunc (&t, x);
    5182                 :       39071 :   if (! real_identical (&t, x) && ! x->sign)
    5183                 :         269 :     do_add (&t, &t, &dconst1, 0);
    5184                 :       39071 :   if (fmt)
    5185                 :       39071 :     real_convert (r, fmt, &t);
    5186                 :             :   else
    5187                 :           0 :     *r = t;
    5188                 :       39071 : }
    5189                 :             : 
    5190                 :             : /* Round X to the nearest integer, but round halfway cases away from
    5191                 :             :    zero.  */
    5192                 :             : 
    5193                 :             : void
    5194                 :        1405 : real_round (REAL_VALUE_TYPE *r, format_helper fmt,
    5195                 :             :             const REAL_VALUE_TYPE *x)
    5196                 :             : {
    5197                 :        1405 :   do_add (r, x, &dconsthalf, x->sign);
    5198                 :        1405 :   do_fix_trunc (r, r);
    5199                 :        1405 :   if (fmt)
    5200                 :        1405 :     real_convert (r, fmt, r);
    5201                 :        1405 : }
    5202                 :             : 
    5203                 :             : /* Return true (including 0) if integer part of R is even, else return
    5204                 :             :    false.  The function is not valid for rvc_inf and rvc_nan classes.  */
    5205                 :             : 
    5206                 :             : static bool
    5207                 :          49 : is_even (REAL_VALUE_TYPE *r)
    5208                 :             : {
    5209                 :          49 :   gcc_assert (r->cl != rvc_inf);
    5210                 :          49 :   gcc_assert (r->cl != rvc_nan);
    5211                 :             : 
    5212                 :          49 :   if (r->cl == rvc_zero)
    5213                 :             :     return true;
    5214                 :             : 
    5215                 :             :   /* For (-1,1), number is even.  */
    5216                 :          49 :   if (REAL_EXP (r) <= 0)
    5217                 :             :     return true;
    5218                 :             : 
    5219                 :             :   /* Check lowest bit, if not set, return true.  */
    5220                 :          49 :   else if (REAL_EXP (r) <= SIGNIFICAND_BITS)
    5221                 :             :     {
    5222                 :          49 :       unsigned int n = SIGNIFICAND_BITS - REAL_EXP (r);
    5223                 :          49 :       int w = n / HOST_BITS_PER_LONG;
    5224                 :             : 
    5225                 :          49 :       unsigned long num = ((unsigned long)1 << (n % HOST_BITS_PER_LONG));
    5226                 :             : 
    5227                 :          49 :       if ((r->sig[w] & num) == 0)
    5228                 :          28 :         return true;
    5229                 :             :     }
    5230                 :             :   else
    5231                 :             :     return true;
    5232                 :             : 
    5233                 :             :   return false;
    5234                 :             : }
    5235                 :             : 
    5236                 :             : /* Return true if R is halfway between two integers, else return
    5237                 :             :    false.  */
    5238                 :             : 
    5239                 :             : static bool
    5240                 :         189 : is_halfway_below (const REAL_VALUE_TYPE *r)
    5241                 :             : {
    5242                 :         189 :   if (r->cl != rvc_normal)
    5243                 :             :     return false;
    5244                 :             : 
    5245                 :             :   /* For numbers (-0.5,0) and (0,0.5).  */
    5246                 :         147 :   if (REAL_EXP (r) < 0)
    5247                 :             :     return false;
    5248                 :             : 
    5249                 :         133 :   else if (REAL_EXP (r) < SIGNIFICAND_BITS)
    5250                 :             :     {
    5251                 :         119 :       unsigned int n = SIGNIFICAND_BITS - REAL_EXP (r) - 1;
    5252                 :         119 :       int w = n / HOST_BITS_PER_LONG;
    5253                 :             : 
    5254                 :         322 :       for (int i = 0; i < w; ++i)
    5255                 :         210 :         if (r->sig[i] != 0)
    5256                 :             :           return false;
    5257                 :             : 
    5258                 :         112 :       unsigned long num = 1UL << (n % HOST_BITS_PER_LONG);
    5259                 :             : 
    5260                 :         112 :       if ((r->sig[w] & num) != 0 && (r->sig[w] & (num - 1)) == 0)
    5261                 :          77 :         return true;
    5262                 :             :     }
    5263                 :             :   return false;
    5264                 :             : }
    5265                 :             : 
    5266                 :             : /* Round X to nearest integer, rounding halfway cases towards even.  */
    5267                 :             : 
    5268                 :             : void
    5269                 :         189 : real_roundeven (REAL_VALUE_TYPE *r, format_helper fmt,
    5270                 :             :                 const REAL_VALUE_TYPE *x)
    5271                 :             : {
    5272                 :         189 :   if (is_halfway_below (x))
    5273                 :             :     {
    5274                 :             :       /* Special case as -0.5 rounds to -0.0 and
    5275                 :             :          similarly +0.5 rounds to +0.0.  */
    5276                 :          77 :       if (REAL_EXP (x) == 0)
    5277                 :             :         {
    5278                 :          28 :           *r = *x;
    5279                 :          28 :           clear_significand_below (r, SIGNIFICAND_BITS);
    5280                 :             :         }
    5281                 :             :       else
    5282                 :             :         {
    5283                 :          49 :           do_add (r, x, &dconsthalf, x->sign);
    5284                 :          49 :           if (!is_even (r))
    5285                 :          21 :             do_add (r, r, &dconstm1, x->sign);
    5286                 :             :         }
    5287                 :          77 :       if (fmt)
    5288                 :          77 :         real_convert (r, fmt, r);
    5289                 :             :     }
    5290                 :             :   else
    5291                 :         112 :     real_round (r, fmt, x);
    5292                 :         189 : }
    5293                 :             : 
    5294                 :             : /* Set the sign of R to the sign of X.  */
    5295                 :             : 
    5296                 :             : void
    5297                 :       70639 : real_copysign (REAL_VALUE_TYPE *r, const REAL_VALUE_TYPE *x)
    5298                 :             : {
    5299                 :       70639 :   r->sign = x->sign;
    5300                 :       70639 : }
    5301                 :             : 
    5302                 :             : /* Check whether the real constant value given is an integer.
    5303                 :             :    Returns false for signaling NaN.  */
    5304                 :             : 
    5305                 :             : bool
    5306                 :        6350 : real_isinteger (const REAL_VALUE_TYPE *c, format_helper fmt)
    5307                 :             : {
    5308                 :        6350 :   REAL_VALUE_TYPE cint;
    5309                 :             : 
    5310                 :        6350 :   real_trunc (&cint, fmt, c);
    5311                 :        6350 :   return real_identical (c, &cint);
    5312                 :             : }
    5313                 :             : 
    5314                 :             : /* Check whether C is an integer that fits in a HOST_WIDE_INT,
    5315                 :             :    storing it in *INT_OUT if so.  */
    5316                 :             : 
    5317                 :             : bool
    5318                 :         148 : real_isinteger (const REAL_VALUE_TYPE *c, HOST_WIDE_INT *int_out)
    5319                 :             : {
    5320                 :         148 :   REAL_VALUE_TYPE cint;
    5321                 :             : 
    5322                 :         148 :   HOST_WIDE_INT n = real_to_integer (c);
    5323                 :         148 :   real_from_integer (&cint, VOIDmode, n, SIGNED);
    5324                 :         148 :   if (real_identical (c, &cint))
    5325                 :             :     {
    5326                 :          67 :       *int_out = n;
    5327                 :          67 :       return true;
    5328                 :             :     }
    5329                 :             :   return false;
    5330                 :             : }
    5331                 :             : 
    5332                 :             : /* Calculate nextafter (X, Y) or nexttoward (X, Y).  Return true if
    5333                 :             :    underflow or overflow needs to be raised.  */
    5334                 :             : 
    5335                 :             : bool
    5336                 :      951700 : real_nextafter (REAL_VALUE_TYPE *r, format_helper fmt,
    5337                 :             :                 const REAL_VALUE_TYPE *x, const REAL_VALUE_TYPE *y)
    5338                 :             : {
    5339                 :      951700 :   int cmp = do_compare (x, y, 2);
    5340                 :             :   /* If either operand is NaN, return qNaN.  */
    5341                 :      951700 :   if (cmp == 2)
    5342                 :             :     {
    5343                 :          70 :       get_canonical_qnan (r, 0);
    5344                 :          70 :       return false;
    5345                 :             :     }
    5346                 :             :   /* If x == y, return y cast to target type.  */
    5347                 :      951630 :   if (cmp == 0)
    5348                 :             :     {
    5349                 :         290 :       real_convert (r, fmt, y);
    5350                 :         290 :       return false;
    5351                 :             :     }
    5352                 :             : 
    5353                 :      951340 :   if (x->cl == rvc_zero)
    5354                 :             :     {
    5355                 :      138172 :       get_zero (r, y->sign);
    5356                 :      138172 :       r->cl = rvc_normal;
    5357                 :      138172 :       SET_REAL_EXP (r, fmt->emin - fmt->p + 1);
    5358                 :      138172 :       r->sig[SIGSZ - 1] = SIG_MSB;
    5359                 :      138172 :       return false;
    5360                 :             :     }
    5361                 :             : 
    5362                 :      813168 :   int np2 = SIGNIFICAND_BITS - fmt->p;
    5363                 :             :   /* For denormals adjust np2 correspondingly.  */
    5364                 :      813168 :   if (x->cl == rvc_normal && REAL_EXP (x) < fmt->emin)
    5365                 :       34138 :     np2 += fmt->emin - REAL_EXP (x);
    5366                 :             : 
    5367                 :      813168 :   REAL_VALUE_TYPE u;
    5368                 :      813168 :   get_zero (r, x->sign);
    5369                 :      813168 :   get_zero (&u, 0);
    5370                 :      813168 :   set_significand_bit (&u, np2);
    5371                 :      813168 :   r->cl = rvc_normal;
    5372                 :      813168 :   SET_REAL_EXP (r, REAL_EXP (x));
    5373                 :             : 
    5374                 :      813168 :   if (x->cl == rvc_inf)
    5375                 :             :     {
    5376                 :      113638 :       bool borrow = sub_significands (r, r, &u, 0);
    5377                 :      113638 :       gcc_assert (borrow);
    5378                 :      113638 :       SET_REAL_EXP (r, fmt->emax);
    5379                 :             :     }
    5380                 :     1209867 :   else if (cmp == (x->sign ? 1 : -1))
    5381                 :             :     {
    5382                 :      320698 :       if (add_significands (r, x, &u))
    5383                 :             :         {
    5384                 :             :           /* Overflow.  Means the significand had been all ones, and
    5385                 :             :              is now all zeros.  Need to increase the exponent, and
    5386                 :             :              possibly re-normalize it.  */
    5387                 :      136813 :           SET_REAL_EXP (r, REAL_EXP (r) + 1);
    5388                 :      136813 :           if (REAL_EXP (r) > fmt->emax)
    5389                 :             :             {
    5390                 :       80975 :               get_inf (r, x->sign);
    5391                 :       80975 :               return true;
    5392                 :             :             }
    5393                 :       55838 :           r->sig[SIGSZ - 1] = SIG_MSB;
    5394                 :             :         }
    5395                 :             :     }
    5396                 :             :   else
    5397                 :             :     {
    5398                 :      378832 :       if (REAL_EXP (x) > fmt->emin && x->sig[SIGSZ - 1] == SIG_MSB)
    5399                 :             :         {
    5400                 :             :           int i;
    5401                 :      509002 :           for (i = SIGSZ - 2; i >= 0; i--)
    5402                 :      339867 :             if (x->sig[i])
    5403                 :             :               break;
    5404                 :      170732 :           if (i < 0)
    5405                 :             :             {
    5406                 :             :               /* When mantissa is 1.0, we need to subtract only
    5407                 :             :                  half of u: nextafter (1.0, 0.0) is 1.0 - __DBL_EPSILON__ / 2
    5408                 :             :                  rather than 1.0 - __DBL_EPSILON__.  */
    5409                 :      169135 :               clear_significand_bit (&u, np2);
    5410                 :      169135 :               np2--;
    5411                 :      169135 :               set_significand_bit (&u, np2);
    5412                 :             :             }
    5413                 :             :         }
    5414                 :      378832 :       sub_significands (r, x, &u, 0);
    5415                 :             :     }
    5416                 :             : 
    5417                 :             :   /* Clear out trailing garbage.  */
    5418                 :      732193 :   clear_significand_below (r, np2);
    5419                 :      732193 :   normalize (r);
    5420                 :      732193 :   if (REAL_EXP (r) <= fmt->emin - fmt->p)
    5421                 :             :     {
    5422                 :           0 :       get_zero (r, x->sign);
    5423                 :           0 :       return true;
    5424                 :             :     }
    5425                 :      732193 :   return r->cl == rvc_zero || REAL_EXP (r) < fmt->emin;
    5426                 :             : }
    5427                 :             : 
    5428                 :             : /* Write into BUF the maximum representable finite floating-point
    5429                 :             :    number, (1 - b**-p) * b**emax for a given FP format FMT as a hex
    5430                 :             :    float string.  LEN is the size of BUF, and the buffer must be large
    5431                 :             :    enough to contain the resulting string.  If NORM_MAX, instead write
    5432                 :             :    the maximum representable finite normalized floating-point number,
    5433                 :             :    defined to be such that all choices of digits for that exponent are
    5434                 :             :    representable in the format (this only makes a difference for IBM
    5435                 :             :    long double).  */
    5436                 :             : 
    5437                 :             : void
    5438                 :    25715561 : get_max_float (const struct real_format *fmt, char *buf, size_t len,
    5439                 :             :                bool norm_max)
    5440                 :             : {
    5441                 :    25715561 :   int i, n;
    5442                 :    25715561 :   char *p;
    5443                 :    25715561 :   bool is_ibm_extended = fmt->pnan < fmt->p;
    5444                 :             : 
    5445                 :    25715561 :   strcpy (buf, "0x0.");
    5446                 :    25715561 :   n = fmt->p;
    5447                 :   358045537 :   for (i = 0, p = buf + 4; i + 3 < n; i += 4)
    5448                 :   332329976 :     *p++ = 'f';
    5449                 :    25715561 :   if (i < n)
    5450                 :    12281384 :     *p++ = "08ce"[n - i];
    5451                 :    25715561 :   sprintf (p, "p%d",
    5452                 :    25715561 :            (is_ibm_extended && norm_max) ? fmt->emax - 1 : fmt->emax);
    5453                 :    25715561 :   if (is_ibm_extended && !norm_max)
    5454                 :             :     {
    5455                 :             :       /* This is an IBM extended double format made up of two IEEE
    5456                 :             :          doubles.  The value of the long double is the sum of the
    5457                 :             :          values of the two parts.  The most significant part is
    5458                 :             :          required to be the value of the long double rounded to the
    5459                 :             :          nearest double.  Rounding means we need a slightly smaller
    5460                 :             :          value for LDBL_MAX.  */
    5461                 :           0 :       buf[4 + fmt->pnan / 4] = "7bde"[fmt->pnan % 4];
    5462                 :             :     }
    5463                 :             : 
    5464                 :    25715561 :   gcc_assert (strlen (buf) < len);
    5465                 :    25715561 : }
    5466                 :             : 
    5467                 :             : /* True if all values of integral type can be represented
    5468                 :             :    by this floating-point type exactly.  */
    5469                 :             : 
    5470                 :       90182 : bool format_helper::can_represent_integral_type_p (tree type) const
    5471                 :             : {
    5472                 :      180364 :   gcc_assert (! decimal_p () && INTEGRAL_TYPE_P (type));
    5473                 :             : 
    5474                 :             :   /* INT?_MIN is power-of-two so it takes
    5475                 :             :      only one mantissa bit.  */
    5476                 :       90182 :   bool signed_p = TYPE_SIGN (type) == SIGNED;
    5477                 :       90182 :   return TYPE_PRECISION (type) - signed_p <= significand_size (*this);
    5478                 :             : }
    5479                 :             : 
    5480                 :             : /* True if mode M has a NaN representation and
    5481                 :             :    the treatment of NaN operands is important.  */
    5482                 :             : 
    5483                 :             : bool
    5484                 :  1099113935 : HONOR_NANS (machine_mode m)
    5485                 :             : {
    5486                 :  2075737753 :   return MODE_HAS_NANS (m) && !flag_finite_math_only;
    5487                 :             : }
    5488                 :             : 
    5489                 :             : bool
    5490                 :   367565324 : HONOR_NANS (const_tree t)
    5491                 :             : {
    5492                 :   367565324 :   return HONOR_NANS (element_mode (t));
    5493                 :             : }
    5494                 :             : 
    5495                 :             : bool
    5496                 :   543115221 : HONOR_NANS (const_rtx x)
    5497                 :             : {
    5498                 :   543115221 :   return HONOR_NANS (GET_MODE (x));
    5499                 :             : }
    5500                 :             : 
    5501                 :             : /* Like HONOR_NANs, but true if we honor signaling NaNs (or sNaNs).  */
    5502                 :             : 
    5503                 :             : bool
    5504                 :   374145543 : HONOR_SNANS (machine_mode m)
    5505                 :             : {
    5506                 :   374145543 :   return flag_signaling_nans && HONOR_NANS (m);
    5507                 :             : }
    5508                 :             : 
    5509                 :             : bool
    5510                 :    41928129 : HONOR_SNANS (const_tree t)
    5511                 :             : {
    5512                 :    41928129 :   return HONOR_SNANS (element_mode (t));
    5513                 :             : }
    5514                 :             : 
    5515                 :             : bool
    5516                 :    81357351 : HONOR_SNANS (const_rtx x)
    5517                 :             : {
    5518                 :    81357351 :   return HONOR_SNANS (GET_MODE (x));
    5519                 :             : }
    5520                 :             : 
    5521                 :             : /* As for HONOR_NANS, but true if the mode can represent infinity and
    5522                 :             :    the treatment of infinite values is important.  */
    5523                 :             : 
    5524                 :             : bool
    5525                 :   318511884 : HONOR_INFINITIES (machine_mode m)
    5526                 :             : {
    5527                 :  1274038920 :   return MODE_HAS_INFINITIES (m) && !flag_finite_math_only;
    5528                 :             : }
    5529                 :             : 
    5530                 :             : bool
    5531                 :   318504150 : HONOR_INFINITIES (const_tree t)
    5532                 :             : {
    5533                 :   318504150 :   return HONOR_INFINITIES (element_mode (t));
    5534                 :             : }
    5535                 :             : 
    5536                 :             : bool
    5537                 :           0 : HONOR_INFINITIES (const_rtx x)
    5538                 :             : {
    5539                 :           0 :   return HONOR_INFINITIES (GET_MODE (x));
    5540                 :             : }
    5541                 :             : 
    5542                 :             : /* Like HONOR_NANS, but true if the given mode distinguishes between
    5543                 :             :    positive and negative zero, and the sign of zero is important.  */
    5544                 :             : 
    5545                 :             : bool
    5546                 :   418442068 : HONOR_SIGNED_ZEROS (machine_mode m)
    5547                 :             : {
    5548                 :   626675118 :   return MODE_HAS_SIGNED_ZEROS (m) && flag_signed_zeros;
    5549                 :             : }
    5550                 :             : 
    5551                 :             : bool
    5552                 :   107208262 : HONOR_SIGNED_ZEROS (const_tree t)
    5553                 :             : {
    5554                 :   107208262 :   return HONOR_SIGNED_ZEROS (element_mode (t));
    5555                 :             : }
    5556                 :             : 
    5557                 :             : bool
    5558                 :      642117 : HONOR_SIGNED_ZEROS (const_rtx x)
    5559                 :             : {
    5560                 :      642117 :   return HONOR_SIGNED_ZEROS (GET_MODE (x));
    5561                 :             : }
    5562                 :             : 
    5563                 :             : /* Like HONOR_NANS, but true if given mode supports sign-dependent rounding,
    5564                 :             :    and the rounding mode is important.  */
    5565                 :             : 
    5566                 :             : bool
    5567                 :   290710394 : HONOR_SIGN_DEPENDENT_ROUNDING (machine_mode m)
    5568                 :             : {
    5569                 :   401792220 :   return MODE_HAS_SIGN_DEPENDENT_ROUNDING (m) && flag_rounding_math;
    5570                 :             : }
    5571                 :             : 
    5572                 :             : bool
    5573                 :    36384938 : HONOR_SIGN_DEPENDENT_ROUNDING (const_tree t)
    5574                 :             : {
    5575                 :    36384938 :   return HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (t));
    5576                 :             : }
    5577                 :             : 
    5578                 :             : bool
    5579                 :           0 : HONOR_SIGN_DEPENDENT_ROUNDING (const_rtx x)
    5580                 :             : {
    5581                 :           0 :   return HONOR_SIGN_DEPENDENT_ROUNDING (GET_MODE (x));
    5582                 :             : }
    5583                 :             : 
    5584                 :             : /* Fills r with the largest value such that 1 + r*r won't overflow.
    5585                 :             :    This is used in both sin (atan (x)) and cos (atan(x)) optimizations. */
    5586                 :             : 
    5587                 :             : void
    5588                 :         102 : build_sinatan_real (REAL_VALUE_TYPE * r, tree type)
    5589                 :             : {
    5590                 :         102 :   REAL_VALUE_TYPE maxval;
    5591                 :         102 :   mpfr_t mpfr_const1, mpfr_c, mpfr_maxval;
    5592                 :         102 :   machine_mode mode = TYPE_MODE (type);
    5593                 :         102 :   const struct real_format * fmt = REAL_MODE_FORMAT (mode);
    5594                 :             : 
    5595                 :         102 :   real_maxval (&maxval, 0, mode);
    5596                 :             : 
    5597                 :         102 :   mpfr_inits (mpfr_const1, mpfr_c, mpfr_maxval, NULL);
    5598                 :             : 
    5599                 :         102 :   mpfr_from_real (mpfr_const1, &dconst1, MPFR_RNDN);
    5600                 :         102 :   mpfr_from_real (mpfr_maxval, &maxval,  MPFR_RNDN);
    5601                 :             : 
    5602                 :         102 :   mpfr_sub (mpfr_c, mpfr_maxval, mpfr_const1, MPFR_RNDN);
    5603                 :         102 :   mpfr_sqrt (mpfr_c, mpfr_c, MPFR_RNDZ);
    5604                 :             : 
    5605                 :         102 :   real_from_mpfr (r, mpfr_c, fmt, MPFR_RNDZ);
    5606                 :             :   
    5607                 :         102 :   mpfr_clears (mpfr_const1, mpfr_c, mpfr_maxval, NULL);
    5608                 :         102 : }
        

Generated by: LCOV version 2.0-1

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.