Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* atof_ieee.c - turn a Flonum into an IEEE floating point number
  2.    Copyright 1987, 1992, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2005,
  3.    2007, 2009  Free Software Foundation, Inc.
  4.  
  5.    This file is part of GAS, the GNU Assembler.
  6.  
  7.    GAS is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3, or (at your option)
  10.    any later version.
  11.  
  12.    GAS is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with GAS; see the file COPYING.  If not, write to the Free
  19.    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  20.    02110-1301, USA.  */
  21.  
  22. #include "as.h"
  23.  
  24. /* Flonums returned here.  */
  25. extern FLONUM_TYPE generic_floating_point_number;
  26.  
  27. extern const char EXP_CHARS[];
  28. /* Precision in LittleNums.  */
  29. /* Don't count the gap in the m68k extended precision format.  */
  30. #define MAX_PRECISION  5
  31. #define F_PRECISION    2
  32. #define D_PRECISION    4
  33. #define X_PRECISION    5
  34. #define P_PRECISION    5
  35.  
  36. /* Length in LittleNums of guard bits.  */
  37. #define GUARD          2
  38.  
  39. #ifndef TC_LARGEST_EXPONENT_IS_NORMAL
  40. #define TC_LARGEST_EXPONENT_IS_NORMAL(PRECISION) 0
  41. #endif
  42.  
  43. static const unsigned long mask[] =
  44. {
  45.   0x00000000,
  46.   0x00000001,
  47.   0x00000003,
  48.   0x00000007,
  49.   0x0000000f,
  50.   0x0000001f,
  51.   0x0000003f,
  52.   0x0000007f,
  53.   0x000000ff,
  54.   0x000001ff,
  55.   0x000003ff,
  56.   0x000007ff,
  57.   0x00000fff,
  58.   0x00001fff,
  59.   0x00003fff,
  60.   0x00007fff,
  61.   0x0000ffff,
  62.   0x0001ffff,
  63.   0x0003ffff,
  64.   0x0007ffff,
  65.   0x000fffff,
  66.   0x001fffff,
  67.   0x003fffff,
  68.   0x007fffff,
  69.   0x00ffffff,
  70.   0x01ffffff,
  71.   0x03ffffff,
  72.   0x07ffffff,
  73.   0x0fffffff,
  74.   0x1fffffff,
  75.   0x3fffffff,
  76.   0x7fffffff,
  77.   0xffffffff,
  78. };
  79. static int bits_left_in_littlenum;
  80. static int littlenums_left;
  81. static LITTLENUM_TYPE *littlenum_pointer;
  82.  
  83. static int
  84. next_bits (int number_of_bits)
  85. {
  86.   int return_value;
  87.  
  88.   if (!littlenums_left)
  89.     return 0;
  90.  
  91.   if (number_of_bits >= bits_left_in_littlenum)
  92.     {
  93.       return_value = mask[bits_left_in_littlenum] & *littlenum_pointer;
  94.       number_of_bits -= bits_left_in_littlenum;
  95.       return_value <<= number_of_bits;
  96.  
  97.       if (--littlenums_left)
  98.         {
  99.           bits_left_in_littlenum = LITTLENUM_NUMBER_OF_BITS - number_of_bits;
  100.           --littlenum_pointer;
  101.           return_value |=
  102.             (*littlenum_pointer >> bits_left_in_littlenum)
  103.             & mask[number_of_bits];
  104.         }
  105.     }
  106.   else
  107.     {
  108.       bits_left_in_littlenum -= number_of_bits;
  109.       return_value =
  110.         mask[number_of_bits] & (*littlenum_pointer >> bits_left_in_littlenum);
  111.     }
  112.   return return_value;
  113. }
  114.  
  115. /* Num had better be less than LITTLENUM_NUMBER_OF_BITS.  */
  116.  
  117. static void
  118. unget_bits (int num)
  119. {
  120.   if (!littlenums_left)
  121.     {
  122.       ++littlenum_pointer;
  123.       ++littlenums_left;
  124.       bits_left_in_littlenum = num;
  125.     }
  126.   else if (bits_left_in_littlenum + num > LITTLENUM_NUMBER_OF_BITS)
  127.     {
  128.       bits_left_in_littlenum =
  129.         num - (LITTLENUM_NUMBER_OF_BITS - bits_left_in_littlenum);
  130.       ++littlenum_pointer;
  131.       ++littlenums_left;
  132.     }
  133.   else
  134.     bits_left_in_littlenum += num;
  135. }
  136.  
  137. static void
  138. make_invalid_floating_point_number (LITTLENUM_TYPE *words)
  139. {
  140.   as_bad (_("cannot create floating-point number"));
  141.   /* Zero the leftmost bit.  */
  142.   words[0] = (LITTLENUM_TYPE) ((unsigned) -1) >> 1;
  143.   words[1] = (LITTLENUM_TYPE) -1;
  144.   words[2] = (LITTLENUM_TYPE) -1;
  145.   words[3] = (LITTLENUM_TYPE) -1;
  146.   words[4] = (LITTLENUM_TYPE) -1;
  147.   words[5] = (LITTLENUM_TYPE) -1;
  148. }
  149. /* Warning: This returns 16-bit LITTLENUMs.  It is up to the caller to
  150.    figure out any alignment problems and to conspire for the
  151.    bytes/word to be emitted in the right order.  Bigendians beware!  */
  152.  
  153. /* Note that atof-ieee always has X and P precisions enabled.  it is up
  154.    to md_atof to filter them out if the target machine does not support
  155.    them.  */
  156.  
  157. /* Returns pointer past text consumed.  */
  158.  
  159. char *
  160. atof_ieee (char *str,                   /* Text to convert to binary.  */
  161.            int what_kind,               /* 'd', 'f', 'x', 'p'.  */
  162.            LITTLENUM_TYPE *words)       /* Build the binary here.  */
  163. {
  164.   /* Extra bits for zeroed low-order bits.
  165.      The 1st MAX_PRECISION are zeroed, the last contain flonum bits.  */
  166.   static LITTLENUM_TYPE bits[MAX_PRECISION + MAX_PRECISION + GUARD];
  167.   char *return_value;
  168.   /* Number of 16-bit words in the format.  */
  169.   int precision;
  170.   long exponent_bits;
  171.   FLONUM_TYPE save_gen_flonum;
  172.  
  173.   /* We have to save the generic_floating_point_number because it
  174.      contains storage allocation about the array of LITTLENUMs where
  175.      the value is actually stored.  We will allocate our own array of
  176.      littlenums below, but have to restore the global one on exit.  */
  177.   save_gen_flonum = generic_floating_point_number;
  178.  
  179.   return_value = str;
  180.   generic_floating_point_number.low = bits + MAX_PRECISION;
  181.   generic_floating_point_number.high = NULL;
  182.   generic_floating_point_number.leader = NULL;
  183.   generic_floating_point_number.exponent = 0;
  184.   generic_floating_point_number.sign = '\0';
  185.  
  186.   /* Use more LittleNums than seems necessary: the highest flonum may
  187.      have 15 leading 0 bits, so could be useless.  */
  188.  
  189.   memset (bits, '\0', sizeof (LITTLENUM_TYPE) * MAX_PRECISION);
  190.  
  191.   switch (what_kind)
  192.     {
  193.     case 'f':
  194.     case 'F':
  195.     case 's':
  196.     case 'S':
  197.       precision = F_PRECISION;
  198.       exponent_bits = 8;
  199.       break;
  200.  
  201.     case 'd':
  202.     case 'D':
  203.     case 'r':
  204.     case 'R':
  205.       precision = D_PRECISION;
  206.       exponent_bits = 11;
  207.       break;
  208.  
  209.     case 'x':
  210.     case 'X':
  211.     case 'e':
  212.     case 'E':
  213.       precision = X_PRECISION;
  214.       exponent_bits = 15;
  215.       break;
  216.  
  217.     case 'p':
  218.     case 'P':
  219.       precision = P_PRECISION;
  220.       exponent_bits = -1;
  221.       break;
  222.  
  223.     default:
  224.       make_invalid_floating_point_number (words);
  225.       return (NULL);
  226.     }
  227.  
  228.   generic_floating_point_number.high
  229.     = generic_floating_point_number.low + precision - 1 + GUARD;
  230.  
  231.   if (atof_generic (&return_value, ".", EXP_CHARS,
  232.                     &generic_floating_point_number))
  233.     {
  234.       make_invalid_floating_point_number (words);
  235.       return NULL;
  236.     }
  237.   gen_to_words (words, precision, exponent_bits);
  238.  
  239.   /* Restore the generic_floating_point_number's storage alloc (and
  240.      everything else).  */
  241.   generic_floating_point_number = save_gen_flonum;
  242.  
  243.   return return_value;
  244. }
  245.  
  246. /* Turn generic_floating_point_number into a real float/double/extended.  */
  247.  
  248. int
  249. gen_to_words (LITTLENUM_TYPE *words, int precision, long exponent_bits)
  250. {
  251.   int return_value = 0;
  252.  
  253.   long exponent_1;
  254.   long exponent_2;
  255.   long exponent_3;
  256.   long exponent_4;
  257.   int exponent_skippage;
  258.   LITTLENUM_TYPE word1;
  259.   LITTLENUM_TYPE *lp;
  260.   LITTLENUM_TYPE *words_end;
  261.  
  262.   words_end = words + precision;
  263. #ifdef TC_M68K
  264.   if (precision == X_PRECISION)
  265.     /* On the m68k the extended precision format has a gap of 16 bits
  266.        between the exponent and the mantissa.  */
  267.     words_end++;
  268. #endif
  269.  
  270.   if (generic_floating_point_number.low > generic_floating_point_number.leader)
  271.     {
  272.       /* 0.0e0 seen.  */
  273.       if (generic_floating_point_number.sign == '+')
  274.         words[0] = 0x0000;
  275.       else
  276.         words[0] = 0x8000;
  277.       memset (&words[1], '\0',
  278.               (words_end - words - 1) * sizeof (LITTLENUM_TYPE));
  279.       return return_value;
  280.     }
  281.  
  282.   /* NaN:  Do the right thing.  */
  283.   if (generic_floating_point_number.sign == 0)
  284.     {
  285.       if (TC_LARGEST_EXPONENT_IS_NORMAL (precision))
  286.         as_warn (_("NaNs are not supported by this target\n"));
  287.       if (precision == F_PRECISION)
  288.         {
  289.           words[0] = 0x7fff;
  290.           words[1] = 0xffff;
  291.         }
  292.       else if (precision == X_PRECISION)
  293.         {
  294. #ifdef TC_M68K
  295.           words[0] = 0x7fff;
  296.           words[1] = 0;
  297.           words[2] = 0xffff;
  298.           words[3] = 0xffff;
  299.           words[4] = 0xffff;
  300.           words[5] = 0xffff;
  301. #else /* ! TC_M68K  */
  302. #ifdef TC_I386
  303.           words[0] = 0xffff;
  304.           words[1] = 0xc000;
  305.           words[2] = 0;
  306.           words[3] = 0;
  307.           words[4] = 0;
  308. #else /* ! TC_I386  */
  309.           abort ();
  310. #endif /* ! TC_I386  */
  311. #endif /* ! TC_M68K  */
  312.         }
  313.       else
  314.         {
  315.           words[0] = 0x7fff;
  316.           words[1] = 0xffff;
  317.           words[2] = 0xffff;
  318.           words[3] = 0xffff;
  319.         }
  320.       return return_value;
  321.     }
  322.   else if (generic_floating_point_number.sign == 'P')
  323.     {
  324.       if (TC_LARGEST_EXPONENT_IS_NORMAL (precision))
  325.         as_warn (_("Infinities are not supported by this target\n"));
  326.  
  327.       /* +INF:  Do the right thing.  */
  328.       if (precision == F_PRECISION)
  329.         {
  330.           words[0] = 0x7f80;
  331.           words[1] = 0;
  332.         }
  333.       else if (precision == X_PRECISION)
  334.         {
  335. #ifdef TC_M68K
  336.           words[0] = 0x7fff;
  337.           words[1] = 0;
  338.           words[2] = 0;
  339.           words[3] = 0;
  340.           words[4] = 0;
  341.           words[5] = 0;
  342. #else /* ! TC_M68K  */
  343. #ifdef TC_I386
  344.           words[0] = 0x7fff;
  345.           words[1] = 0x8000;
  346.           words[2] = 0;
  347.           words[3] = 0;
  348.           words[4] = 0;
  349. #else /* ! TC_I386  */
  350.           abort ();
  351. #endif /* ! TC_I386  */
  352. #endif /* ! TC_M68K  */
  353.         }
  354.       else
  355.         {
  356.           words[0] = 0x7ff0;
  357.           words[1] = 0;
  358.           words[2] = 0;
  359.           words[3] = 0;
  360.         }
  361.       return return_value;
  362.     }
  363.   else if (generic_floating_point_number.sign == 'N')
  364.     {
  365.       if (TC_LARGEST_EXPONENT_IS_NORMAL (precision))
  366.         as_warn (_("Infinities are not supported by this target\n"));
  367.  
  368.       /* Negative INF.  */
  369.       if (precision == F_PRECISION)
  370.         {
  371.           words[0] = 0xff80;
  372.           words[1] = 0x0;
  373.         }
  374.       else if (precision == X_PRECISION)
  375.         {
  376. #ifdef TC_M68K
  377.           words[0] = 0xffff;
  378.           words[1] = 0;
  379.           words[2] = 0;
  380.           words[3] = 0;
  381.           words[4] = 0;
  382.           words[5] = 0;
  383. #else /* ! TC_M68K  */
  384. #ifdef TC_I386
  385.           words[0] = 0xffff;
  386.           words[1] = 0x8000;
  387.           words[2] = 0;
  388.           words[3] = 0;
  389.           words[4] = 0;
  390. #else /* ! TC_I386  */
  391.           abort ();
  392. #endif /* ! TC_I386  */
  393. #endif /* ! TC_M68K  */
  394.         }
  395.       else
  396.         {
  397.           words[0] = 0xfff0;
  398.           words[1] = 0x0;
  399.           words[2] = 0x0;
  400.           words[3] = 0x0;
  401.         }
  402.       return return_value;
  403.     }
  404.  
  405.   /* The floating point formats we support have:
  406.      Bit 15 is sign bit.
  407.      Bits 14:n are excess-whatever exponent.
  408.      Bits n-1:0 (if any) are most significant bits of fraction.
  409.      Bits 15:0 of the next word(s) are the next most significant bits.
  410.  
  411.      So we need: number of bits of exponent, number of bits of
  412.      mantissa.  */
  413.   bits_left_in_littlenum = LITTLENUM_NUMBER_OF_BITS;
  414.   littlenum_pointer = generic_floating_point_number.leader;
  415.   littlenums_left = (1
  416.                      + generic_floating_point_number.leader
  417.                      - generic_floating_point_number.low);
  418.  
  419.   /* Seek (and forget) 1st significant bit.  */
  420.   for (exponent_skippage = 0; !next_bits (1); ++exponent_skippage);
  421.   exponent_1 = (generic_floating_point_number.exponent
  422.                 + generic_floating_point_number.leader
  423.                 + 1
  424.                 - generic_floating_point_number.low);
  425.  
  426.   /* Radix LITTLENUM_RADIX, point just higher than
  427.      generic_floating_point_number.leader.  */
  428.   exponent_2 = exponent_1 * LITTLENUM_NUMBER_OF_BITS;
  429.  
  430.   /* Radix 2.  */
  431.   exponent_3 = exponent_2 - exponent_skippage;
  432.  
  433.   /* Forget leading zeros, forget 1st bit.  */
  434.   exponent_4 = exponent_3 + ((1 << (exponent_bits - 1)) - 2);
  435.  
  436.   /* Offset exponent.  */
  437.   lp = words;
  438.  
  439.   /* Word 1.  Sign, exponent and perhaps high bits.  */
  440.   word1 = ((generic_floating_point_number.sign == '+')
  441.            ? 0
  442.            : (1 << (LITTLENUM_NUMBER_OF_BITS - 1)));
  443.  
  444.   /* Assume 2's complement integers.  */
  445.   if (exponent_4 <= 0)
  446.     {
  447.       int prec_bits;
  448.       int num_bits;
  449.  
  450.       unget_bits (1);
  451.       num_bits = -exponent_4;
  452.       prec_bits =
  453.         LITTLENUM_NUMBER_OF_BITS * precision - (exponent_bits + 1 + num_bits);
  454. #ifdef TC_I386
  455.       if (precision == X_PRECISION && exponent_bits == 15)
  456.         {
  457.           /* On the i386 a denormalized extended precision float is
  458.              shifted down by one, effectively decreasing the exponent
  459.              bias by one.  */
  460.           prec_bits -= 1;
  461.           num_bits += 1;
  462.         }
  463. #endif
  464.  
  465.       if (num_bits >= LITTLENUM_NUMBER_OF_BITS - exponent_bits)
  466.         {
  467.           /* Bigger than one littlenum.  */
  468.           num_bits -= (LITTLENUM_NUMBER_OF_BITS - 1) - exponent_bits;
  469.           *lp++ = word1;
  470.           if (num_bits + exponent_bits + 1
  471.               > precision * LITTLENUM_NUMBER_OF_BITS)
  472.             {
  473.               /* Exponent overflow.  */
  474.               make_invalid_floating_point_number (words);
  475.               return return_value;
  476.             }
  477. #ifdef TC_M68K
  478.           if (precision == X_PRECISION && exponent_bits == 15)
  479.             *lp++ = 0;
  480. #endif
  481.           while (num_bits >= LITTLENUM_NUMBER_OF_BITS)
  482.             {
  483.               num_bits -= LITTLENUM_NUMBER_OF_BITS;
  484.               *lp++ = 0;
  485.             }
  486.           if (num_bits)
  487.             *lp++ = next_bits (LITTLENUM_NUMBER_OF_BITS - (num_bits));
  488.         }
  489.       else
  490.         {
  491.           if (precision == X_PRECISION && exponent_bits == 15)
  492.             {
  493.               *lp++ = word1;
  494. #ifdef TC_M68K
  495.               *lp++ = 0;
  496. #endif
  497.               *lp++ = next_bits (LITTLENUM_NUMBER_OF_BITS - num_bits);
  498.             }
  499.           else
  500.             {
  501.               word1 |= next_bits ((LITTLENUM_NUMBER_OF_BITS - 1)
  502.                                   - (exponent_bits + num_bits));
  503.               *lp++ = word1;
  504.             }
  505.         }
  506.       while (lp < words_end)
  507.         *lp++ = next_bits (LITTLENUM_NUMBER_OF_BITS);
  508.  
  509.       /* Round the mantissa up, but don't change the number.  */
  510.       if (next_bits (1))
  511.         {
  512.           --lp;
  513.           if (prec_bits >= LITTLENUM_NUMBER_OF_BITS)
  514.             {
  515.               int n = 0;
  516.               int tmp_bits;
  517.  
  518.               n = 0;
  519.               tmp_bits = prec_bits;
  520.               while (tmp_bits > LITTLENUM_NUMBER_OF_BITS)
  521.                 {
  522.                   if (lp[n] != (LITTLENUM_TYPE) - 1)
  523.                     break;
  524.                   --n;
  525.                   tmp_bits -= LITTLENUM_NUMBER_OF_BITS;
  526.                 }
  527.               if (tmp_bits > LITTLENUM_NUMBER_OF_BITS
  528.                   || (lp[n] & mask[tmp_bits]) != mask[tmp_bits]
  529.                   || (prec_bits != (precision * LITTLENUM_NUMBER_OF_BITS
  530.                                     - exponent_bits - 1)
  531. #ifdef TC_I386
  532.                       /* An extended precision float with only the integer
  533.                          bit set would be invalid.  That must be converted
  534.                          to the smallest normalized number.  */
  535.                       && !(precision == X_PRECISION
  536.                            && prec_bits == (precision * LITTLENUM_NUMBER_OF_BITS
  537.                                             - exponent_bits - 2))
  538. #endif
  539.                       ))
  540.                 {
  541.                   unsigned long carry;
  542.  
  543.                   for (carry = 1; carry && (lp >= words); lp--)
  544.                     {
  545.                       carry = *lp + carry;
  546.                       *lp = carry;
  547.                       carry >>= LITTLENUM_NUMBER_OF_BITS;
  548.                     }
  549.                 }
  550.               else
  551.                 {
  552.                   /* This is an overflow of the denormal numbers.  We
  553.                      need to forget what we have produced, and instead
  554.                      generate the smallest normalized number.  */
  555.                   lp = words;
  556.                   word1 = ((generic_floating_point_number.sign == '+')
  557.                            ? 0
  558.                            : (1 << (LITTLENUM_NUMBER_OF_BITS - 1)));
  559.                   word1 |= (1
  560.                             << ((LITTLENUM_NUMBER_OF_BITS - 1)
  561.                                 - exponent_bits));
  562.                   *lp++ = word1;
  563. #ifdef TC_I386
  564.                   /* Set the integer bit in the extended precision format.
  565.                      This cannot happen on the m68k where the mantissa
  566.                      just overflows into the integer bit above.  */
  567.                   if (precision == X_PRECISION)
  568.                     *lp++ = 1 << (LITTLENUM_NUMBER_OF_BITS - 1);
  569. #endif
  570.                   while (lp < words_end)
  571.                     *lp++ = 0;
  572.                 }
  573.             }
  574.           else
  575.             *lp += 1;
  576.         }
  577.  
  578.       return return_value;
  579.     }
  580.   else if ((unsigned long) exponent_4 > mask[exponent_bits]
  581.            || (! TC_LARGEST_EXPONENT_IS_NORMAL (precision)
  582.                && (unsigned long) exponent_4 == mask[exponent_bits]))
  583.     {
  584.       /* Exponent overflow.  Lose immediately.  */
  585.  
  586.       /* We leave return_value alone: admit we read the
  587.          number, but return a floating exception
  588.          because we can't encode the number.  */
  589.       make_invalid_floating_point_number (words);
  590.       return return_value;
  591.     }
  592.   else
  593.     {
  594.       word1 |= (exponent_4 << ((LITTLENUM_NUMBER_OF_BITS - 1) - exponent_bits))
  595.         | next_bits ((LITTLENUM_NUMBER_OF_BITS - 1) - exponent_bits);
  596.     }
  597.  
  598.   *lp++ = word1;
  599.  
  600.   /* X_PRECISION is special: on the 68k, it has 16 bits of zero in the
  601.      middle.  Either way, it is then followed by a 1 bit.  */
  602.   if (exponent_bits == 15 && precision == X_PRECISION)
  603.     {
  604. #ifdef TC_M68K
  605.       *lp++ = 0;
  606. #endif
  607.       *lp++ = (1 << (LITTLENUM_NUMBER_OF_BITS - 1)
  608.                | next_bits (LITTLENUM_NUMBER_OF_BITS - 1));
  609.     }
  610.  
  611.   /* The rest of the words are just mantissa bits.  */
  612.   while (lp < words_end)
  613.     *lp++ = next_bits (LITTLENUM_NUMBER_OF_BITS);
  614.  
  615.   if (next_bits (1))
  616.     {
  617.       unsigned long carry;
  618.       /* Since the NEXT bit is a 1, round UP the mantissa.
  619.          The cunning design of these hidden-1 floats permits
  620.          us to let the mantissa overflow into the exponent, and
  621.          it 'does the right thing'. However, we lose if the
  622.          highest-order bit of the lowest-order word flips.
  623.          Is that clear?  */
  624.  
  625.       /* #if (sizeof(carry)) < ((sizeof(bits[0]) * BITS_PER_CHAR) + 2)
  626.          Please allow at least 1 more bit in carry than is in a LITTLENUM.
  627.          We need that extra bit to hold a carry during a LITTLENUM carry
  628.          propagation. Another extra bit (kept 0) will assure us that we
  629.          don't get a sticky sign bit after shifting right, and that
  630.          permits us to propagate the carry without any masking of bits.
  631.          #endif */
  632.       for (carry = 1, lp--; carry; lp--)
  633.         {
  634.           carry = *lp + carry;
  635.           *lp = carry;
  636.           carry >>= LITTLENUM_NUMBER_OF_BITS;
  637.           if (lp == words)
  638.             break;
  639.         }
  640.       if (precision == X_PRECISION && exponent_bits == 15)
  641.         {
  642.           /* Extended precision numbers have an explicit integer bit
  643.              that we may have to restore.  */
  644.           if (lp == words)
  645.             {
  646. #ifdef TC_M68K
  647.               /* On the m68k there is a gap of 16 bits.  We must
  648.                  explicitly propagate the carry into the exponent.  */
  649.               words[0] += words[1];
  650.               words[1] = 0;
  651.               lp++;
  652. #endif
  653.               /* Put back the integer bit.  */
  654.               lp[1] |= 1 << (LITTLENUM_NUMBER_OF_BITS - 1);
  655.             }
  656.         }
  657.       if ((word1 ^ *words) & (1 << (LITTLENUM_NUMBER_OF_BITS - 1)))
  658.         {
  659.           /* We leave return_value alone: admit we read the number,
  660.              but return a floating exception because we can't encode
  661.              the number.  */
  662.           *words &= ~(1 << (LITTLENUM_NUMBER_OF_BITS - 1));
  663.         }
  664.     }
  665.   return return_value;
  666. }
  667.  
  668. #ifdef TEST
  669. char *
  670. print_gen (gen)
  671.      FLONUM_TYPE *gen;
  672. {
  673.   FLONUM_TYPE f;
  674.   LITTLENUM_TYPE arr[10];
  675.   double dv;
  676.   float fv;
  677.   static char sbuf[40];
  678.  
  679.   if (gen)
  680.     {
  681.       f = generic_floating_point_number;
  682.       generic_floating_point_number = *gen;
  683.     }
  684.   gen_to_words (&arr[0], 4, 11);
  685.   memcpy (&dv, &arr[0], sizeof (double));
  686.   sprintf (sbuf, "%x %x %x %x %.14G   ", arr[0], arr[1], arr[2], arr[3], dv);
  687.   gen_to_words (&arr[0], 2, 8);
  688.   memcpy (&fv, &arr[0], sizeof (float));
  689.   sprintf (sbuf + strlen (sbuf), "%x %x %.12g\n", arr[0], arr[1], fv);
  690.  
  691.   if (gen)
  692.     generic_floating_point_number = f;
  693.  
  694.   return (sbuf);
  695. }
  696. #endif
  697.  
  698. extern const char FLT_CHARS[];
  699. #define MAX_LITTLENUMS 6
  700.  
  701. /* This is a utility function called from various tc-*.c files.  It
  702.    is here in order to reduce code duplication.
  703.    
  704.    Turn a string at input_line_pointer into a floating point constant
  705.    of type TYPE (a character found in the FLT_CHARS macro), and store
  706.    it as LITTLENUMS in the bytes buffer LITP.  The number of chars
  707.    emitted is stored in *SIZEP.  BIG_WORDIAN is TRUE if the littlenums
  708.    should be emitted most significant littlenum first.
  709.  
  710.    An error message is returned, or a NULL pointer if everything went OK.  */
  711.  
  712. char *
  713. ieee_md_atof (int type,
  714.               char *litP,
  715.               int *sizeP,
  716.               bfd_boolean big_wordian)
  717. {
  718.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  719.   LITTLENUM_TYPE *wordP;
  720.   char *t;
  721.   int prec = 0;
  722.  
  723.   if (strchr (FLT_CHARS, type) != NULL)
  724.     {
  725.       switch (type)
  726.         {
  727.         case 'f':
  728.         case 'F':
  729.         case 's':
  730.         case 'S':
  731.           prec = F_PRECISION;
  732.           break;
  733.  
  734.         case 'd':
  735.         case 'D':
  736.         case 'r':
  737.         case 'R':
  738.           prec = D_PRECISION;
  739.           break;
  740.  
  741.         case 't':
  742.         case 'T':
  743.           prec = X_PRECISION;
  744.           type = 'x';           /* This is what atof_ieee() understands.  */
  745.           break;
  746.  
  747.         case 'x':
  748.         case 'X':
  749.         case 'p':
  750.         case 'P':
  751. #ifdef TC_M68K
  752.           /* Note: on the m68k there is a gap of 16 bits (one littlenum)
  753.              between the exponent and mantissa.  Hence the precision is
  754.              6 and not 5.  */
  755.           prec = P_PRECISION + 1;
  756. #else
  757.           prec = P_PRECISION;
  758. #endif
  759.           break;
  760.  
  761.         default:
  762.           break;
  763.         }
  764.     }
  765.   /* The 'f' and 'd' types are always recognised, even if the target has
  766.      not put them into the FLT_CHARS macro.  This is because the 'f' type
  767.      can come from the .dc.s, .dcb.s, .float or .single pseudo-ops and the
  768.      'd' type from the .dc.d, .dbc.d or .double pseudo-ops.
  769.  
  770.      The 'x' type is not implicitly recongised however, even though it can
  771.      be generated by the .dc.x and .dbc.x pseudo-ops because not all targets
  772.      can support floating point values that big.  ie the target has to
  773.      explicitly allow them by putting them into FLT_CHARS.  */
  774.   else if (type == 'f')
  775.     prec = F_PRECISION;
  776.   else if (type == 'd')
  777.     prec = D_PRECISION;
  778.  
  779.   if (prec == 0)
  780.     {
  781.       *sizeP = 0;
  782.       return _("Unrecognized or unsupported floating point constant");
  783.     }
  784.  
  785.   gas_assert (prec <= MAX_LITTLENUMS);
  786.  
  787.   t = atof_ieee (input_line_pointer, type, words);
  788.   if (t)
  789.     input_line_pointer = t;
  790.  
  791.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  792.  
  793.   if (big_wordian)
  794.     {
  795.       for (wordP = words; prec --;)
  796.         {
  797.           md_number_to_chars (litP, (valueT) (* wordP ++), sizeof (LITTLENUM_TYPE));
  798.           litP += sizeof (LITTLENUM_TYPE);
  799.         }
  800.     }
  801.   else
  802.     {
  803.       for (wordP = words + prec; prec --;)
  804.         {
  805.           md_number_to_chars (litP, (valueT) (* -- wordP), sizeof (LITTLENUM_TYPE));
  806.           litP += sizeof (LITTLENUM_TYPE);
  807.         }
  808.     }
  809.  
  810.   return NULL;
  811. }
  812.