diff options
author | K. Richard Pixley <rich@cygnus> | 1992-02-13 08:33:54 +0000 |
---|---|---|
committer | K. Richard Pixley <rich@cygnus> | 1992-02-13 08:33:54 +0000 |
commit | a39116f1c91d3642c068d9df871338cca9006be2 (patch) | |
tree | dbd53d94ef859ca6425ef5370573030d4766161b /gas/config/atof-ieee.c | |
parent | 77806c3e79cc6ebd5ab62ce46f7cdeecad50ca52 (diff) | |
download | gdb-a39116f1c91d3642c068d9df871338cca9006be2.zip gdb-a39116f1c91d3642c068d9df871338cca9006be2.tar.gz gdb-a39116f1c91d3642c068d9df871338cca9006be2.tar.bz2 |
White space and comments only. The devo tree prior to this delta is
tagged as "vanilla" for your convenience.
There are also some comment changes.
Diffstat (limited to 'gas/config/atof-ieee.c')
-rw-r--r-- | gas/config/atof-ieee.c | 367 |
1 files changed, 191 insertions, 176 deletions
diff --git a/gas/config/atof-ieee.c b/gas/config/atof-ieee.c index 323d4e1..d9bf68b 100644 --- a/gas/config/atof-ieee.c +++ b/gas/config/atof-ieee.c @@ -1,21 +1,21 @@ /* atof_ieee.c - turn a Flonum into an IEEE floating point number Copyright (C) 1987 Free Software Foundation, Inc. - -This file is part of GAS, the GNU Assembler. - -GAS is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 1, or (at your option) -any later version. - -GAS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GAS; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + + This file is part of GAS, the GNU Assembler. + + GAS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GAS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GAS; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "as.h" @@ -31,51 +31,51 @@ extern FLONUM_TYPE generic_floating_point_number; /* Flonums returned here. */ #endif extern char EXP_CHARS[]; - /* Precision in LittleNums. */ +/* Precision in LittleNums. */ #define MAX_PRECISION (6) #define F_PRECISION (2) #define D_PRECISION (4) #define X_PRECISION (6) #define P_PRECISION (6) - /* Length in LittleNums of guard bits. */ +/* Length in LittleNums of guard bits. */ #define GUARD (2) static unsigned long mask [] = { - 0x00000000, - 0x00000001, - 0x00000003, - 0x00000007, - 0x0000000f, - 0x0000001f, - 0x0000003f, - 0x0000007f, - 0x000000ff, - 0x000001ff, - 0x000003ff, - 0x000007ff, - 0x00000fff, - 0x00001fff, - 0x00003fff, - 0x00007fff, - 0x0000ffff, - 0x0001ffff, - 0x0003ffff, - 0x0007ffff, - 0x000fffff, - 0x001fffff, - 0x003fffff, - 0x007fffff, - 0x00ffffff, - 0x01ffffff, - 0x03ffffff, - 0x07ffffff, - 0x0fffffff, - 0x1fffffff, - 0x3fffffff, - 0x7fffffff, - 0xffffffff - }; + 0x00000000, + 0x00000001, + 0x00000003, + 0x00000007, + 0x0000000f, + 0x0000001f, + 0x0000003f, + 0x0000007f, + 0x000000ff, + 0x000001ff, + 0x000003ff, + 0x000007ff, + 0x00000fff, + 0x00001fff, + 0x00003fff, + 0x00007fff, + 0x0000ffff, + 0x0001ffff, + 0x0003ffff, + 0x0007ffff, + 0x000fffff, + 0x001fffff, + 0x003fffff, + 0x007fffff, + 0x00ffffff, + 0x01ffffff, + 0x03ffffff, + 0x07ffffff, + 0x0fffffff, + 0x1fffffff, + 0x3fffffff, + 0x7fffffff, + 0xffffffff + }; static int bits_left_in_littlenum; @@ -83,35 +83,35 @@ static int littlenums_left; static LITTLENUM_TYPE *littlenum_pointer; static int -next_bits (number_of_bits) - int number_of_bits; + next_bits (number_of_bits) +int number_of_bits; { - int return_value; - - if(!littlenums_left) - return 0; - if (number_of_bits >= bits_left_in_littlenum) - { - return_value = mask [bits_left_in_littlenum] & *littlenum_pointer; - number_of_bits -= bits_left_in_littlenum; - return_value <<= number_of_bits; - if(--littlenums_left) { - bits_left_in_littlenum = LITTLENUM_NUMBER_OF_BITS - number_of_bits; - littlenum_pointer --; - return_value |= (*littlenum_pointer>>bits_left_in_littlenum) & mask[number_of_bits]; - } - } - else - { - bits_left_in_littlenum -= number_of_bits; - return_value = mask [number_of_bits] & (*littlenum_pointer>>bits_left_in_littlenum); - } - return (return_value); + int return_value; + + if(!littlenums_left) + return 0; + if (number_of_bits >= bits_left_in_littlenum) + { + return_value = mask [bits_left_in_littlenum] & *littlenum_pointer; + number_of_bits -= bits_left_in_littlenum; + return_value <<= number_of_bits; + if(--littlenums_left) { + bits_left_in_littlenum = LITTLENUM_NUMBER_OF_BITS - number_of_bits; + littlenum_pointer --; + return_value |= (*littlenum_pointer>>bits_left_in_littlenum) & mask[number_of_bits]; + } + } + else + { + bits_left_in_littlenum -= number_of_bits; + return_value = mask [number_of_bits] & (*littlenum_pointer>>bits_left_in_littlenum); + } + return (return_value); } /* Num had better be less than LITTLENUM_NUMBER_OF_BITS */ static void -unget_bits(num) + unget_bits(num) int num; { if(!littlenums_left) { @@ -123,12 +123,12 @@ int num; ++littlenum_pointer; ++littlenums_left; } else - bits_left_in_littlenum+=num; + bits_left_in_littlenum+=num; } static void -make_invalid_floating_point_number (words) - LITTLENUM_TYPE * words; + make_invalid_floating_point_number (words) +LITTLENUM_TYPE * words; { as_bad("cannot create floating-point number"); words[0]= ((unsigned)-1)>>1; /* Zero the leftmost bit */ @@ -140,43 +140,51 @@ make_invalid_floating_point_number (words) } /***********************************************************************\ -* Warning: this returns 16-bit LITTLENUMs. It is up to the caller * -* to figure out any alignment problems and to conspire for the * -* bytes/word to be emitted in the right order. Bigendians beware! * -* * -\***********************************************************************/ + * Warning: this returns 16-bit LITTLENUMs. It is up to the caller * + * to figure out any alignment problems and to conspire for the * + * bytes/word to be emitted in the right order. Bigendians beware! * + * * + \***********************************************************************/ /* Note that atof-ieee always has X and P precisions enabled. it is up to md_atof to filter them out if the target machine does not support them. */ char * /* Return pointer past text consumed. */ -atof_ieee (str, what_kind, words) - char * str; /* Text to convert to binary. */ - char what_kind; /* 'd', 'f', 'g', 'h' */ - LITTLENUM_TYPE * words; /* Build the binary here. */ + atof_ieee (str, what_kind, words) +char * str; /* Text to convert to binary. */ +char what_kind; /* 'd', 'f', 'g', 'h' */ +LITTLENUM_TYPE * words; /* Build the binary here. */ { static LITTLENUM_TYPE bits [MAX_PRECISION + MAX_PRECISION + GUARD]; - /* Extra bits for zeroed low-order bits. */ - /* The 1st MAX_PRECISION are zeroed, */ - /* the last contain flonum bits. */ + /* Extra bits for zeroed low-order bits. */ + /* The 1st MAX_PRECISION are zeroed, */ + /* the last contain flonum bits. */ char * return_value; int precision; /* Number of 16-bit words in the format. */ long exponent_bits; - + FLONUM_TYPE save_gen_flonum; + + /* We have to save the generic_floating_point_number because it + contains storage allocation about the array of LITTLENUMs + where the value is actually stored. We will allocate our + own array of littlenums below, but have to restore the global + one on exit. */ + save_gen_flonum = generic_floating_point_number; + return_value = str; generic_floating_point_number.low = bits + MAX_PRECISION; generic_floating_point_number.high = NULL; generic_floating_point_number.leader = NULL; generic_floating_point_number.exponent = NULL; generic_floating_point_number.sign = '\0'; - - /* Use more LittleNums than seems */ - /* necessary: the highest flonum may have */ - /* 15 leading 0 bits, so could be useless. */ - + + /* Use more LittleNums than seems */ + /* necessary: the highest flonum may have */ + /* 15 leading 0 bits, so could be useless. */ + bzero (bits, sizeof(LITTLENUM_TYPE) * MAX_PRECISION); - + switch(what_kind) { case 'f': case 'F': @@ -185,7 +193,7 @@ atof_ieee (str, what_kind, words) precision = F_PRECISION; exponent_bits = 8; break; - + case 'd': case 'D': case 'r': @@ -193,7 +201,7 @@ atof_ieee (str, what_kind, words) precision = D_PRECISION; exponent_bits = 11; break; - + case 'x': case 'X': case 'e': @@ -201,27 +209,32 @@ atof_ieee (str, what_kind, words) precision = X_PRECISION; exponent_bits = 15; break; - + case 'p': case 'P': precision = P_PRECISION; exponent_bits= -1; break; - + default: make_invalid_floating_point_number (words); return NULL; } - + generic_floating_point_number.high = generic_floating_point_number.low + precision - 1 + GUARD; - + if (atof_generic (& return_value, ".", EXP_CHARS, & generic_floating_point_number)) { /* as_bad("Error converting floating point number (Exponent overflow?)"); */ make_invalid_floating_point_number (words); return NULL; } gen_to_words(words, precision, exponent_bits); + + /* Restore the generic_floating_point_number's storage alloc + (and everything else). */ + generic_floating_point_number = save_gen_flonum; + return return_value; } @@ -232,7 +245,7 @@ int precision; long exponent_bits; { int return_value=0; - + long exponent_1; long exponent_2; long exponent_3; @@ -240,17 +253,17 @@ long exponent_bits; int exponent_skippage; LITTLENUM_TYPE word1; LITTLENUM_TYPE * lp; - + if (generic_floating_point_number.low > generic_floating_point_number.leader) { /* 0.0e0 seen. */ if(generic_floating_point_number.sign=='+') - words[0]=0x0000; + words[0]=0x0000; else - words[0]=0x8000; + words[0]=0x8000; bzero (&words[1], sizeof(LITTLENUM_TYPE) * (precision-1)); return return_value; } - + /* NaN: Do the right thing */ if(generic_floating_point_number.sign==0) { if(precision==F_PRECISION) { @@ -288,24 +301,24 @@ long exponent_bits; } return return_value; } - /* - * The floating point formats we support have: - * Bit 15 is sign bit. - * Bits 14:n are excess-whatever exponent. - * Bits n-1:0 (if any) are most significant bits of fraction. - * Bits 15:0 of the next word(s) are the next most significant bits. - * - * So we need: number of bits of exponent, number of bits of - * mantissa. - */ + /* + * The floating point formats we support have: + * Bit 15 is sign bit. + * Bits 14:n are excess-whatever exponent. + * Bits n-1:0 (if any) are most significant bits of fraction. + * Bits 15:0 of the next word(s) are the next most significant bits. + * + * So we need: number of bits of exponent, number of bits of + * mantissa. + */ bits_left_in_littlenum = LITTLENUM_NUMBER_OF_BITS; littlenum_pointer = generic_floating_point_number.leader; littlenums_left = 1+generic_floating_point_number.leader - generic_floating_point_number.low; /* Seek (and forget) 1st significant bit */ for (exponent_skippage = 0;! next_bits(1); exponent_skippage ++) - ; + ; exponent_1 = generic_floating_point_number.exponent + generic_floating_point_number.leader + 1 - - generic_floating_point_number.low; + generic_floating_point_number.low; /* Radix LITTLENUM_RADIX, point just higher than generic_floating_point_number.leader. */ exponent_2 = exponent_1 * LITTLENUM_NUMBER_OF_BITS; /* Radix 2. */ @@ -313,23 +326,23 @@ long exponent_bits; /* Forget leading zeros, forget 1st bit. */ exponent_4 = exponent_3 + ((1 << (exponent_bits - 1)) - 2); /* Offset exponent. */ - + lp = words; - + /* Word 1. Sign, exponent and perhaps high bits. */ word1 = (generic_floating_point_number.sign == '+') ? 0 : (1<<(LITTLENUM_NUMBER_OF_BITS-1)); - + /* Assume 2's complement integers. */ if(exponent_4<1 && exponent_4>=-62) { int prec_bits; int num_bits; - + unget_bits(1); num_bits= -exponent_4; prec_bits=LITTLENUM_NUMBER_OF_BITS*precision-(exponent_bits+1+num_bits); if(precision==X_PRECISION && exponent_bits==15) - prec_bits-=LITTLENUM_NUMBER_OF_BITS+1; - + prec_bits-=LITTLENUM_NUMBER_OF_BITS+1; + if(num_bits>=LITTLENUM_NUMBER_OF_BITS-exponent_bits) { /* Bigger than one littlenum */ num_bits-=(LITTLENUM_NUMBER_OF_BITS-1)-exponent_bits; @@ -349,7 +362,7 @@ long exponent_bits; *lp++=0; } if(num_bits) - *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS-(num_bits)); + *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS-(num_bits)); } else { if(precision==X_PRECISION && exponent_bits==15) { *lp++=word1; @@ -358,9 +371,9 @@ long exponent_bits; *lp++=0; *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS-1); } else if(num_bits==LITTLENUM_NUMBER_OF_BITS-1) - *lp++=0; + *lp++=0; else - *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS-1-num_bits); + *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS-1-num_bits); num_bits=0; } else { word1|= next_bits ((LITTLENUM_NUMBER_OF_BITS-1) - (exponent_bits+num_bits)); @@ -368,26 +381,26 @@ long exponent_bits; } } while(lp<words+precision) - *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS); - + *lp++=next_bits(LITTLENUM_NUMBER_OF_BITS); + /* Round the mantissa up, but don't change the number */ if(next_bits(1)) { --lp; if(prec_bits>LITTLENUM_NUMBER_OF_BITS) { int n = 0; int tmp_bits; - + n=0; tmp_bits=prec_bits; while(tmp_bits>LITTLENUM_NUMBER_OF_BITS) { if(lp[n]!=(LITTLENUM_TYPE)-1) - break; + break; --n; tmp_bits-=LITTLENUM_NUMBER_OF_BITS; } if(tmp_bits>LITTLENUM_NUMBER_OF_BITS || (lp[n]&mask[tmp_bits])!=mask[tmp_bits]) { unsigned long carry; - + for (carry = 1; carry && (lp >= words); lp --) { carry = * lp + carry; * lp = carry; @@ -395,59 +408,59 @@ long exponent_bits; } } } else if((*lp&mask[prec_bits])!=mask[prec_bits]) - lp++; + lp++; } - + return return_value; } else if (exponent_4 & ~ mask [exponent_bits]) { - /* - * Exponent overflow. Lose immediately. - */ - - /* - * We leave return_value alone: admit we read the - * number, but return a floating exception - * because we can't encode the number. - */ + /* + * Exponent overflow. Lose immediately. + */ + + /* + * We leave return_value alone: admit we read the + * number, but return a floating exception + * because we can't encode the number. + */ make_invalid_floating_point_number (words); return return_value; } else { word1 |= (exponent_4 << ((LITTLENUM_NUMBER_OF_BITS-1) - exponent_bits)) - | next_bits ((LITTLENUM_NUMBER_OF_BITS-1) - exponent_bits); + | next_bits ((LITTLENUM_NUMBER_OF_BITS-1) - exponent_bits); } - + * lp ++ = word1; - + /* X_PRECISION is special: it has 16 bits of zero in the middle, followed by a 1 bit. */ if(exponent_bits==15 && precision==X_PRECISION) { *lp++=0; *lp++= 1<<(LITTLENUM_NUMBER_OF_BITS)|next_bits(LITTLENUM_NUMBER_OF_BITS-1); } - + /* The rest of the words are just mantissa bits. */ while(lp < words + precision) - *lp++ = next_bits (LITTLENUM_NUMBER_OF_BITS); - + *lp++ = next_bits (LITTLENUM_NUMBER_OF_BITS); + if (next_bits (1)) { unsigned long carry; - /* - * Since the NEXT bit is a 1, round UP the mantissa. - * The cunning design of these hidden-1 floats permits - * us to let the mantissa overflow into the exponent, and - * it 'does the right thing'. However, we lose if the - * highest-order bit of the lowest-order word flips. - * Is that clear? - */ - - -/* #if (sizeof(carry)) < ((sizeof(bits[0]) * BITS_PER_CHAR) + 2) - Please allow at least 1 more bit in carry than is in a LITTLENUM. - We need that extra bit to hold a carry during a LITTLENUM carry - propagation. Another extra bit (kept 0) will assure us that we - don't get a sticky sign bit after shifting right, and that - permits us to propagate the carry without any masking of bits. -#endif */ + /* + * Since the NEXT bit is a 1, round UP the mantissa. + * The cunning design of these hidden-1 floats permits + * us to let the mantissa overflow into the exponent, and + * it 'does the right thing'. However, we lose if the + * highest-order bit of the lowest-order word flips. + * Is that clear? + */ + + + /* #if (sizeof(carry)) < ((sizeof(bits[0]) * BITS_PER_CHAR) + 2) + Please allow at least 1 more bit in carry than is in a LITTLENUM. + We need that extra bit to hold a carry during a LITTLENUM carry + propagation. Another extra bit (kept 0) will assure us that we + don't get a sticky sign bit after shifting right, and that + permits us to propagate the carry without any masking of bits. + #endif */ for (carry = 1, lp --; carry && (lp >= words); lp --) { carry = * lp + carry; * lp = carry; @@ -469,23 +482,23 @@ long exponent_bits; /* This routine is a real kludge. Someone really should do it better, but I'm too lazy, and I don't understand this stuff all too well anyway (JF) - */ + */ void -int_to_gen(x) + int_to_gen(x) long x; { char buf[20]; char *bufp; - + sprintf(buf,"%ld",x); bufp= &buf[0]; if(atof_generic(&bufp,".", EXP_CHARS, &generic_floating_point_number)) - as_bad("Error converting number to floating point (Exponent overflow?)"); + as_bad("Error converting number to floating point (Exponent overflow?)"); } #ifdef TEST char * -print_gen(gen) + print_gen(gen) FLONUM_TYPE *gen; { FLONUM_TYPE f; @@ -493,7 +506,7 @@ FLONUM_TYPE *gen; double dv; float fv; static char sbuf[40]; - + if(gen) { f=generic_floating_point_number; generic_floating_point_number= *gen; @@ -505,7 +518,9 @@ FLONUM_TYPE *gen; bcopy(&arr[0],&fv,sizeof(float)); sprintf(sbuf+strlen(sbuf),"%x %x %.12g\n",arr[0],arr[1],fv); if(gen) - generic_floating_point_number=f; + generic_floating_point_number=f; return sbuf; } #endif + +/* end of atof-ieee.c */ |