[1/3] Generic support for IEEE 754 floating point numbers.

Message ID 909f013f-b291-0a58-e0a6-da0bd63b8cb8@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:26 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 contains generic support for half-precision IEEE 754 floating 
point numbers that applies for any
target.

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.

Cross compiled and regtested on aarch64-none-elf, 
aarch64-none-linux-gnu, 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-07-11 Barnaby Wilks <barnaby.wilks@arm.com>

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

Patch

diff --git a/gas/config/atof-ieee.c b/gas/config/atof-ieee.c
index 9bb9e55d26658a8d3b34d424a17062fb2074618b..944c8a46ff486ddc4cedc7fe4679b2e1d862a5f5 100644
--- a/gas/config/atof-ieee.c
+++ b/gas/config/atof-ieee.c
@@ -26,6 +26,7 @@  extern FLONUM_TYPE generic_floating_point_number;
 /* Precision in LittleNums.  */
 /* Don't count the gap in the m68k extended precision format.  */
 #define MAX_PRECISION  5
+#define H_PRECISION    1
 #define F_PRECISION    2
 #define D_PRECISION    4
 #define X_PRECISION    5
@@ -190,6 +191,12 @@  atof_ieee (char *str,			/* Text to convert to binary.  */
 
   switch (what_kind)
     {
+    case 'h':
+    case 'H':
+      precision = H_PRECISION;
+      exponent_bits = 5;
+      break;
+
     case 'f':
     case 'F':
     case 's':
@@ -283,8 +290,13 @@  gen_to_words (LITTLENUM_TYPE *words, int precision, long exponent_bits)
   if (generic_floating_point_number.sign == 0)
     {
       if (TC_LARGEST_EXPONENT_IS_NORMAL (precision))
-	as_warn (_("NaNs are not supported by this target\n"));
-      if (precision == F_PRECISION)
+	as_warn (_("NaNs are not supported by this target"));
+
+      if (precision == H_PRECISION)
+	{
+	  words[0] = 0x7fff;
+	}
+      else if (precision == F_PRECISION)
 	{
 	  words[0] = 0x7fff;
 	  words[1] = 0xffff;
@@ -322,10 +334,14 @@  gen_to_words (LITTLENUM_TYPE *words, int precision, long exponent_bits)
   else if (generic_floating_point_number.sign == 'P')
     {
       if (TC_LARGEST_EXPONENT_IS_NORMAL (precision))
-	as_warn (_("Infinities are not supported by this target\n"));
+	as_warn (_("Infinities are not supported by this target"));
 
       /* +INF:  Do the right thing.  */
-      if (precision == F_PRECISION)
+      if (precision == H_PRECISION)
+	{
+	  words[0] = 0x7c00;
+	}
+      else if (precision == F_PRECISION)
 	{
 	  words[0] = 0x7f80;
 	  words[1] = 0;
@@ -363,10 +379,14 @@  gen_to_words (LITTLENUM_TYPE *words, int precision, long exponent_bits)
   else if (generic_floating_point_number.sign == 'N')
     {
       if (TC_LARGEST_EXPONENT_IS_NORMAL (precision))
-	as_warn (_("Infinities are not supported by this target\n"));
+	as_warn (_("Infinities are not supported by this target"));
 
       /* Negative INF.  */
-      if (precision == F_PRECISION)
+      if (precision == H_PRECISION)
+	{
+	  words[0] = 0xfc00;
+	}
+      else if (precision == F_PRECISION)
 	{
 	  words[0] = 0xff80;
 	  words[1] = 0x0;
@@ -721,6 +741,11 @@  ieee_md_atof (int type,
     {
       switch (type)
 	{
+	case 'H':
+	case 'h':
+	  prec = H_PRECISION;
+	  break;
+
 	case 'f':
 	case 'F':
 	case 's':