[AArch64,3/3] Add support for float16 (IEEE format) for AArch64 backend.

Message ID ae75487d-8008-b1f6-3d00-952cf9b256e0@arm.com
State New
Headers show
Series
  • Add float16 directive for assembling 16-bit floating point numbers.
Related show

Commit Message

Barnaby Wilks July 11, 2019, 3:27 p.m.
Hello,

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 a float16 directive for assembling 16 bit IEEE 754 floating point numbers
for AArch64.

The syntax of the directive is:
.float16 <0-n decimal numbers>
e.g.
.float16 0.5
.float16 10.2, NaN, 452.09

The floats will always be encoded using the binary16 format as described in the
IEEE 754-2008 standard. There is no need to support Arm's alternative half-precision
format since AArch64 only supports the IEEE format.

Added testcases to verify the correct encoding (for big and little endian targets) and cross-referenced the encodings with
GCC's __fp16 type to ensure consistency.

Cross compiled and regtested on aarch64-none-elf and aarch64-none-linux-gnu with no issues.

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

Thanks,
Barney

gas/ChangeLog:

2019-07-11  Barnaby Wilks<barnaby.wilks@arm.com>

	* config/tc-aarch64.c: Add float16 directive and add "Hh" to acceptable float
	characters.
	* testsuite/gas/aarch64/float16-be.d: New test.
	* testsuite/gas/aarch64/float16-be.s: New test.
	* testsuite/gas/aarch64/float16-le.d: New test.
	* testsuite/gas/aarch64/float16-le.s: New test.

Comments

Tamar Christina July 24, 2019, 11:12 a.m. | #1
Hi Barnaby,

Thanks for the patch!

Your float16-le.s and float-16-be.s look identical to me. Could you delete one and rename it to float16.s and use that as the source for both.

Also could you add a NEWS entry for both these and the AArch32 patches.

Thanks,
Tamar
 

> -----Original Message-----

> From: binutils-owner@sourceware.org <binutils-owner@sourceware.org> On 

> Behalf Of Barnaby Wilks

> Sent: Thursday, July 11, 2019 16:27

> To: binutils@sourceware.org

> Cc: nd <nd@arm.com>; Richard Earnshaw <Richard.Earnshaw@arm.com>; 

> Marcus Shawcroft <Marcus.Shawcroft@arm.com>

> Subject: [PATCH][binutils][AArch64][3/3] Add support for float16 (IEEE

> format) for AArch64 backend.

> 

> Hello,

> 

> 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 a float16 directive for assembling 16 bit IEEE

> 754 floating point numbers for AArch64.

> 

> The syntax of the directive is:

> .float16 <0-n decimal numbers>

> e.g.

> .float16 0.5

> .float16 10.2, NaN, 452.09

> 

> The floats will always be encoded using the binary16 format as 

> described in the IEEE 754-2008 standard. There is no need to support 

> Arm's alternative half-precision format since AArch64 only supports the IEEE format.

> 

> Added testcases to verify the correct encoding (for big and little 

> endian

> targets) and cross-referenced the encodings with GCC's __fp16 type to 

> ensure consistency.

> 

> Cross compiled and regtested on aarch64-none-elf and

> aarch64-none-linux- gnu with no issues.

> 

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

> my behalf?

> 

> Thanks,

> Barney

> 

> gas/ChangeLog:

> 

> 2019-07-11  Barnaby Wilks<barnaby.wilks@arm.com>

> 

> 	* config/tc-aarch64.c: Add float16 directive and add "Hh" to 

> acceptable float

> 	characters.

> 	* testsuite/gas/aarch64/float16-be.d: New test.

> 	* testsuite/gas/aarch64/float16-be.s: New test.

> 	* testsuite/gas/aarch64/float16-le.d: New test.

> 	* testsuite/gas/aarch64/float16-le.s: New test.
Tamar Christina July 24, 2019, 1:40 p.m. | #2
And also document the new directive in gas/doc/c-aarch64.texi (and same for the Arm equivalent).

