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

859 lines
22 KiB
C
Raw Normal View History

1999-05-03 09:29:11 +02:00
/* atof_ieee.c - turn a Flonum into an IEEE floating point number
Copyright (C) 1987-2020 Free Software Foundation, Inc.
1999-05-03 09:29:11 +02: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 13:01:12 +02:00
the Free Software Foundation; either version 3, or (at your option)
1999-05-03 09:29:11 +02: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 09:29:11 +02:00
#include "as.h"
/* Flonums returned here. */
extern FLONUM_TYPE generic_floating_point_number;
/* Precision in LittleNums. */
1999-05-03 09:29:11 +02:00
/* Don't count the gap in the m68k extended precision format. */
#define MAX_PRECISION 5
Add generic and ARM specific support for half-precision IEEE 754 floating point numbers to the assembler. Half precision floating point numbers will be encoded using the IEEE 754 half precision floating point format - 16 bits in total, 1 for sign, 5 for exponent and 10 bits of mantissa. This patch implements the float16 directive for both the IEEE 754 format and the Arm alternative format for the Arm backend. The syntax of the directive is: .float16 <0-n decimal numbers> e.g. .float16 12.0 .float16 0.23, 433.1, 0.06 The Arm alternative format is almost identical to the IEEE 754 format, except that it doesn't encode for NaNs or Infinity (instead an exponent of 0x1F represents a normalized number in the range 65536 to 131008). The alternative format is documented in the reference manual: https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf?_ga=2.72318806.49764181.1561632697-999473562.1560847439 Which format is used is controlled by the .float16_format <format> directive, where if <format> = ieee, then use the IEEE 754 half-precision format else if <format> = alternative, then use the Arm alternative format Or the format can be set on the command line via the -mfp16-format option that has a similar syntax. -mfp16-format=<ieee|alternative>. This also fixes the format and it cannot be changed by any directives. Once the format has been set (either by the command line option or a directive) it cannot be changed, and any attempts to change it (i.e. with the float16_format directive) will result in a warning and the line being ignored. For ELF targets the appropriate EABI attribute will be written out at the end of assembling if the format has been explicitly specified. If no format has been explicitly specified then no EABI attributes will be written. If the format is not explicitly specified then any float16 directives are encoding using the IEEE 754-2008 format by default until the format is fixed or changed with the float16_format directive. gas * config/tc-arm.c (enum fp_16bit_format): Add enum to represent the 2 float16 encodings. (md_atof): Set precision for float16 type. (arm_is_largest_exponent_ok): Check for whether to encode with the IEEE or alternative format. (set_fp16_format): Parse a float16_format directive. (arm_parse_fp16_opt): Parse the fp16-format command line option. (aeabi_set_public_attributes): For ELF encode the FP16 format EABI attribute. * config/tc-arm.h (TC_LARGEST_EXPONENT_IS_NORMAL): Macro that expands to arm_is_largest_exponent_ok. (arm_is_largest_exponent_ok): Add prototype for arm_is_largest_exponent_ok function. * doc/c-arm.texi: Add documentation for .float16, .float16_format and -mfp16-format= * testsuite/gas/arm/float16-bad.d: New test. * testsuite/gas/arm/float16-bad.l: New test. * testsuite/gas/arm/float16-bad.s: New test. * testsuite/gas/arm/float16-be.d: New test. * testsuite/gas/arm/float16-format-bad.d: New test. * testsuite/gas/arm/float16-format-bad.l: New test. * testsuite/gas/arm/float16-format-bad.s: New test. * testsuite/gas/arm/float16-format-opt-bad.d: New test. * testsuite/gas/arm/float16-format-opt-bad.l: New test. * testsuite/gas/arm/float16-le.d: New test. * testsuite/gas/arm/float16.s: New test. * testsuite/gas/arm/float16-eabi-alternative-format.d: New test. * testsuite/gas/arm/float16-eabi-ieee-format.d: New test. * testsuite/gas/arm/float16-eabi-no-format.d: New test. * testsuite/gas/arm/float16-eabi.s: New test. * config/atof-ieee.c (H_PRECISION): Macro for precision of float16 type. (atof_ieee): Set precision and exponent bits for encoding float16 types. (gen_to_words): NaN and Infinity encoding for float16. (ieee_md_atof): Set precision for encoding float16 type.
2019-08-12 12:08:36 +02:00
#define H_PRECISION 1
#define F_PRECISION 2
#define D_PRECISION 4
#define X_PRECISION 5
#define P_PRECISION 5
1999-05-03 09:29:11 +02:00
/* Length in LittleNums of guard bits. */
#define GUARD 2
1999-05-03 09:29:11 +02:00
2002-04-11 13:21:01 +02:00
#ifndef TC_LARGEST_EXPONENT_IS_NORMAL
#define TC_LARGEST_EXPONENT_IS_NORMAL(PRECISION) 0
#endif
1999-05-03 09:29:11 +02:00
static const 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,
};
static int bits_left_in_littlenum;
static int littlenums_left;
static LITTLENUM_TYPE *littlenum_pointer;
static int
next_bits (int number_of_bits)
1999-05-03 09:29:11 +02:00
{
int return_value;
if (!littlenums_left)
return 0;
1999-05-03 09:29:11 +02:00
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];
1999-05-03 09:29:11 +02:00
}
}
else
{
bits_left_in_littlenum -= number_of_bits;
return_value =
mask[number_of_bits] & (*littlenum_pointer >> bits_left_in_littlenum);
1999-05-03 09:29:11 +02:00
}
return return_value;
1999-05-03 09:29:11 +02:00
}
/* Num had better be less than LITTLENUM_NUMBER_OF_BITS. */
1999-05-03 09:29:11 +02:00
static void
unget_bits (int num)
1999-05-03 09:29:11 +02:00
{
if (!littlenums_left)
{
++littlenum_pointer;
++littlenums_left;
bits_left_in_littlenum = num;
}
else if (bits_left_in_littlenum + num > LITTLENUM_NUMBER_OF_BITS)
{
bits_left_in_littlenum =
num - (LITTLENUM_NUMBER_OF_BITS - bits_left_in_littlenum);
1999-05-03 09:29:11 +02:00
++littlenum_pointer;
++littlenums_left;
}
else
bits_left_in_littlenum += num;
}
static void
make_invalid_floating_point_number (LITTLENUM_TYPE *words)
1999-05-03 09:29:11 +02:00
{
as_bad (_("cannot create floating-point number"));
/* Zero the leftmost bit. */
words[0] = (LITTLENUM_TYPE) ((unsigned) -1) >> 1;
1999-05-03 09:29:11 +02:00
words[1] = (LITTLENUM_TYPE) -1;
words[2] = (LITTLENUM_TYPE) -1;
words[3] = (LITTLENUM_TYPE) -1;
words[4] = (LITTLENUM_TYPE) -1;
words[5] = (LITTLENUM_TYPE) -1;
}
/* Build a floating point constant at str into a IEEE floating
point number. This function does the same thing as atof_ieee
however it allows more control over the exact format, i.e.
explicitly specifying the precision and number of exponent bits
instead of relying on this infomation being deduced from a given type.
1999-05-03 09:29:11 +02:00
If generic_float_info is not NULL then it will be set to contain generic
infomation about the parsed floating point number.
Returns pointer past text consumed. */
1999-05-03 09:29:11 +02:00
char *
atof_ieee_detail (char * str,
int precision,
int exponent_bits,
LITTLENUM_TYPE * words,
FLONUM_TYPE * generic_float_info)
1999-05-03 09:29:11 +02:00
{
/* Extra bits for zeroed low-order bits.
The 1st MAX_PRECISION are zeroed, the last contain flonum bits. */
1999-05-03 09:29:11 +02:00
static LITTLENUM_TYPE bits[MAX_PRECISION + MAX_PRECISION + GUARD];
char *return_value;
/* Number of 16-bit words in the format. */
1999-05-03 09:29:11 +02:00
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 = 0;
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. */
1999-05-03 09:29:11 +02:00
memset (bits, '\0', sizeof (LITTLENUM_TYPE) * MAX_PRECISION);
generic_floating_point_number.high
= generic_floating_point_number.low + precision - 1 + GUARD;
if (atof_generic (&return_value, ".", EXP_CHARS,
&generic_floating_point_number))
{
make_invalid_floating_point_number (words);
return NULL;
}
if (generic_float_info)
*generic_float_info = generic_floating_point_number;
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;
}
/* 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. */
/* Returns pointer past text consumed. */
char *
atof_ieee (char *str, /* Text to convert to binary. */
int what_kind, /* 'd', 'f', 'x', 'p'. */
LITTLENUM_TYPE *words) /* Build the binary here. */
{
int precision;
long exponent_bits;
1999-05-03 09:29:11 +02:00
switch (what_kind)
{
Add generic and ARM specific support for half-precision IEEE 754 floating point numbers to the assembler. Half precision floating point numbers will be encoded using the IEEE 754 half precision floating point format - 16 bits in total, 1 for sign, 5 for exponent and 10 bits of mantissa. This patch implements the float16 directive for both the IEEE 754 format and the Arm alternative format for the Arm backend. The syntax of the directive is: .float16 <0-n decimal numbers> e.g. .float16 12.0 .float16 0.23, 433.1, 0.06 The Arm alternative format is almost identical to the IEEE 754 format, except that it doesn't encode for NaNs or Infinity (instead an exponent of 0x1F represents a normalized number in the range 65536 to 131008). The alternative format is documented in the reference manual: https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf?_ga=2.72318806.49764181.1561632697-999473562.1560847439 Which format is used is controlled by the .float16_format <format> directive, where if <format> = ieee, then use the IEEE 754 half-precision format else if <format> = alternative, then use the Arm alternative format Or the format can be set on the command line via the -mfp16-format option that has a similar syntax. -mfp16-format=<ieee|alternative>. This also fixes the format and it cannot be changed by any directives. Once the format has been set (either by the command line option or a directive) it cannot be changed, and any attempts to change it (i.e. with the float16_format directive) will result in a warning and the line being ignored. For ELF targets the appropriate EABI attribute will be written out at the end of assembling if the format has been explicitly specified. If no format has been explicitly specified then no EABI attributes will be written. If the format is not explicitly specified then any float16 directives are encoding using the IEEE 754-2008 format by default until the format is fixed or changed with the float16_format directive. gas * config/tc-arm.c (enum fp_16bit_format): Add enum to represent the 2 float16 encodings. (md_atof): Set precision for float16 type. (arm_is_largest_exponent_ok): Check for whether to encode with the IEEE or alternative format. (set_fp16_format): Parse a float16_format directive. (arm_parse_fp16_opt): Parse the fp16-format command line option. (aeabi_set_public_attributes): For ELF encode the FP16 format EABI attribute. * config/tc-arm.h (TC_LARGEST_EXPONENT_IS_NORMAL): Macro that expands to arm_is_largest_exponent_ok. (arm_is_largest_exponent_ok): Add prototype for arm_is_largest_exponent_ok function. * doc/c-arm.texi: Add documentation for .float16, .float16_format and -mfp16-format= * testsuite/gas/arm/float16-bad.d: New test. * testsuite/gas/arm/float16-bad.l: New test. * testsuite/gas/arm/float16-bad.s: New test. * testsuite/gas/arm/float16-be.d: New test. * testsuite/gas/arm/float16-format-bad.d: New test. * testsuite/gas/arm/float16-format-bad.l: New test. * testsuite/gas/arm/float16-format-bad.s: New test. * testsuite/gas/arm/float16-format-opt-bad.d: New test. * testsuite/gas/arm/float16-format-opt-bad.l: New test. * testsuite/gas/arm/float16-le.d: New test. * testsuite/gas/arm/float16.s: New test. * testsuite/gas/arm/float16-eabi-alternative-format.d: New test. * testsuite/gas/arm/float16-eabi-ieee-format.d: New test. * testsuite/gas/arm/float16-eabi-no-format.d: New test. * testsuite/gas/arm/float16-eabi.s: New test. * config/atof-ieee.c (H_PRECISION): Macro for precision of float16 type. (atof_ieee): Set precision and exponent bits for encoding float16 types. (gen_to_words): NaN and Infinity encoding for float16. (ieee_md_atof): Set precision for encoding float16 type.
2019-08-12 12:08:36 +02:00
case 'h':
case 'H':
precision = H_PRECISION;
exponent_bits = 5;
break;
1999-05-03 09:29:11 +02:00
case 'f':
case 'F':
case 's':
case 'S':
precision = F_PRECISION;
exponent_bits = 8;
break;
case 'd':
case 'D':
case 'r':
case 'R':
precision = D_PRECISION;
exponent_bits = 11;
break;
case 'x':
case 'X':
case 'e':
case 'E':
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);
}
return atof_ieee_detail (str, precision, exponent_bits, words, NULL);
1999-05-03 09:29:11 +02:00
}
/* Turn generic_floating_point_number into a real float/double/extended. */
1999-05-03 09:29:11 +02:00
int
gen_to_words (LITTLENUM_TYPE *words, int precision, long exponent_bits)
1999-05-03 09:29:11 +02:00
{
int return_value = 0;
long exponent_1;
long exponent_2;
long exponent_3;
long exponent_4;
int exponent_skippage;
LITTLENUM_TYPE word1;
LITTLENUM_TYPE *lp;
LITTLENUM_TYPE *words_end;
words_end = words + precision;
#ifdef TC_M68K
if (precision == X_PRECISION)
/* On the m68k the extended precision format has a gap of 16 bits
between the exponent and the mantissa. */
words_end++;
#endif
if (generic_floating_point_number.low > generic_floating_point_number.leader)
{
/* 0.0e0 seen. */
1999-05-03 09:29:11 +02:00
if (generic_floating_point_number.sign == '+')
words[0] = 0x0000;
else
words[0] = 0x8000;
memset (&words[1], '\0',
(words_end - words - 1) * sizeof (LITTLENUM_TYPE));
return return_value;
1999-05-03 09:29:11 +02:00
}
/* NaN: Do the right thing. */
1999-05-03 09:29:11 +02:00
if (generic_floating_point_number.sign == 0)
{
if (TC_LARGEST_EXPONENT_IS_NORMAL (precision))
Add generic and ARM specific support for half-precision IEEE 754 floating point numbers to the assembler. Half precision floating point numbers will be encoded using the IEEE 754 half precision floating point format - 16 bits in total, 1 for sign, 5 for exponent and 10 bits of mantissa. This patch implements the float16 directive for both the IEEE 754 format and the Arm alternative format for the Arm backend. The syntax of the directive is: .float16 <0-n decimal numbers> e.g. .float16 12.0 .float16 0.23, 433.1, 0.06 The Arm alternative format is almost identical to the IEEE 754 format, except that it doesn't encode for NaNs or Infinity (instead an exponent of 0x1F represents a normalized number in the range 65536 to 131008). The alternative format is documented in the reference manual: https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf?_ga=2.72318806.49764181.1561632697-999473562.1560847439 Which format is used is controlled by the .float16_format <format> directive, where if <format> = ieee, then use the IEEE 754 half-precision format else if <format> = alternative, then use the Arm alternative format Or the format can be set on the command line via the -mfp16-format option that has a similar syntax. -mfp16-format=<ieee|alternative>. This also fixes the format and it cannot be changed by any directives. Once the format has been set (either by the command line option or a directive) it cannot be changed, and any attempts to change it (i.e. with the float16_format directive) will result in a warning and the line being ignored. For ELF targets the appropriate EABI attribute will be written out at the end of assembling if the format has been explicitly specified. If no format has been explicitly specified then no EABI attributes will be written. If the format is not explicitly specified then any float16 directives are encoding using the IEEE 754-2008 format by default until the format is fixed or changed with the float16_format directive. gas * config/tc-arm.c (enum fp_16bit_format): Add enum to represent the 2 float16 encodings. (md_atof): Set precision for float16 type. (arm_is_largest_exponent_ok): Check for whether to encode with the IEEE or alternative format. (set_fp16_format): Parse a float16_format directive. (arm_parse_fp16_opt): Parse the fp16-format command line option. (aeabi_set_public_attributes): For ELF encode the FP16 format EABI attribute. * config/tc-arm.h (TC_LARGEST_EXPONENT_IS_NORMAL): Macro that expands to arm_is_largest_exponent_ok. (arm_is_largest_exponent_ok): Add prototype for arm_is_largest_exponent_ok function. * doc/c-arm.texi: Add documentation for .float16, .float16_format and -mfp16-format= * testsuite/gas/arm/float16-bad.d: New test. * testsuite/gas/arm/float16-bad.l: New test. * testsuite/gas/arm/float16-bad.s: New test. * testsuite/gas/arm/float16-be.d: New test. * testsuite/gas/arm/float16-format-bad.d: New test. * testsuite/gas/arm/float16-format-bad.l: New test. * testsuite/gas/arm/float16-format-bad.s: New test. * testsuite/gas/arm/float16-format-opt-bad.d: New test. * testsuite/gas/arm/float16-format-opt-bad.l: New test. * testsuite/gas/arm/float16-le.d: New test. * testsuite/gas/arm/float16.s: New test. * testsuite/gas/arm/float16-eabi-alternative-format.d: New test. * testsuite/gas/arm/float16-eabi-ieee-format.d: New test. * testsuite/gas/arm/float16-eabi-no-format.d: New test. * testsuite/gas/arm/float16-eabi.s: New test. * config/atof-ieee.c (H_PRECISION): Macro for precision of float16 type. (atof_ieee): Set precision and exponent bits for encoding float16 types. (gen_to_words): NaN and Infinity encoding for float16. (ieee_md_atof): Set precision for encoding float16 type.
2019-08-12 12:08:36 +02:00
as_warn (_("NaNs are not supported by this target"));
if (precision == H_PRECISION)
{
words[0] = 0x7fff;
}
else if (precision == F_PRECISION)
1999-05-03 09:29:11 +02:00
{
words[0] = 0x7fff;
words[1] = 0xffff;
}
else if (precision == X_PRECISION)
{
#ifdef TC_M68K
words[0] = 0x7fff;
words[1] = 0;
words[2] = 0xffff;
words[3] = 0xffff;
words[4] = 0xffff;
words[5] = 0xffff;
#else /* ! TC_M68K */
1999-05-03 09:29:11 +02:00
#ifdef TC_I386
words[0] = 0xffff;
words[1] = 0xc000;
words[2] = 0;
words[3] = 0;
words[4] = 0;
#else /* ! TC_I386 */
1999-05-03 09:29:11 +02:00
abort ();
#endif /* ! TC_I386 */
#endif /* ! TC_M68K */
1999-05-03 09:29:11 +02:00
}
else
{
words[0] = 0x7fff;
words[1] = 0xffff;
words[2] = 0xffff;
words[3] = 0xffff;
}
return return_value;
}
else if (generic_floating_point_number.sign == 'P')
{
if (TC_LARGEST_EXPONENT_IS_NORMAL (precision))
Add generic and ARM specific support for half-precision IEEE 754 floating point numbers to the assembler. Half precision floating point numbers will be encoded using the IEEE 754 half precision floating point format - 16 bits in total, 1 for sign, 5 for exponent and 10 bits of mantissa. This patch implements the float16 directive for both the IEEE 754 format and the Arm alternative format for the Arm backend. The syntax of the directive is: .float16 <0-n decimal numbers> e.g. .float16 12.0 .float16 0.23, 433.1, 0.06 The Arm alternative format is almost identical to the IEEE 754 format, except that it doesn't encode for NaNs or Infinity (instead an exponent of 0x1F represents a normalized number in the range 65536 to 131008). The alternative format is documented in the reference manual: https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf?_ga=2.72318806.49764181.1561632697-999473562.1560847439 Which format is used is controlled by the .float16_format <format> directive, where if <format> = ieee, then use the IEEE 754 half-precision format else if <format> = alternative, then use the Arm alternative format Or the format can be set on the command line via the -mfp16-format option that has a similar syntax. -mfp16-format=<ieee|alternative>. This also fixes the format and it cannot be changed by any directives. Once the format has been set (either by the command line option or a directive) it cannot be changed, and any attempts to change it (i.e. with the float16_format directive) will result in a warning and the line being ignored. For ELF targets the appropriate EABI attribute will be written out at the end of assembling if the format has been explicitly specified. If no format has been explicitly specified then no EABI attributes will be written. If the format is not explicitly specified then any float16 directives are encoding using the IEEE 754-2008 format by default until the format is fixed or changed with the float16_format directive. gas * config/tc-arm.c (enum fp_16bit_format): Add enum to represent the 2 float16 encodings. (md_atof): Set precision for float16 type. (arm_is_largest_exponent_ok): Check for whether to encode with the IEEE or alternative format. (set_fp16_format): Parse a float16_format directive. (arm_parse_fp16_opt): Parse the fp16-format command line option. (aeabi_set_public_attributes): For ELF encode the FP16 format EABI attribute. * config/tc-arm.h (TC_LARGEST_EXPONENT_IS_NORMAL): Macro that expands to arm_is_largest_exponent_ok. (arm_is_largest_exponent_ok): Add prototype for arm_is_largest_exponent_ok function. * doc/c-arm.texi: Add documentation for .float16, .float16_format and -mfp16-format= * testsuite/gas/arm/float16-bad.d: New test. * testsuite/gas/arm/float16-bad.l: New test. * testsuite/gas/arm/float16-bad.s: New test. * testsuite/gas/arm/float16-be.d: New test. * testsuite/gas/arm/float16-format-bad.d: New test. * testsuite/gas/arm/float16-format-bad.l: New test. * testsuite/gas/arm/float16-format-bad.s: New test. * testsuite/gas/arm/float16-format-opt-bad.d: New test. * testsuite/gas/arm/float16-format-opt-bad.l: New test. * testsuite/gas/arm/float16-le.d: New test. * testsuite/gas/arm/float16.s: New test. * testsuite/gas/arm/float16-eabi-alternative-format.d: New test. * testsuite/gas/arm/float16-eabi-ieee-format.d: New test. * testsuite/gas/arm/float16-eabi-no-format.d: New test. * testsuite/gas/arm/float16-eabi.s: New test. * config/atof-ieee.c (H_PRECISION): Macro for precision of float16 type. (atof_ieee): Set precision and exponent bits for encoding float16 types. (gen_to_words): NaN and Infinity encoding for float16. (ieee_md_atof): Set precision for encoding float16 type.
2019-08-12 12:08:36 +02:00
as_warn (_("Infinities are not supported by this target"));
/* +INF: Do the right thing. */
Add generic and ARM specific support for half-precision IEEE 754 floating point numbers to the assembler. Half precision floating point numbers will be encoded using the IEEE 754 half precision floating point format - 16 bits in total, 1 for sign, 5 for exponent and 10 bits of mantissa. This patch implements the float16 directive for both the IEEE 754 format and the Arm alternative format for the Arm backend. The syntax of the directive is: .float16 <0-n decimal numbers> e.g. .float16 12.0 .float16 0.23, 433.1, 0.06 The Arm alternative format is almost identical to the IEEE 754 format, except that it doesn't encode for NaNs or Infinity (instead an exponent of 0x1F represents a normalized number in the range 65536 to 131008). The alternative format is documented in the reference manual: https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf?_ga=2.72318806.49764181.1561632697-999473562.1560847439 Which format is used is controlled by the .float16_format <format> directive, where if <format> = ieee, then use the IEEE 754 half-precision format else if <format> = alternative, then use the Arm alternative format Or the format can be set on the command line via the -mfp16-format option that has a similar syntax. -mfp16-format=<ieee|alternative>. This also fixes the format and it cannot be changed by any directives. Once the format has been set (either by the command line option or a directive) it cannot be changed, and any attempts to change it (i.e. with the float16_format directive) will result in a warning and the line being ignored. For ELF targets the appropriate EABI attribute will be written out at the end of assembling if the format has been explicitly specified. If no format has been explicitly specified then no EABI attributes will be written. If the format is not explicitly specified then any float16 directives are encoding using the IEEE 754-2008 format by default until the format is fixed or changed with the float16_format directive. gas * config/tc-arm.c (enum fp_16bit_format): Add enum to represent the 2 float16 encodings. (md_atof): Set precision for float16 type. (arm_is_largest_exponent_ok): Check for whether to encode with the IEEE or alternative format. (set_fp16_format): Parse a float16_format directive. (arm_parse_fp16_opt): Parse the fp16-format command line option. (aeabi_set_public_attributes): For ELF encode the FP16 format EABI attribute. * config/tc-arm.h (TC_LARGEST_EXPONENT_IS_NORMAL): Macro that expands to arm_is_largest_exponent_ok. (arm_is_largest_exponent_ok): Add prototype for arm_is_largest_exponent_ok function. * doc/c-arm.texi: Add documentation for .float16, .float16_format and -mfp16-format= * testsuite/gas/arm/float16-bad.d: New test. * testsuite/gas/arm/float16-bad.l: New test. * testsuite/gas/arm/float16-bad.s: New test. * testsuite/gas/arm/float16-be.d: New test. * testsuite/gas/arm/float16-format-bad.d: New test. * testsuite/gas/arm/float16-format-bad.l: New test. * testsuite/gas/arm/float16-format-bad.s: New test. * testsuite/gas/arm/float16-format-opt-bad.d: New test. * testsuite/gas/arm/float16-format-opt-bad.l: New test. * testsuite/gas/arm/float16-le.d: New test. * testsuite/gas/arm/float16.s: New test. * testsuite/gas/arm/float16-eabi-alternative-format.d: New test. * testsuite/gas/arm/float16-eabi-ieee-format.d: New test. * testsuite/gas/arm/float16-eabi-no-format.d: New test. * testsuite/gas/arm/float16-eabi.s: New test. * config/atof-ieee.c (H_PRECISION): Macro for precision of float16 type. (atof_ieee): Set precision and exponent bits for encoding float16 types. (gen_to_words): NaN and Infinity encoding for float16. (ieee_md_atof): Set precision for encoding float16 type.
2019-08-12 12:08:36 +02:00
if (precision == H_PRECISION)
{
words[0] = 0x7c00;
}
else if (precision == F_PRECISION)
1999-05-03 09:29:11 +02:00
{
words[0] = 0x7f80;
words[1] = 0;
}
else if (precision == X_PRECISION)
{
#ifdef TC_M68K
words[0] = 0x7fff;
words[1] = 0;
words[2] = 0;
words[3] = 0;
words[4] = 0;
words[5] = 0;
#else /* ! TC_M68K */
1999-05-03 09:29:11 +02:00
#ifdef TC_I386
words[0] = 0x7fff;
words[1] = 0x8000;
words[2] = 0;
words[3] = 0;
words[4] = 0;
#else /* ! TC_I386 */
1999-05-03 09:29:11 +02:00
abort ();
#endif /* ! TC_I386 */
#endif /* ! TC_M68K */
1999-05-03 09:29:11 +02:00
}
else
{
words[0] = 0x7ff0;
words[1] = 0;
words[2] = 0;
words[3] = 0;
}
return return_value;
1999-05-03 09:29:11 +02:00
}
else if (generic_floating_point_number.sign == 'N')
{
if (TC_LARGEST_EXPONENT_IS_NORMAL (precision))
Add generic and ARM specific support for half-precision IEEE 754 floating point numbers to the assembler. Half precision floating point numbers will be encoded using the IEEE 754 half precision floating point format - 16 bits in total, 1 for sign, 5 for exponent and 10 bits of mantissa. This patch implements the float16 directive for both the IEEE 754 format and the Arm alternative format for the Arm backend. The syntax of the directive is: .float16 <0-n decimal numbers> e.g. .float16 12.0 .float16 0.23, 433.1, 0.06 The Arm alternative format is almost identical to the IEEE 754 format, except that it doesn't encode for NaNs or Infinity (instead an exponent of 0x1F represents a normalized number in the range 65536 to 131008). The alternative format is documented in the reference manual: https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf?_ga=2.72318806.49764181.1561632697-999473562.1560847439 Which format is used is controlled by the .float16_format <format> directive, where if <format> = ieee, then use the IEEE 754 half-precision format else if <format> = alternative, then use the Arm alternative format Or the format can be set on the command line via the -mfp16-format option that has a similar syntax. -mfp16-format=<ieee|alternative>. This also fixes the format and it cannot be changed by any directives. Once the format has been set (either by the command line option or a directive) it cannot be changed, and any attempts to change it (i.e. with the float16_format directive) will result in a warning and the line being ignored. For ELF targets the appropriate EABI attribute will be written out at the end of assembling if the format has been explicitly specified. If no format has been explicitly specified then no EABI attributes will be written. If the format is not explicitly specified then any float16 directives are encoding using the IEEE 754-2008 format by default until the format is fixed or changed with the float16_format directive. gas * config/tc-arm.c (enum fp_16bit_format): Add enum to represent the 2 float16 encodings. (md_atof): Set precision for float16 type. (arm_is_largest_exponent_ok): Check for whether to encode with the IEEE or alternative format. (set_fp16_format): Parse a float16_format directive. (arm_parse_fp16_opt): Parse the fp16-format command line option. (aeabi_set_public_attributes): For ELF encode the FP16 format EABI attribute. * config/tc-arm.h (TC_LARGEST_EXPONENT_IS_NORMAL): Macro that expands to arm_is_largest_exponent_ok. (arm_is_largest_exponent_ok): Add prototype for arm_is_largest_exponent_ok function. * doc/c-arm.texi: Add documentation for .float16, .float16_format and -mfp16-format= * testsuite/gas/arm/float16-bad.d: New test. * testsuite/gas/arm/float16-bad.l: New test. * testsuite/gas/arm/float16-bad.s: New test. * testsuite/gas/arm/float16-be.d: New test. * testsuite/gas/arm/float16-format-bad.d: New test. * testsuite/gas/arm/float16-format-bad.l: New test. * testsuite/gas/arm/float16-format-bad.s: New test. * testsuite/gas/arm/float16-format-opt-bad.d: New test. * testsuite/gas/arm/float16-format-opt-bad.l: New test. * testsuite/gas/arm/float16-le.d: New test. * testsuite/gas/arm/float16.s: New test. * testsuite/gas/arm/float16-eabi-alternative-format.d: New test. * testsuite/gas/arm/float16-eabi-ieee-format.d: New test. * testsuite/gas/arm/float16-eabi-no-format.d: New test. * testsuite/gas/arm/float16-eabi.s: New test. * config/atof-ieee.c (H_PRECISION): Macro for precision of float16 type. (atof_ieee): Set precision and exponent bits for encoding float16 types. (gen_to_words): NaN and Infinity encoding for float16. (ieee_md_atof): Set precision for encoding float16 type.
2019-08-12 12:08:36 +02:00
as_warn (_("Infinities are not supported by this target"));
/* Negative INF. */
Add generic and ARM specific support for half-precision IEEE 754 floating point numbers to the assembler. Half precision floating point numbers will be encoded using the IEEE 754 half precision floating point format - 16 bits in total, 1 for sign, 5 for exponent and 10 bits of mantissa. This patch implements the float16 directive for both the IEEE 754 format and the Arm alternative format for the Arm backend. The syntax of the directive is: .float16 <0-n decimal numbers> e.g. .float16 12.0 .float16 0.23, 433.1, 0.06 The Arm alternative format is almost identical to the IEEE 754 format, except that it doesn't encode for NaNs or Infinity (instead an exponent of 0x1F represents a normalized number in the range 65536 to 131008). The alternative format is documented in the reference manual: https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf?_ga=2.72318806.49764181.1561632697-999473562.1560847439 Which format is used is controlled by the .float16_format <format> directive, where if <format> = ieee, then use the IEEE 754 half-precision format else if <format> = alternative, then use the Arm alternative format Or the format can be set on the command line via the -mfp16-format option that has a similar syntax. -mfp16-format=<ieee|alternative>. This also fixes the format and it cannot be changed by any directives. Once the format has been set (either by the command line option or a directive) it cannot be changed, and any attempts to change it (i.e. with the float16_format directive) will result in a warning and the line being ignored. For ELF targets the appropriate EABI attribute will be written out at the end of assembling if the format has been explicitly specified. If no format has been explicitly specified then no EABI attributes will be written. If the format is not explicitly specified then any float16 directives are encoding using the IEEE 754-2008 format by default until the format is fixed or changed with the float16_format directive. gas * config/tc-arm.c (enum fp_16bit_format): Add enum to represent the 2 float16 encodings. (md_atof): Set precision for float16 type. (arm_is_largest_exponent_ok): Check for whether to encode with the IEEE or alternative format. (set_fp16_format): Parse a float16_format directive. (arm_parse_fp16_opt): Parse the fp16-format command line option. (aeabi_set_public_attributes): For ELF encode the FP16 format EABI attribute. * config/tc-arm.h (TC_LARGEST_EXPONENT_IS_NORMAL): Macro that expands to arm_is_largest_exponent_ok. (arm_is_largest_exponent_ok): Add prototype for arm_is_largest_exponent_ok function. * doc/c-arm.texi: Add documentation for .float16, .float16_format and -mfp16-format= * testsuite/gas/arm/float16-bad.d: New test. * testsuite/gas/arm/float16-bad.l: New test. * testsuite/gas/arm/float16-bad.s: New test. * testsuite/gas/arm/float16-be.d: New test. * testsuite/gas/arm/float16-format-bad.d: New test. * testsuite/gas/arm/float16-format-bad.l: New test. * testsuite/gas/arm/float16-format-bad.s: New test. * testsuite/gas/arm/float16-format-opt-bad.d: New test. * testsuite/gas/arm/float16-format-opt-bad.l: New test. * testsuite/gas/arm/float16-le.d: New test. * testsuite/gas/arm/float16.s: New test. * testsuite/gas/arm/float16-eabi-alternative-format.d: New test. * testsuite/gas/arm/float16-eabi-ieee-format.d: New test. * testsuite/gas/arm/float16-eabi-no-format.d: New test. * testsuite/gas/arm/float16-eabi.s: New test. * config/atof-ieee.c (H_PRECISION): Macro for precision of float16 type. (atof_ieee): Set precision and exponent bits for encoding float16 types. (gen_to_words): NaN and Infinity encoding for float16. (ieee_md_atof): Set precision for encoding float16 type.
2019-08-12 12:08:36 +02:00
if (precision == H_PRECISION)
{
words[0] = 0xfc00;
}
else if (precision == F_PRECISION)
1999-05-03 09:29:11 +02:00
{
words[0] = 0xff80;
words[1] = 0x0;
}
else if (precision == X_PRECISION)
{
#ifdef TC_M68K
words[0] = 0xffff;
words[1] = 0;
words[2] = 0;
words[3] = 0;
words[4] = 0;
words[5] = 0;
#else /* ! TC_M68K */
1999-05-03 09:29:11 +02:00
#ifdef TC_I386
words[0] = 0xffff;
words[1] = 0x8000;
words[2] = 0;
words[3] = 0;
words[4] = 0;
#else /* ! TC_I386 */
1999-05-03 09:29:11 +02:00
abort ();
#endif /* ! TC_I386 */
#endif /* ! TC_M68K */
1999-05-03 09:29:11 +02:00
}
else
{
words[0] = 0xfff0;
words[1] = 0x0;
words[2] = 0x0;
words[3] = 0x0;
}
return return_value;
1999-05-03 09:29:11 +02:00
}
/* 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. */
1999-05-03 09:29:11 +02:00
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);
1999-05-03 09:29:11 +02:00
exponent_1 = (generic_floating_point_number.exponent
+ generic_floating_point_number.leader
+ 1
- generic_floating_point_number.low);
1999-05-03 09:29:11 +02:00
/* Radix LITTLENUM_RADIX, point just higher than
generic_floating_point_number.leader. */
1999-05-03 09:29:11 +02:00
exponent_2 = exponent_1 * LITTLENUM_NUMBER_OF_BITS;
/* Radix 2. */
1999-05-03 09:29:11 +02:00
exponent_3 = exponent_2 - exponent_skippage;
/* Forget leading zeros, forget 1st bit. */
1999-05-03 09:29:11 +02:00
exponent_4 = exponent_3 + ((1 << (exponent_bits - 1)) - 2);
/* Offset exponent. */
1999-05-03 09:29:11 +02:00
lp = words;
/* Word 1. Sign, exponent and perhaps high bits. */
1999-05-03 09:29:11 +02:00
word1 = ((generic_floating_point_number.sign == '+')
? 0
: (1 << (LITTLENUM_NUMBER_OF_BITS - 1)));
/* Assume 2's complement integers. */
1999-05-03 09:29:11 +02:00
if (exponent_4 <= 0)
{
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);
1999-05-03 09:29:11 +02:00
#ifdef TC_I386
if (precision == X_PRECISION && exponent_bits == 15)
{
/* On the i386 a denormalized extended precision float is
shifted down by one, effectively decreasing the exponent
bias by one. */
prec_bits -= 1;
num_bits += 1;
}
#endif
if (num_bits >= LITTLENUM_NUMBER_OF_BITS - exponent_bits)
{
/* Bigger than one littlenum. */
1999-05-03 09:29:11 +02:00
num_bits -= (LITTLENUM_NUMBER_OF_BITS - 1) - exponent_bits;
*lp++ = word1;
if (num_bits + exponent_bits + 1
> precision * LITTLENUM_NUMBER_OF_BITS)
1999-05-03 09:29:11 +02:00
{
/* Exponent overflow. */
1999-05-03 09:29:11 +02:00
make_invalid_floating_point_number (words);
return return_value;
1999-05-03 09:29:11 +02:00
}
#ifdef TC_M68K
if (precision == X_PRECISION && exponent_bits == 15)
*lp++ = 0;
#endif
while (num_bits >= LITTLENUM_NUMBER_OF_BITS)
{
num_bits -= LITTLENUM_NUMBER_OF_BITS;
*lp++ = 0;
}
if (num_bits)
*lp++ = next_bits (LITTLENUM_NUMBER_OF_BITS - (num_bits));
}
else
{
if (precision == X_PRECISION && exponent_bits == 15)
{
*lp++ = word1;
#ifdef TC_M68K
*lp++ = 0;
#endif
*lp++ = next_bits (LITTLENUM_NUMBER_OF_BITS - num_bits);
}
else
{
word1 |= next_bits ((LITTLENUM_NUMBER_OF_BITS - 1)
- (exponent_bits + num_bits));
1999-05-03 09:29:11 +02:00
*lp++ = word1;
}
}
while (lp < words_end)
*lp++ = next_bits (LITTLENUM_NUMBER_OF_BITS);
/* Round the mantissa up, but don't change the number. */
1999-05-03 09:29:11 +02:00
if (next_bits (1))
{
--lp;
if (prec_bits >= LITTLENUM_NUMBER_OF_BITS)
1999-05-03 09:29:11 +02:00
{
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;
--n;
tmp_bits -= LITTLENUM_NUMBER_OF_BITS;
}
if (tmp_bits > LITTLENUM_NUMBER_OF_BITS
|| (lp[n] & mask[tmp_bits]) != mask[tmp_bits]
|| (prec_bits != (precision * LITTLENUM_NUMBER_OF_BITS
- exponent_bits - 1)
#ifdef TC_I386
/* An extended precision float with only the integer
bit set would be invalid. That must be converted
to the smallest normalized number. */
&& !(precision == X_PRECISION
&& prec_bits == (precision * LITTLENUM_NUMBER_OF_BITS
- exponent_bits - 2))
#endif
))
1999-05-03 09:29:11 +02:00
{
unsigned long carry;
for (carry = 1; carry && (lp >= words); lp--)
{
carry = *lp + carry;
*lp = carry;
carry >>= LITTLENUM_NUMBER_OF_BITS;
}
}
else
{
/* This is an overflow of the denormal numbers. We
need to forget what we have produced, and instead
generate the smallest normalized number. */
lp = words;
word1 = ((generic_floating_point_number.sign == '+')
? 0
: (1 << (LITTLENUM_NUMBER_OF_BITS - 1)));
word1 |= (1
<< ((LITTLENUM_NUMBER_OF_BITS - 1)
- exponent_bits));
*lp++ = word1;
#ifdef TC_I386
/* Set the integer bit in the extended precision format.
This cannot happen on the m68k where the mantissa
just overflows into the integer bit above. */
if (precision == X_PRECISION)
*lp++ = 1 << (LITTLENUM_NUMBER_OF_BITS - 1);
#endif
1999-05-03 09:29:11 +02:00
while (lp < words_end)
*lp++ = 0;
}
}
else
1999-05-03 09:29:11 +02:00
*lp += 1;
}
return return_value;
}
else if ((unsigned long) exponent_4 > mask[exponent_bits]
|| (! TC_LARGEST_EXPONENT_IS_NORMAL (precision)
&& (unsigned long) exponent_4 == mask[exponent_bits]))
1999-05-03 09:29:11 +02:00
{
/* 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. */
1999-05-03 09:29:11 +02:00
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);
}
*lp++ = word1;
/* X_PRECISION is special: on the 68k, it has 16 bits of zero in the
middle. Either way, it is then followed by a 1 bit. */
1999-05-03 09:29:11 +02:00
if (exponent_bits == 15 && precision == X_PRECISION)
{
#ifdef TC_M68K
*lp++ = 0;
#endif
*lp++ = (1 << (LITTLENUM_NUMBER_OF_BITS - 1)
| next_bits (LITTLENUM_NUMBER_OF_BITS - 1));
}
/* The rest of the words are just mantissa bits. */
1999-05-03 09:29:11 +02:00
while (lp < words_end)
*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? */
1999-05-03 09:29:11 +02: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 */
for (carry = 1, lp--; carry; lp--)
1999-05-03 09:29:11 +02:00
{
carry = *lp + carry;
*lp = carry;
carry >>= LITTLENUM_NUMBER_OF_BITS;
if (lp == words)
break;
1999-05-03 09:29:11 +02:00
}
if (precision == X_PRECISION && exponent_bits == 15)
{
/* Extended precision numbers have an explicit integer bit
that we may have to restore. */
if (lp == words)
{
#ifdef TC_M68K
/* On the m68k there is a gap of 16 bits. We must
explicitly propagate the carry into the exponent. */
1999-05-03 09:29:11 +02:00
words[0] += words[1];
words[1] = 0;
lp++;
#endif
/* Put back the integer bit. */
1999-05-03 09:29:11 +02:00
lp[1] |= 1 << (LITTLENUM_NUMBER_OF_BITS - 1);
}
}
1999-05-03 09:29:11 +02:00
if ((word1 ^ *words) & (1 << (LITTLENUM_NUMBER_OF_BITS - 1)))
{
/* 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 09:29:11 +02:00
*words &= ~(1 << (LITTLENUM_NUMBER_OF_BITS - 1));
}
}
return return_value;
1999-05-03 09:29:11 +02:00
}
#ifdef TEST
char *
print_gen (gen)
FLONUM_TYPE *gen;
{
FLONUM_TYPE f;
LITTLENUM_TYPE arr[10];
double dv;
float fv;
static char sbuf[40];
if (gen)
{
f = generic_floating_point_number;
generic_floating_point_number = *gen;
}
gen_to_words (&arr[0], 4, 11);
memcpy (&dv, &arr[0], sizeof (double));
sprintf (sbuf, "%x %x %x %x %.14G ", arr[0], arr[1], arr[2], arr[3], dv);
gen_to_words (&arr[0], 2, 8);
memcpy (&fv, &arr[0], sizeof (float));
sprintf (sbuf + strlen (sbuf), "%x %x %.12g\n", arr[0], arr[1], fv);
if (gen)
generic_floating_point_number = f;
1999-05-03 09:29:11 +02:00
return (sbuf);
}
#endif
/* This is a utility function called from various tc-*.c files. It
is here in order to reduce code duplication.
2015-08-12 13:40:42 +02:00
Turn a string at input_line_pointer into a floating point constant
of type TYPE (a character found in the FLT_CHARS macro), and store
it as LITTLENUMS in the bytes buffer LITP. The number of chars
emitted is stored in *SIZEP. BIG_WORDIAN is TRUE if the littlenums
should be emitted most significant littlenum first.
An error message is returned, or a NULL pointer if everything went OK. */
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 14:07:50 +02:00
const char *
ieee_md_atof (int type,
char *litP,
int *sizeP,
bfd_boolean big_wordian)
{
LITTLENUM_TYPE words[MAX_LITTLENUMS];
LITTLENUM_TYPE *wordP;
char *t;
int prec = 0;
1999-05-03 09:29:11 +02:00
if (strchr (FLT_CHARS, type) != NULL)
{
switch (type)
{
Add generic and ARM specific support for half-precision IEEE 754 floating point numbers to the assembler. Half precision floating point numbers will be encoded using the IEEE 754 half precision floating point format - 16 bits in total, 1 for sign, 5 for exponent and 10 bits of mantissa. This patch implements the float16 directive for both the IEEE 754 format and the Arm alternative format for the Arm backend. The syntax of the directive is: .float16 <0-n decimal numbers> e.g. .float16 12.0 .float16 0.23, 433.1, 0.06 The Arm alternative format is almost identical to the IEEE 754 format, except that it doesn't encode for NaNs or Infinity (instead an exponent of 0x1F represents a normalized number in the range 65536 to 131008). The alternative format is documented in the reference manual: https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf?_ga=2.72318806.49764181.1561632697-999473562.1560847439 Which format is used is controlled by the .float16_format <format> directive, where if <format> = ieee, then use the IEEE 754 half-precision format else if <format> = alternative, then use the Arm alternative format Or the format can be set on the command line via the -mfp16-format option that has a similar syntax. -mfp16-format=<ieee|alternative>. This also fixes the format and it cannot be changed by any directives. Once the format has been set (either by the command line option or a directive) it cannot be changed, and any attempts to change it (i.e. with the float16_format directive) will result in a warning and the line being ignored. For ELF targets the appropriate EABI attribute will be written out at the end of assembling if the format has been explicitly specified. If no format has been explicitly specified then no EABI attributes will be written. If the format is not explicitly specified then any float16 directives are encoding using the IEEE 754-2008 format by default until the format is fixed or changed with the float16_format directive. gas * config/tc-arm.c (enum fp_16bit_format): Add enum to represent the 2 float16 encodings. (md_atof): Set precision for float16 type. (arm_is_largest_exponent_ok): Check for whether to encode with the IEEE or alternative format. (set_fp16_format): Parse a float16_format directive. (arm_parse_fp16_opt): Parse the fp16-format command line option. (aeabi_set_public_attributes): For ELF encode the FP16 format EABI attribute. * config/tc-arm.h (TC_LARGEST_EXPONENT_IS_NORMAL): Macro that expands to arm_is_largest_exponent_ok. (arm_is_largest_exponent_ok): Add prototype for arm_is_largest_exponent_ok function. * doc/c-arm.texi: Add documentation for .float16, .float16_format and -mfp16-format= * testsuite/gas/arm/float16-bad.d: New test. * testsuite/gas/arm/float16-bad.l: New test. * testsuite/gas/arm/float16-bad.s: New test. * testsuite/gas/arm/float16-be.d: New test. * testsuite/gas/arm/float16-format-bad.d: New test. * testsuite/gas/arm/float16-format-bad.l: New test. * testsuite/gas/arm/float16-format-bad.s: New test. * testsuite/gas/arm/float16-format-opt-bad.d: New test. * testsuite/gas/arm/float16-format-opt-bad.l: New test. * testsuite/gas/arm/float16-le.d: New test. * testsuite/gas/arm/float16.s: New test. * testsuite/gas/arm/float16-eabi-alternative-format.d: New test. * testsuite/gas/arm/float16-eabi-ieee-format.d: New test. * testsuite/gas/arm/float16-eabi-no-format.d: New test. * testsuite/gas/arm/float16-eabi.s: New test. * config/atof-ieee.c (H_PRECISION): Macro for precision of float16 type. (atof_ieee): Set precision and exponent bits for encoding float16 types. (gen_to_words): NaN and Infinity encoding for float16. (ieee_md_atof): Set precision for encoding float16 type.
2019-08-12 12:08:36 +02:00
case 'H':
case 'h':
prec = H_PRECISION;
break;
case 'f':
case 'F':
case 's':
case 'S':
prec = F_PRECISION;
break;
case 'd':
case 'D':
case 'r':
case 'R':
prec = D_PRECISION;
break;
case 't':
case 'T':
prec = X_PRECISION;
type = 'x'; /* This is what atof_ieee() understands. */
break;
case 'x':
case 'X':
case 'p':
case 'P':
#ifdef TC_M68K
/* Note: on the m68k there is a gap of 16 bits (one littlenum)
between the exponent and mantissa. Hence the precision is
6 and not 5. */
prec = P_PRECISION + 1;
#else
prec = P_PRECISION;
1999-05-03 09:29:11 +02:00
#endif
break;
default:
break;
}
}
/* The 'f' and 'd' types are always recognised, even if the target has
not put them into the FLT_CHARS macro. This is because the 'f' type
can come from the .dc.s, .dcb.s, .float or .single pseudo-ops and the
'd' type from the .dc.d, .dbc.d or .double pseudo-ops.
Fix spelling mistakes and typos in the GAS sources. PR gas/21072 * asintl.h: Fix spelling mistakes and typos. * atof-generic.c: Likewise. * bit_fix.h: Likewise. * config/atof-ieee.c: Likewise. * config/bfin-defs.h: Likewise. * config/bfin-parse.y: Likewise. * config/obj-coff-seh.h: Likewise. * config/obj-coff.c: Likewise. * config/obj-evax.c: Likewise. * config/obj-macho.c: Likewise. * config/rx-parse.y: Likewise. * config/tc-aarch64.c: Likewise. * config/tc-alpha.c: Likewise. * config/tc-arc.c: Likewise. * config/tc-arm.c: Likewise. * config/tc-avr.c: Likewise. * config/tc-bfin.c: Likewise. * config/tc-cr16.c: Likewise. * config/tc-cris.c: Likewise. * config/tc-crx.c: Likewise. * config/tc-d10v.c: Likewise. * config/tc-d30v.c: Likewise. * config/tc-dlx.c: Likewise. * config/tc-epiphany.c: Likewise. * config/tc-frv.c: Likewise. * config/tc-hppa.c: Likewise. * config/tc-i370.c: Likewise. * config/tc-i386-intel.c: Likewise. * config/tc-i386.c: Likewise. * config/tc-i960.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-m32r.c: Likewise. * config/tc-m68hc11.c: Likewise. * config/tc-m68k.c: Likewise. * config/tc-mcore.c: Likewise. * config/tc-mep.c: Likewise. * config/tc-mep.h: Likewise. * config/tc-metag.c: Likewise. * config/tc-microblaze.c: Likewise. * config/tc-mips.c: Likewise. * config/tc-mmix.c: Likewise. * config/tc-mn10200.c: Likewise. * config/tc-mn10300.c: Likewise. * config/tc-msp430.c: Likewise. * config/tc-msp430.h: Likewise. * config/tc-nds32.c: Likewise. * config/tc-nds32.h: Likewise. * config/tc-nios2.c: Likewise. * config/tc-nios2.h: Likewise. * config/tc-ns32k.c: Likewise. * config/tc-pdp11.c: Likewise. * config/tc-ppc.c: Likewise. * config/tc-pru.c: Likewise. * config/tc-rx.c: Likewise. * config/tc-s390.c: Likewise. * config/tc-score.c: Likewise. * config/tc-score7.c: Likewise. * config/tc-sh.c: Likewise. * config/tc-sh64.c: Likewise. * config/tc-sparc.c: Likewise. * config/tc-tic4x.c: Likewise. * config/tc-tic54x.c: Likewise. * config/tc-v850.c: Likewise. * config/tc-vax.c: Likewise. * config/tc-visium.c: Likewise. * config/tc-xgate.c: Likewise. * config/tc-xtensa.c: Likewise. * config/tc-z80.c: Likewise. * config/tc-z8k.c: Likewise. * config/te-vms.c: Likewise. * config/xtensa-relax.c: Likewise. * doc/as.texinfo: Likewise. * doc/c-arm.texi: Likewise. * doc/c-hppa.texi: Likewise. * doc/c-i370.texi: Likewise. * doc/c-i386.texi: Likewise. * doc/c-m32r.texi: Likewise. * doc/c-m68k.texi: Likewise. * doc/c-mmix.texi: Likewise. * doc/c-msp430.texi: Likewise. * doc/c-nds32.texi: Likewise. * doc/c-ns32k.texi: Likewise. * doc/c-riscv.texi: Likewise. * doc/c-rx.texi: Likewise. * doc/c-s390.texi: Likewise. * doc/c-tic6x.texi: Likewise. * doc/c-tilegx.texi: Likewise. * doc/c-tilepro.texi: Likewise. * doc/c-v850.texi: Likewise. * doc/c-xgate.texi: Likewise. * doc/c-xtensa.texi: Likewise. * dwarf2dbg.c: Likewise. * ecoff.c: Likewise. * itbl-ops.c: Likewise. * listing.c: Likewise. * macro.c: Likewise. * po/gas.pot: Likewise. * read.c: Likewise. * struc-symbol.h: Likewise. * symbols.h: Likewise. * testsuite/gas/arc/relocs-errors.err: Likewise. * write.c: Likewise.
2017-01-23 16:23:07 +01:00
The 'x' type is not implicitly recognised however, even though it can
be generated by the .dc.x and .dbc.x pseudo-ops because not all targets
can support floating point values that big. ie the target has to
explicitly allow them by putting them into FLT_CHARS. */
else if (type == 'f')
prec = F_PRECISION;
else if (type == 'd')
prec = D_PRECISION;
if (prec == 0)
{
*sizeP = 0;
return _("Unrecognized or unsupported floating point constant");
}
gas_assert (prec <= MAX_LITTLENUMS);
t = atof_ieee (input_line_pointer, type, words);
if (t)
input_line_pointer = t;
*sizeP = prec * sizeof (LITTLENUM_TYPE);
if (big_wordian)
{
for (wordP = words; prec --;)
{
md_number_to_chars (litP, (valueT) (* wordP ++), sizeof (LITTLENUM_TYPE));
litP += sizeof (LITTLENUM_TYPE);
}
}
else
{
for (wordP = words + prec; prec --;)
{
md_number_to_chars (litP, (valueT) (* -- wordP), sizeof (LITTLENUM_TYPE));
litP += sizeof (LITTLENUM_TYPE);
}
}
return NULL;
}