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