Thanks,
Tamar

> -----Original Message-----

> From: binutils-owner@sourceware.org <binutils-owner@sourceware.org>

> On Behalf Of Tamar Christina

> Sent: Wednesday, July 24, 2019 12:12

> To: Barnaby Wilks <Barnaby.Wilks@arm.com>; binutils@sourceware.org

> Cc: nd <nd@arm.com>; Richard Earnshaw <Richard.Earnshaw@arm.com>;

> Marcus Shawcroft <Marcus.Shawcroft@arm.com>

> Subject: RE: [PATCH][binutils][AArch64][3/3] Add support for float16 (IEEE

> format) for AArch64 backend.

> 

> Hi Barnaby,

> 

> Thanks for the patch!

> 

> Your float16-le.s and float-16-be.s look identical to me. Could you delete one

> and rename it to float16.s and use that as the source for both.

> 

> Also could you add a NEWS entry for both these and the AArch32 patches.

> 

> Thanks,

> Tamar

> 

> 

> > -----Original Message-----

> > From: binutils-owner@sourceware.org <binutils-owner@sourceware.org>

> On

> > Behalf Of Barnaby Wilks

> > Sent: Thursday, July 11, 2019 16:27

> > To: binutils@sourceware.org

> > Cc: nd <nd@arm.com>; Richard Earnshaw <Richard.Earnshaw@arm.com>;

> > Marcus Shawcroft <Marcus.Shawcroft@arm.com>

> > Subject: [PATCH][binutils][AArch64][3/3] Add support for float16 (IEEE

> > format) for AArch64 backend.

> >

> > Hello,

> >

> > 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 a float16 directive for assembling 16 bit IEEE

> > 754 floating point numbers for AArch64.

> >

> > The syntax of the directive is:

> > .float16 <0-n decimal numbers>

> > e.g.

> > .float16 0.5

> > .float16 10.2, NaN, 452.09

> >

> > The floats will always be encoded using the binary16 format as

> > described in the IEEE 754-2008 standard. There is no need to support

> > Arm's alternative half-precision format since AArch64 only supports the

> IEEE format.

> >

> > Added testcases to verify the correct encoding (for big and little

> > endian

> > targets) and cross-referenced the encodings with GCC's __fp16 type to

> > ensure consistency.

> >

> > Cross compiled and regtested on aarch64-none-elf and

> > aarch64-none-linux- gnu with no issues.

> >

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

> > my behalf?

> >

> > Thanks,

> > Barney

> >

> > gas/ChangeLog:

> >

> > 2019-07-11  Barnaby Wilks<barnaby.wilks@arm.com>

> >

> > 	* config/tc-aarch64.c: Add float16 directive and add "Hh" to

> > acceptable float

> > 	characters.

> > 	* testsuite/gas/aarch64/float16-be.d: New test.

> > 	* testsuite/gas/aarch64/float16-be.s: New test.

> > 	* testsuite/gas/aarch64/float16-le.d: New test.

> > 	* testsuite/gas/aarch64/float16-le.s: New test.
Barnaby Wilks Aug. 8, 2019, 4:27 p.m. | #3
Hello,

