home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
gas-1.38-src.lha
/
src
/
amiga
/
gas-1.38
/
atof-vax.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-22
|
14KB
|
514 lines
/* atof_vax.c - turn a Flonum into a VAX 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. */
/* JF added these two for md_atof() */
#include "as.h"
#include "read.h"
#include "flonum.h"
/* Precision in LittleNums. */
#define MAX_PRECISION (8)
#define H_PRECISION (8)
#define G_PRECISION (4)
#define D_PRECISION (4)
#define F_PRECISION (2)
/* Length in LittleNums of guard bits. */
#define GUARD (2)
int /* Number of chars in flonum type 'letter'. */
atof_vax_sizeof (letter)
char letter;
{
int return_value;
/*
* Permitting uppercase letters is probably a bad idea.
* Please use only lower-cased letters in case the upper-cased
* ones become unsupported!
*/
switch (letter)
{
case 'f':
case 'F':
return_value = 4;
break;
case 'd':
case 'D':
case 'g':
case 'G':
return_value = 8;
break;
case 'h':
case 'H':
return_value = 16;
break;
default:
return_value = 0;
break;
}
return (return_value);
} /* atof_vax_sizeof */
static const long int 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
};
/* Shared between flonum_gen2vax and next_bits */
static int bits_left_in_littlenum;
static LITTLENUM_TYPE * littlenum_pointer;
static LITTLENUM_TYPE * littlenum_end;
static int
next_bits (number_of_bits)
int number_of_bits;
{
int return_value;
if(littlenum_pointer<littlenum_end)
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;
bits_left_in_littlenum = LITTLENUM_NUMBER_OF_BITS - number_of_bits;
littlenum_pointer --;
if(littlenum_pointer>=littlenum_end)
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);
}
static void
make_invalid_floating_point_number (words)
LITTLENUM_TYPE * words;
{
* words = 0x8000; /* Floating Reserved Operand Code */
}
static int /* 0 means letter is OK. */
what_kind_of_float (letter, precisionP, exponent_bitsP)
char letter; /* In: lowercase please. What kind of float? */
int * precisionP; /* Number of 16-bit words in the float. */
long int * exponent_bitsP; /* Number of exponent bits. */
{
int retval; /* 0: OK. */
retval = 0;
switch (letter)
{
case 'f':
* precisionP = F_PRECISION;
* exponent_bitsP = 8;
break;
case 'd':
* precisionP = D_PRECISION;
* exponent_bitsP = 8;
break;
case 'g':
* precisionP = G_PRECISION;
* exponent_bitsP = 11;
break;
case 'h':
* precisionP = H_PRECISION;
* exponent_bitsP = 15;
break;
default:
retval = 69;
break;
}
return (retval);
}
/***********************************************************************\
* *
* Warning: this returns 16-bit LITTLENUMs, because that is *
* what the VAX thinks in. 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! *
* *
\***********************************************************************/
char * /* Return pointer past text consumed. */
atof_vax (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. */
{
FLONUM_TYPE f;
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. */
char * return_value;
int precision; /* Number of 16-bit words in the format. */
long int exponent_bits;
return_value = str;
f . low = bits + MAX_PRECISION;
f . high = NULL;
f . leader = NULL;
f . exponent = NULL;
f . sign = '\0';
if (what_kind_of_float (what_kind, & precision, & exponent_bits))
{
return_value = NULL; /* We lost. */
make_invalid_floating_point_number (words);
}
if (return_value)
{
bzero (bits, sizeof(LITTLENUM_TYPE) * MAX_PRECISION);
/* Use more LittleNums than seems */
/* necessary: the highest flonum may have */
/* 15 leading 0 bits, so could be useless. */
f . high = f . low + precision - 1 + GUARD;
if (atof_generic (& return_value, ".", "eE", & f))
{
make_invalid_floating_point_number (words);
return_value = NULL; /* we lost */
}
else
{
if (flonum_gen2vax (what_kind, & f, words))
{
return_value = NULL;
}
}
}
return (return_value);
}
/*
* In: a flonum, a vax floating point format.
* Out: a vax floating-point bit pattern.
*/
int /* 0: OK. */
flonum_gen2vax (format_letter, f, words)
char format_letter; /* One of 'd' 'f' 'g' 'h'. */
FLONUM_TYPE * f;
LITTLENUM_TYPE * words; /* Deliver answer here. */
{
LITTLENUM_TYPE * lp;
int precision;
long int exponent_bits;
int return_value; /* 0 == OK. */
return_value = what_kind_of_float (format_letter, & precision, & exponent_bits);
if (return_value != 0)
{
make_invalid_floating_point_number (words);
}
else
{
if (f -> low > f -> leader)
{
/* 0.0e0 seen. */
bzero (words, sizeof(LITTLENUM_TYPE) * precision);
}
else
{
long int exponent_1;
long int exponent_2;
long int exponent_3;
long int exponent_4;
int exponent_skippage;
LITTLENUM_TYPE word1;
/* JF: Deal with new Nan, +Inf and -Inf codes */
if(f->sign!='-' && f->sign!='+') {
make_invalid_floating_point_number(words);
return return_value;
}
/*
* All vaxen floating_point formats (so far) 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 are the next most significant bits.
* And so on for each other word.
*
* All this to be compatible with a KF11?? (Which is still faster
* than lots of vaxen I can think of, but it also has higher
* maintenance costs ... sigh).
*
* So we need: number of bits of exponent, number of bits of
* mantissa.
*/
#ifdef NEVER /******* This zeroing seems redundant - Dean 3may86 **********/
/*
* No matter how few bits we got back from the atof()
* routine, add enough zero littlenums so the rest of the
* code won't run out of "significant" bits in the mantissa.
*/
{
LITTLENUM_TYPE * ltp;
for (ltp = f -> leader + 1;
ltp <= f -> low + precision;
ltp ++)
{
* ltp = 0;
}
}
#endif
bits_left_in_littlenum = LITTLENUM_NUMBER_OF_BITS;
littlenum_pointer = f -> leader;
littlenu