[PATCH][binutils][Arm][2/3] Add support for float16 (IEEE and Alternative formats) for Arm backend.

Barnaby Wilks Barnaby.Wilks@arm.com
Thu Aug 8 16:08:00 GMT 2019


Hello,

This is a reworked version of the original patch (https://sourceware.org/ml/binutils/2019-07/msg00116.html) - now the format
used to encode the float16's is controlled by the .float16_format directive and a -mfp16-format option instead of being controlled
by the Tag_ABI_FP_16bit_format EABI attribute.

This is part of a patch series that implements a directive for assembling 16-bit floating point constants for Arm and AArch64.

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.

Added testcases to verify the correct encoding for both formats (for both big and little endian targets),
as well as tests verifying that warnings are thrown if trying to encode NaN or Infinity when using
the Arm alternative format. Tests verifying that trying to set different formats is as expected (i.e.
only use the first specified format) and tests to verify that (for ELF targets) EABI attributes are written
(or not written) correctly.
The encodings have been cross referenced with GCC's encoding for __fp16 types to ensure consistency.

Cross compiled and regtested on arm-none-eabi and arm-none-linux-gnueabihf

I don't have write access, so if it's OK then could someone commit on my behalf?

Thanks,
Barney

gas/ChangeLog:

2019-08-29  Barnaby Wilks<barnaby.wilks@arm.com>

	* 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.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: float16-arm-updated.txt
URL: <https://sourceware.org/pipermail/binutils/attachments/20190808/58dc0304/attachment.txt>


More information about the Binutils mailing list