This is an updated patch to include documentation and a NEWS entry for this patch series. (The original patch
is here https://sourceware.org/ml/binutils/2019-07/msg00117.html).

This is part of a patch series that implements a directive for assembling 16-bit floating point constants for Arm and AArch64.
This patch includes a NEWS entry that covers the changes made in this AArch64 patch and the previous Arm patch.

This patch implements a float16 directive for assembling 16 bit IEEE 754 floating point numbers
for AArch64.

The syntax of the directive is:
.float16 <0-n decimal numbers>
e.g.
.float16 0.5
.float16 10.2, NaN, 452.09

The floats will always be encoded using the binary16 format as described in the
IEEE 754-2008 standard. There is no need to support Arm's alternative half-precision
format since AArch64 only supports the IEEE format.

Added testcases to verify the correct encoding (for big and little endian targets) and cross-referenced the encodings with
GCC's __fp16 type to ensure consistency.

Cross compiled and regtested on aarch64-none-elf and aarch64-none-linux-gnu with no issues.

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

Thanks,
Barney

gas/ChangeLog:

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

	* config/tc-aarch64.c: Add float16 directive and add "Hh" to acceptable float
	characters.
	* doc/c-aarch64.texi: Documentation for float16 directive.
	* testsuite/gas/aarch64/float16-be.d: New test.
	* testsuite/gas/aarch64/float16-le.d: New test.
	* testsuite/gas/aarch64/float16.s: New test.
	* NEWS: Add NEWS entry.
diff --git a/gas/NEWS b/gas/NEWS
index ff88fe900146b57e38fde5bbbc389cd803cc7147..592c6cd77b019ad213b3d968f9088970c6567538 100644
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -8,6 +8,11 @@
   to set the default behavior. Set the default if the configure option is not used
   to "no".
 
+* Add .float16 directive for both Arm and AArch64 to allow encoding of 16-bit
+  floating point literals.  Add .float16_format directive and
+  -mfp16-format=[ieee|alternative] option for Arm to control the format of the
+  encoding.
+
 Changes in 2.32:
 
 * Add -mvexwig=[0|1] option to x86 assembler to control encoding of
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 4c19cd4a24a7459bd5b48493ea95f40c96a9a0fa..0665b58cc6e52f8779be2ef2dca9aa9fbd88c021 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -529,7 +529,7 @@ const char EXP_CHARS[] = "eE";
 /* As in 0f12.456  */
 /* or	 0d1.2345e12  */
 
-const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
+const char FLT_CHARS[] = "rRsSfFdDxXeEpPhH";
 
 /* Prefix character that indicates the start of an immediate value.  */
 #define is_immediate_prefix(C) ((C) == '#')
@@ -2106,6 +2106,7 @@ const pseudo_typeS md_pseudo_table[] = {
   {"dword", s_aarch64_elf_cons, 8},
   {"variant_pcs", s_variant_pcs, 0},
 #endif
+  {"float16", float_cons, 'h'},
   {0, 0, 0}
 };
 
diff --git a/gas/doc/c-aarch64.texi b/gas/doc/c-aarch64.texi
index 05e49ad6a8c0385bacb3df5d562f7863764fd768..bade55adb60546361d756eb09b284ead4802c5a7 100644
--- a/gas/doc/c-aarch64.texi
+++ b/gas/doc/c-aarch64.texi
@@ -353,6 +353,14 @@ The @code{.even} directive aligns the output on the next even byte
 boundary.
 
 @c FFFFFFFFFFFFFFFFFFFFFFFFFF
+
+@cindex @code{.float16} directive, AArch64
+@item .float16 @var{value [,...,value_n]}
+Place the half precision floating point representation of one or more
+floating-point values into the current section.
+The format used to encode the floating point values is always the
+IEEE 754-2008 half precision floating point format.
+
 @c GGGGGGGGGGGGGGGGGGGGGGGGGG
 @c HHHHHHHHHHHHHHHHHHHHHHHHHH
 @c IIIIIIIIIIIIIIIIIIIIIIIIII
diff --git a/gas/testsuite/gas/aarch64/float16-be.d b/gas/testsuite/gas/aarch64/float16-be.d
new file mode 100644
index 0000000000000000000000000000000000000000..f47962f3a78ac9b85d13e7a957a6d5cedad37c29
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/float16-be.d
@@ -0,0 +1,11 @@
+# name: Big endian float16 literals (IEEE 754 format)
+# source: float16.s
+# objdump: -s --section=.data
+# as: -mbig-endian
+
+.*: +file format .*
+
+Contents of section \.data:
+ 0000 4a002fdf 1c197bff 000103ff 04003c00.*
+ 0010 3c017fff 7c00fc00 00008000 bc00bbe7.*
+ 0020 fbff4200 4a00603e.*
diff --git a/gas/testsuite/gas/aarch64/float16-le.d b/gas/testsuite/gas/aarch64/float16-le.d
new file mode 100644
index 0000000000000000000000000000000000000000..873d96731fafad293d2bd6605e9832b0a1f63ec3
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/float16-le.d
@@ -0,0 +1,11 @@
+# name: Little endian float16 literals (IEEE 754 format)
+# source: float16.s
+# objdump: -s --section=.data
+# as: -mlittle-endian
+
+.*: +file format .*
+
+Contents of section \.data:
+ 0000 004adf2f 191cff7b 0100ff03 0004003c.*
+ 0010 013cff7f 007c00fc 00000080 00bce7bb.*
+ 0020 fffb0042 004a3e60.*
diff --git a/gas/testsuite/gas/aarch64/float16.s b/gas/testsuite/gas/aarch64/float16.s
new file mode 100644
index 0000000000000000000000000000000000000000..d2cf6b51a6367ed3e87456d1544bb291c9cdce49
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/float16.s
@@ -0,0 +1,19 @@
+.data
+	.float16 12.0
+	.float16 0.123
+	.float16 0.004
+	.float16 65504
+	.float16 5.9605e-8
+	.float16 6.0976e-5
+	.float16 6.1035e-5
+	.float16 1
+	.float16 1.001
+	.float16 NaN
+	.float16 +Inf
+	.float16 -Inf
+	.float16 +0
+	.float16 -0
+	.float16 -1
+	.float16 -0.98765
+	.float16 -65504
+	.float16 3.0, 12.0, 543.123
Barnaby Wilks Aug. 19, 2019, 11:23 a.m. | #4
Hi,

Pinging this patch, could someone give this the once over and apply it 
if it's all OK?

This patch doesn't require the generic IEEE float16 patch
(https://sourceware.org/ml/binutils/2019-07/msg00115.html)
to be applied first, as that has already been committed as part of the 
Arm patch (https://sourceware.org/ml/binutils/2019-08/msg00080.html).

Regards,

Barney

On 8/8/19 5:27 PM, Barnaby Wilks wrote:
> Hello,

> 

> This is an updated patch to include documentation and a NEWS entry for this patch series. (The original patch

> is here https://sourceware.org/ml/binutils/2019-07/msg00117.html).

> 

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

> This patch includes a NEWS entry that covers the changes made in this AArch64 patch and the previous Arm patch.

> 

> This patch implements a float16 directive for assembling 16 bit IEEE 754 floating point numbers

> for AArch64.

> 

> The syntax of the directive is:

> .float16 <0-n decimal numbers>

> e.g.

> .float16 0.5

> .float16 10.2, NaN, 452.09

> 

> The floats will always be encoded using the binary16 format as described in the

> IEEE 754-2008 standard. There is no need to support Arm's alternative half-precision

> format since AArch64 only supports the IEEE format.

> 

> Added testcases to verify the correct encoding (for big and little endian targets) and cross-referenced the encodings with

> GCC's __fp16 type to ensure consistency.

> 

> Cross compiled and regtested on aarch64-none-elf and aarch64-none-linux-gnu with no issues.

> 

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

> 

> Thanks,

> Barney

> 

> gas/ChangeLog:

> 

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

> 

> 	* config/tc-aarch64.c: Add float16 directive and add "Hh" to acceptable float

> 	characters.

> 	* doc/c-aarch64.texi: Documentation for float16 directive.

> 	* testsuite/gas/aarch64/float16-be.d: New test.

> 	* testsuite/gas/aarch64/float16-le.d: New test.

> 	* testsuite/gas/aarch64/float16.s: New test.

> 	* NEWS: Add NEWS entry.

>
Nick Clifton Aug. 22, 2019, 10:15 a.m. | #5
Hi Barnaby,

> Pinging this patch, could someone give this the once over and apply it 

> if it's all OK?


Sorry for missing this one.  Yes the patch is OK, and I have now applied it.

Cheers
  Nick

Patch

diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 000a81c64f8e95eef920fe447358f99bb68b84f9..fa25dce0730794d8d7af41f6d26e854c8210b504 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -529,7 +529,7 @@  const char EXP_CHARS[] = "eE";
 /* As in 0f12.456  */
 /* or	 0d1.2345e12  */
 
-const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
+const char FLT_CHARS[] = "rRsSfFdDxXeEpPhH";
 
 /* Prefix character that indicates the start of an immediate value.  */
 #define is_immediate_prefix(C) ((C) == '#')
@@ -2106,6 +2106,7 @@  const pseudo_typeS md_pseudo_table[] = {
   {"dword", s_aarch64_elf_cons, 8},
   {"variant_pcs", s_variant_pcs, 0},
 #endif
+  {"float16", float_cons, 'h'},
   {0, 0, 0}
 };
 
diff --git a/gas/testsuite/gas/aarch64/float16-be.d b/gas/testsuite/gas/aarch64/float16-be.d
new file mode 100644
index 0000000000000000000000000000000000000000..0dfc66b0d1234384f6a3c135acd20cd7f6d8e397
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/float16-be.d
@@ -0,0 +1,11 @@ 
+# name: Big endian float16 literals (IEEE 754 format)
+# source: float16-be.s
+# objdump: -s --section=.data
+# as: -mbig-endian
+
+.*: +file format .*
+
+Contents of section \.data:
+ 0000 4a002fdf 1c197bff 000103ff 04003c00.*
+ 0010 3c017fff 7c00fc00 00008000 bc00bbe7.*
+ 0020 fbff4200 4a00603e.*
diff --git a/gas/testsuite/gas/aarch64/float16-be.s b/gas/testsuite/gas/aarch64/float16-be.s
new file mode 100644
index 0000000000000000000000000000000000000000..d2cf6b51a6367ed3e87456d1544bb291c9cdce49
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/float16-be.s
@@ -0,0 +1,19 @@ 
+.data
+	.float16 12.0
+	.float16 0.123
+	.float16 0.004
+	.float16 65504
+	.float16 5.9605e-8
+	.float16 6.0976e-5
+	.float16 6.1035e-5
+	.float16 1
+	.float16 1.001
+	.float16 NaN
+	.float16 +Inf
+	.float16 -Inf
+	.float16 +0
+	.float16 -0
+	.float16 -1
+	.float16 -0.98765
+	.float16 -65504
+	.float16 3.0, 12.0, 543.123
diff --git a/gas/testsuite/gas/aarch64/float16-le.d b/gas/testsuite/gas/aarch64/float16-le.d
new file mode 100644
index 0000000000000000000000000000000000000000..64d02f736f0da56086f22326b21c83418bd68dcb
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/float16-le.d
@@ -0,0 +1,11 @@ 
+# name: Little endian float16 literals (IEEE 754 format)
+# source: float16-le.s
+# objdump: -s --section=.data
+# as: -mlittle-endian
+
+.*: +file format .*
+
+Contents of section \.data:
+ 0000 004adf2f 191cff7b 0100ff03 0004003c.*
+ 0010 013cff7f 007c00fc 00000080 00bce7bb.*
+ 0020 fffb0042 004a3e60.*
diff --git a/gas/testsuite/gas/aarch64/float16-le.s b/gas/testsuite/gas/aarch64/float16-le.s
new file mode 100644
index 0000000000000000000000000000000000000000..d2cf6b51a6367ed3e87456d1544bb291c9cdce49
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/float16-le.s
@@ -0,0 +1,19 @@ 
+.data
+	.float16 12.0
+	.float16 0.123
+	.float16 0.004
+	.float16 65504
+	.float16 5.9605e-8
+	.float16 6.0976e-5
+	.float16 6.1035e-5
+	.float16 1
+	.float16 1.001
+	.float16 NaN
+	.float16 +Inf
+	.float16 -Inf
+	.float16 +0
+	.float16 -0
+	.float16 -1
+	.float16 -0.98765
+	.float16 -65504
+	.float16 3.0, 12.0, 543.123