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

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