binutils-gdb/gas/config/atof-vax.c

451 lines
12 KiB
C
Raw Normal View History

1999-05-03 15:29:11 +08:00
/* atof_vax.c - turn a Flonum into a VAX floating point number
Copyright (C) 1987-2024 Free Software Foundation, Inc.
1999-05-03 15:29:11 +08:00
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
2007-07-03 19:01:12 +08:00
the Free Software Foundation; either version 3, or (at your option)
1999-05-03 15:29:11 +08:00
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, 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
1999-05-03 15:29:11 +08:00
#include "as.h"
/* Precision in LittleNums. */
2005-03-23 19:18:14 +08:00
#define MAX_PRECISION 8
#define H_PRECISION 8
#define G_PRECISION 4
#define D_PRECISION 4
#define F_PRECISION 2
1999-05-03 15:29:11 +08:00
/* Length in LittleNums of guard bits. */
#define GUARD 2
1999-05-03 15:29:11 +08:00
2005-03-23 19:18:14 +08:00
int flonum_gen2vax (int, FLONUM_TYPE *, LITTLENUM_TYPE *);
1999-05-03 15:29:11 +08:00
/* Number of chars in flonum type 'letter'. */
2005-03-23 19:18:14 +08:00
static unsigned int
2005-03-23 19:18:14 +08:00
atof_vax_sizeof (int letter)
1999-05-03 15:29:11 +08:00
{
int return_value;
2005-03-23 19:18:14 +08:00
/* Permitting uppercase letters is probably a bad idea.
Please use only lower-cased letters in case the upper-cased
ones become unsupported! */
1999-05-03 15:29:11 +08:00
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;
}
2005-03-23 19:18:14 +08:00
return return_value;
}
1999-05-03 15:29:11 +08:00
static const 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
};
2005-03-23 19:18:14 +08:00
/* Shared between flonum_gen2vax and next_bits. */
1999-05-03 15:29:11 +08:00
static int bits_left_in_littlenum;
static LITTLENUM_TYPE *littlenum_pointer;
static LITTLENUM_TYPE *littlenum_end;
static int
2005-03-23 19:18:14 +08:00
next_bits (int number_of_bits)
1999-05-03 15:29:11 +08:00
{
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);
}
2005-03-23 19:18:14 +08:00
return return_value;
1999-05-03 15:29:11 +08:00
}
static void
2005-03-23 19:18:14 +08:00
make_invalid_floating_point_number (LITTLENUM_TYPE *words)
1999-05-03 15:29:11 +08:00
{
2005-03-23 19:18:14 +08:00
*words = 0x8000; /* Floating Reserved Operand Code. */
1999-05-03 15:29:11 +08:00
}
2005-03-23 19:18:14 +08:00
1999-05-03 15:29:11 +08:00
static int /* 0 means letter is OK. */
2005-03-23 19:18:14 +08:00
what_kind_of_float (int letter, /* In: lowercase please. What kind of float? */
int *precisionP, /* Number of 16-bit words in the float. */
long *exponent_bitsP) /* Number of exponent bits. */
1999-05-03 15:29:11 +08:00
{
2005-03-23 19:18:14 +08:00
int retval;
1999-05-03 15:29:11 +08:00
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;
}
2005-03-23 19:18:14 +08:00
return retval;
1999-05-03 15:29:11 +08:00
}
2005-03-23 19:18:14 +08:00
/* 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! */
static char *
atof_vax (char *str, /* Text to convert to binary. */
int what_kind, /* 'd', 'f', 'g', 'h' */
LITTLENUM_TYPE *words) /* Build the binary here. */
1999-05-03 15:29:11 +08:00
{
FLONUM_TYPE f;
LITTLENUM_TYPE bits[MAX_PRECISION + MAX_PRECISION + GUARD];
2005-03-23 19:18:14 +08:00
/* Extra bits for zeroed low-order bits.
The 1st MAX_PRECISION are zeroed,
the last contain flonum bits. */
1999-05-03 15:29:11 +08:00
char *return_value;
int precision; /* Number of 16-bit words in the format. */
1999-05-03 15:29:11 +08:00
long exponent_bits;
return_value = str;
f.low = bits + MAX_PRECISION;
f.high = NULL;
f.leader = NULL;
f.exponent = 0;
f.sign = '\0';
if (what_kind_of_float (what_kind, &precision, &exponent_bits))
{
2005-03-23 19:18:14 +08:00
return_value = NULL;
1999-05-03 15:29:11 +08:00
make_invalid_floating_point_number (words);
}
if (return_value)
{
memset (bits, '\0', sizeof (LITTLENUM_TYPE) * MAX_PRECISION);
2005-03-23 19:18:14 +08:00
/* Use more LittleNums than seems
necessary: the highest flonum may have
15 leading 0 bits, so could be useless. */
1999-05-03 15:29:11 +08:00
f.high = f.low + precision - 1 + GUARD;
if (atof_generic (&return_value, ".", "eE", &f))
{
make_invalid_floating_point_number (words);
2005-03-23 19:18:14 +08:00
return_value = NULL;
1999-05-03 15:29:11 +08:00
}
2005-03-23 19:18:14 +08:00
else if (flonum_gen2vax (what_kind, &f, words))
return_value = NULL;
1999-05-03 15:29:11 +08:00
}
2005-03-23 19:18:14 +08:00
return return_value;
}
1999-05-03 15:29:11 +08:00
2005-03-23 19:18:14 +08:00
/* In: a flonum, a vax floating point format.
Out: a vax floating-point bit pattern. */
int
flonum_gen2vax (int format_letter, /* One of 'd' 'f' 'g' 'h'. */
FLONUM_TYPE *f,
LITTLENUM_TYPE *words) /* Deliver answer here. */
1999-05-03 15:29:11 +08:00
{
LITTLENUM_TYPE *lp;
int precision;
long exponent_bits;
int return_value; /* 0 == OK. */
1999-05-03 15:29:11 +08:00
return_value = what_kind_of_float (format_letter, &precision, &exponent_bits);
if (return_value != 0)
2005-03-23 19:18:14 +08:00
make_invalid_floating_point_number (words);
1999-05-03 15:29:11 +08:00
else
{
if (f->low > f->leader)
2005-03-23 19:18:14 +08:00
/* 0.0e0 seen. */
memset (words, '\0', sizeof (LITTLENUM_TYPE) * precision);
1999-05-03 15:29:11 +08:00
else
{
long exponent_1;
long exponent_2;
long exponent_3;
long exponent_4;
int exponent_skippage;
LITTLENUM_TYPE word1;
2005-03-23 19:18:14 +08:00
/* JF: Deal with new Nan, +Inf and -Inf codes. */
1999-05-03 15:29:11 +08:00
if (f->sign != '-' && f->sign != '+')
{
make_invalid_floating_point_number (words);
return return_value;
}
2005-03-23 19:18:14 +08:00
/* 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. */
1999-05-03 15:29:11 +08:00
bits_left_in_littlenum = LITTLENUM_NUMBER_OF_BITS;
littlenum_pointer = f->leader;
littlenum_end = f->low;
2005-03-23 19:18:14 +08:00
/* Seek (and forget) 1st significant bit. */
1999-05-03 15:29:11 +08:00
for (exponent_skippage = 0;
!next_bits (1);
exponent_skippage++);
1999-05-03 15:29:11 +08:00
exponent_1 = f->exponent + f->leader + 1 - f->low;
/* Radix LITTLENUM_RADIX, point just higher than f->leader. */
1999-05-03 15:29:11 +08:00
exponent_2 = exponent_1 * LITTLENUM_NUMBER_OF_BITS;
/* Radix 2. */
1999-05-03 15:29:11 +08:00
exponent_3 = exponent_2 - exponent_skippage;
/* Forget leading zeros, forget 1st bit. */
1999-05-03 15:29:11 +08:00
exponent_4 = exponent_3 + (1 << (exponent_bits - 1));
/* Offset exponent. */
1999-05-03 15:29:11 +08:00
if (exponent_4 & ~mask[exponent_bits])
{
2005-03-23 19:18:14 +08:00
/* Exponent overflow. Lose immediately. */
1999-05-03 15:29:11 +08:00
make_invalid_floating_point_number (words);
2005-03-23 19:18:14 +08:00
/* We leave return_value alone: admit we read the
number, but return a floating exception
because we can't encode the number. */
1999-05-03 15:29:11 +08:00
}
else
{
lp = words;
2005-03-23 19:18:14 +08:00
/* Word 1. Sign, exponent and perhaps high bits.
Assume 2's complement integers. */
1999-05-03 15:29:11 +08:00
word1 = (((exponent_4 & mask[exponent_bits]) << (15 - exponent_bits))
| ((f->sign == '+') ? 0 : 0x8000)
| next_bits (15 - exponent_bits));
*lp++ = word1;
/* The rest of the words are just mantissa bits. */
1999-05-03 15:29:11 +08:00
for (; lp < words + precision; lp++)
2005-03-23 19:18:14 +08:00
*lp = next_bits (LITTLENUM_NUMBER_OF_BITS);
1999-05-03 15:29:11 +08:00
if (next_bits (1))
{
2005-03-23 19:18:14 +08:00
/* 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? */
1999-05-03 15:29:11 +08:00
unsigned long carry;
/*
2005-03-23 19:18:14 +08:00
#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 */
1999-05-03 15:29:11 +08:00
for (carry = 1, lp--;
carry && (lp >= words);
lp--)
{
carry = *lp + carry;
*lp = carry;
carry >>= LITTLENUM_NUMBER_OF_BITS;
}
if ((word1 ^ *words) & (1 << (LITTLENUM_NUMBER_OF_BITS - 1)))
{
make_invalid_floating_point_number (words);
2005-03-23 19:18:14 +08:00
/* We leave return_value alone: admit we read the
number, but return a floating exception
because we can't encode the number. */
1999-05-03 15:29:11 +08:00
}
2005-03-23 19:18:14 +08:00
}
}
}
}
return return_value;
}
/* JF this used to be in vax.c but this looks like a better place for it. */
/* In: input_line_pointer->the 1st character of a floating-point
number.
1 letter denoting the type of statement that wants a
binary floating point number returned.
Address of where to build floating point literal.
Assumed to be 'big enough'.
Address of where to return size of literal (in chars).
2015-08-12 19:40:42 +08:00
2005-03-23 19:18:14 +08:00
Out: Input_line_pointer->of next char after floating number.
Error message, or 0.
Floating point literal.
Number of chars we used for the literal. */
#define MAXIMUM_NUMBER_OF_LITTLENUMS 8 /* For .hfloats. */
1999-05-03 15:29:11 +08:00
Constify more * cgen.c (weak_operand_overflow_check): Return const char*. * messages.c (as_internal_value_out_of_range): Formatting. (as_warn_value_out_of_range): Consify prefix param. (as_bad_value_out_of_range): Likewise. * read.c (s_errwarn): Constify msg.. (s_float_space, float_cons): ..and err. * as.h (as_warn_value_out_of_range, as_bad_value_out_of_range, ieee_md_atof, vax_md_atof): Update prototypes. * tc.h (md_atof): Update prototype. * config/atof-ieee.c (ieee_md_atof): Return const char*. * config/atof-vax.c (vax_md_atof): Likewise. * config/obj-elf.c (obj_elf_parse_section_letters): Constify bad_msg. * config/tc-aarch64.c (md_atof): Return const char*. * config/tc-alpha.c (s_alpha_section_name): Likewise. (s_alpha_comm): Constify sec_name. (section_name): Constify. (s_alpha_section): Consify name.. (alpha_elf_section_letter): ..and ptr_msg param.. (md_atof): ..and return. * config/tc-alpha.h (alpha_elf_section_letter): Update prototype. * config/tc-arc.c (md_atof): Return const char*. * config/tc-arm.c (md_atof): Likewise. * config/tc-avr.c (md_atof): Likewise. * config/tc-bfin.c (md_atof): Likewise. * config/tc-cr16.c (md_atof): Likewise. * config/tc-cris.c (md_atof): Likewise. * config/tc-crx.c (md_atof): Likewise. * config/tc-d10v.c (md_atof): Likewise. * config/tc-d30v.c (md_atof): Likewise. * config/tc-dlx.c (md_atof): Likewise. * config/tc-epiphany.c (md_atof): Likewise. * config/tc-fr30.c (md_atof): Likewise. * config/tc-frv.c (md_atof): Likewise. * config/tc-ft32.c (md_atof): Likewise. * config/tc-h8300.c (md_atof): Likewise. * config/tc-hppa.c (struct default_subspace_dict): Constify name. (struct default_space_dict): Likewise. (create_new_space): Constify name param. (create_new_subspace): Likewise. (is_defined_space, is_defined_subspace): Likewise. (pa_parse_space_stmt): Constify space_name param. (md_atof): Return const char*. (pa_spaces_begin): Constify name. * config/tc-i370.c (md_atof): Return const char*. * config/tc-i386.c (md_atof): Likewise. (x86_64_section_letter): Constify ptr_msg param. * config/tc-i386.h (x86_64_section_letter): Update prototype. * config/tc-i860.c (struct i860_it): Constify error. (md_atof): Return const char*. * config/tc-i960.c (md_atof): Likewise. * config/tc-ia64.c (md_atof): Likewise. (ia64_elf_section_letter): Constify ptr_msg param. * config/tc-ia64.h (ia64_elf_section_letter): Update prototype. * config/tc-ip2k.c (md_atof): Return const char*. * config/tc-iq2000.c (md_atof): Likewise. * config/tc-lm32.c (md_atof): Likewise. * config/tc-m32c.c (md_atof): Likewise. * config/tc-m32r.c (md_atof): Likewise. * config/tc-m68hc11.c (md_atof): Likewise. * config/tc-m68k.c (md_atof): Likewise. * config/tc-mcore.c (md_atof): Likewise. * config/tc-mep.c (md_atof): Likewise. (mep_elf_section_letter): Constify ptr_msg param. * config/tc-mep.h (mep_elf_section_letter): Update prototype. * config/tc-metag.c (md_atof): Return const char*. * config/tc-microblaze.c (md_atof): Likewise. * config/tc-microblaze.h (md_atof): Delete prototype. * config/tc-mips.c (mips_parse_argument_token): Constify err. (md_atof): Return const char*. * config/tc-mmix.c (md_atof): Likewise. * config/tc-mn10200.c (md_atof): Likewise. * config/tc-mn10300.c (md_atof): Likewise. * config/tc-moxie.c (md_atof): Likewise. * config/tc-msp430.c (md_atof): Likewise. * config/tc-mt.c (md_atof): Likewise. * config/tc-nds32.c (md_atof): Likewise. * config/tc-nios2.c (md_atof): Likewise. (nios2_elf_section_letter): Constify ptr_msg param. * config/tc-nios2.h (nios2_elf_section_letter): Update prototype. * config/tc-ns32k.c (md_atof): Return const char*. * config/tc-or1k.c (md_atof): Likewise. * config/tc-pdp11.c (struct pdp11_code): Constify error. (md_atof): Return const char*. * config/tc-pj.c (md_atof): Likewise. * config/tc-ppc.c (md_atof): Likewise. * config/tc-rl78.c (md_atof): Likewise. * config/tc-rx.c (md_atof): Likewise. * config/tc-s390.c (md_atof): Likewise. * config/tc-score.c (s3_atof, md_atof): Likewise. * config/tc-sh.c (md_atof): Likewise. * config/tc-sparc.c (struct sparc_it): Constify error. (md_atof): Return const char*. * config/tc-spu.c (md_atof): Likewise. * config/tc-tic30.c (md_atof): Likewise. * config/tc-tic4x.c (md_atof): Likewise. * config/tc-tic54x.c (md_atof): Likewise. * config/tc-tic6x.c (md_atof): Likewise. * config/tc-tilegx.c (md_atof): Likewise. * config/tc-tilepro.c (md_atof): Likewise. * config/tc-v850.c (parse_register_list, md_atof): Likewise. * config/tc-vax.c (md_atof): Likewise. * config/tc-visium.c (md_atof): Likewise. * config/tc-xc16x.c (md_atof): Likewise. * config/tc-xgate.c (md_atof): Likewise. * config/tc-xstormy16.c (md_atof): Likewise. * config/tc-xtensa.c (md_atof): Likewise. * config/tc-z80.c (md_atof): Likewise. * config/tc-z8k.c (md_atof): Likewise.
2016-04-01 20:07:50 +08:00
const char *
vax_md_atof (int what_statement_type,
char *literalP,
int *sizeP)
1999-05-03 15:29:11 +08:00
{
LITTLENUM_TYPE words[MAXIMUM_NUMBER_OF_LITTLENUMS];
2005-03-23 19:18:14 +08:00
char kind_of_float;
unsigned int number_of_chars;
2005-03-23 19:18:14 +08:00
LITTLENUM_TYPE *littlenumP;
1999-05-03 15:29:11 +08:00
switch (what_statement_type)
{
2005-03-23 19:18:14 +08:00
case 'F':
case 'f':
1999-05-03 15:29:11 +08:00
kind_of_float = 'f';
break;
2005-03-23 19:18:14 +08:00
case 'D':
case 'd':
1999-05-03 15:29:11 +08:00
kind_of_float = 'd';
break;
2005-03-23 19:18:14 +08:00
case 'g':
1999-05-03 15:29:11 +08:00
kind_of_float = 'g';
break;
2005-03-23 19:18:14 +08:00
case 'h':
1999-05-03 15:29:11 +08:00
kind_of_float = 'h';
break;
default:
kind_of_float = 0;
break;
};
if (kind_of_float)
{
2005-03-23 19:18:14 +08:00
LITTLENUM_TYPE *limit;
1999-05-03 15:29:11 +08:00
input_line_pointer = atof_vax (input_line_pointer,
kind_of_float,
words);
2005-03-23 19:18:14 +08:00
/* The atof_vax() builds up 16-bit numbers.
Since the assembler may not be running on
a little-endian machine, be very careful about
converting words to chars. */
1999-05-03 15:29:11 +08:00
number_of_chars = atof_vax_sizeof (kind_of_float);
know (number_of_chars <= MAXIMUM_NUMBER_OF_LITTLENUMS * sizeof (LITTLENUM_TYPE));
1999-05-03 15:29:11 +08:00
limit = words + (number_of_chars / sizeof (LITTLENUM_TYPE));
for (littlenumP = words; littlenumP < limit; littlenumP++)
{
md_number_to_chars (literalP, *littlenumP, sizeof (LITTLENUM_TYPE));
literalP += sizeof (LITTLENUM_TYPE);
};
}
else
2005-03-23 19:18:14 +08:00
number_of_chars = 0;
1999-05-03 15:29:11 +08:00
*sizeP = number_of_chars;
return kind_of_float ? NULL : _("Unrecognized or unsupported floating point constant");
1999-05-03 15:29:11 +08:00
}