[Patch][binutils] Generic support for parsing numbers in bfloat16 format [5/X]

Hi,

This patch is part of a series that adds support for Armv8.6-A
(Matrix Multiply and BFloat16 extensions).

This patch contains some general refactoring of the atof_ieee
function, exposing a function that allows a higher level of control
over the format of IEEE-like floating point numbers.
This has been done in order to be able to add a directive for assembling
floating point literals in the bfloat16 format in the following patches.

Committed on behalf of Mihail Ionescu.

Tested on arm-none-eabi, arm-none-linux-gnueabihf, aarch64-none-elf
and aarch64-none-linux-gnuwith no issues.

gas/ChangeLog:

2019-10-21  Mihail Ionescu  <mihail.ionescu@arm.com>
2019-10-21  Barnaby Wilks  <barnaby.wilks@arm.com>

	* as.h (atof_ieee_detail): Add prototype for atof_ieee_detail function.
	(atof_ieee): Move some code into the atof_ieee_detail function.
	(atof_ieee_detail): Add function that provides a higher level of control over generating
	IEEE-like numbers.

Is it ok for trunk?

Regards,
Mihail
This commit is contained in:
Matthew Malcomson 2019-11-07 17:01:04 +00:00
parent aab2c27d9f
commit c96f148b7b
3 changed files with 63 additions and 29 deletions

View File

@ -1,3 +1,11 @@
2019-11-07 Mihail Ionescu <mihail.ionescu@arm.com>
2019-11-07 Barnaby Wilks <barnaby.wilks@arm.com>
* as.h (atof_ieee_detail): Add prototype for atof_ieee_detail function.
(atof_ieee): Move some code into the atof_ieee_detail function.
(atof_ieee_detail): Add function that provides a higher level of
control over generating IEEE-like numbers.
2019-11-07 Mihail Ionescu <mihail.ionescu@arm.com> 2019-11-07 Mihail Ionescu <mihail.ionescu@arm.com>
2019-11-07 Matthew Malcomson <matthew.malcomson@arm.com> 2019-11-07 Matthew Malcomson <matthew.malcomson@arm.com>

View File

@ -484,6 +484,7 @@ char * app_push (void);
#define MAX_LITTLENUMS 6 #define MAX_LITTLENUMS 6
char * atof_ieee (char *, int, LITTLENUM_TYPE *); char * atof_ieee (char *, int, LITTLENUM_TYPE *);
char * atof_ieee_detail (char *, int, int, LITTLENUM_TYPE *, FLONUM_TYPE *);
const char * ieee_md_atof (int, char *, int *, bfd_boolean); const char * ieee_md_atof (int, char *, int *, bfd_boolean);
const char * vax_md_atof (int, char *, int *); const char * vax_md_atof (int, char *, int *);
char * input_scrub_include_file (const char *, char *); char * input_scrub_include_file (const char *, char *);

View File

@ -146,29 +146,30 @@ make_invalid_floating_point_number (LITTLENUM_TYPE *words)
words[4] = (LITTLENUM_TYPE) -1; words[4] = (LITTLENUM_TYPE) -1;
words[5] = (LITTLENUM_TYPE) -1; words[5] = (LITTLENUM_TYPE) -1;
} }
/* 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 /* Build a floating point constant at str into a IEEE floating
to md_atof to filter them out if the target machine does not support point number. This function does the same thing as atof_ieee
them. */ 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.
/* Returns pointer past text consumed. */ 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. */
char * char *
atof_ieee (char *str, /* Text to convert to binary. */ atof_ieee_detail (char * str,
int what_kind, /* 'd', 'f', 'x', 'p'. */ int precision,
LITTLENUM_TYPE *words) /* Build the binary here. */ int exponent_bits,
LITTLENUM_TYPE * words,
FLONUM_TYPE * generic_float_info)
{ {
/* Extra bits for zeroed low-order bits. /* Extra bits for zeroed low-order bits.
The 1st MAX_PRECISION are zeroed, the last contain flonum bits. */ The 1st MAX_PRECISION are zeroed, the last contain flonum bits. */
static LITTLENUM_TYPE bits[MAX_PRECISION + MAX_PRECISION + GUARD]; static LITTLENUM_TYPE bits[MAX_PRECISION + MAX_PRECISION + GUARD];
char *return_value; char *return_value;
/* Number of 16-bit words in the format. */ /* Number of 16-bit words in the format. */
int precision;
long exponent_bits;
FLONUM_TYPE save_gen_flonum; FLONUM_TYPE save_gen_flonum;
/* We have to save the generic_floating_point_number because it /* We have to save the generic_floating_point_number because it
@ -189,6 +190,45 @@ atof_ieee (char *str, /* Text to convert to binary. */
memset (bits, '\0', sizeof (LITTLENUM_TYPE) * MAX_PRECISION); 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;
switch (what_kind) switch (what_kind)
{ {
case 'h': case 'h':
@ -232,22 +272,7 @@ atof_ieee (char *str, /* Text to convert to binary. */
return (NULL); return (NULL);
} }
generic_floating_point_number.high return atof_ieee_detail (str, precision, exponent_bits, words, NULL);
= 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;
}
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;
} }
/* Turn generic_floating_point_number into a real float/double/extended. */ /* Turn generic_floating_point_number into a real float/double/extended. */