diff mbox

[15/17,libgcc,ARM] Add double to half conversions.

Message ID 1478878946-22725-2-git-send-email-james.greenhalgh@arm.com
State New
Headers show

Commit Message

James Greenhalgh Nov. 11, 2016, 3:42 p.m. UTC
Hi,

Conversions from double precision floats to the ARM __fp16 are required
to round only once.

This patch adds a functions named __gnu_d2h_ieee and
__gnu_d2h_alternative for double to __fp16 conversions in IEEE and ARM
alternative format. The make use of the existing __gnu_float2h_internal
conversion function which rounds once only.

Bootstrapped on an ARMv8-A machine with no issues, and cross-tested with
a range of multilibs.

OK?

Thanks,
James
---

libgcc/

2016-11-09  James Greenhalgh  <james.greenhalgh@arm.com>
	    Matthew Wahab  <matthew.wahab@arm.com>

	* config/arm/fp16.c (binary64): New.
	(__gnu_d2h_internal): New.
	(__gnu_d2h_ieee): New.
	(__gnu_d2h_alternative): New.

Comments

Kyrill Tkachov Nov. 16, 2016, 2:46 p.m. UTC | #1
On 11/11/16 15:42, James Greenhalgh wrote:
> Hi,

>

> Conversions from double precision floats to the ARM __fp16 are required

> to round only once.

>

> This patch adds a functions named __gnu_d2h_ieee and

> __gnu_d2h_alternative for double to __fp16 conversions in IEEE and ARM

> alternative format. The make use of the existing __gnu_float2h_internal

> conversion function which rounds once only.

>

> Bootstrapped on an ARMv8-A machine with no issues, and cross-tested with

> a range of multilibs.

>

> OK?


Ok.
Thanks,
Kyrill

> Thanks,

> James

> ---

>

> libgcc/

>

> 2016-11-09  James Greenhalgh  <james.greenhalgh@arm.com>

> 	    Matthew Wahab  <matthew.wahab@arm.com>

>

> 	* config/arm/fp16.c (binary64): New.

> 	(__gnu_d2h_internal): New.

> 	(__gnu_d2h_ieee): New.

> 	(__gnu_d2h_alternative): New.

>
diff mbox

Patch

diff --git a/libgcc/config/arm/fp16.c b/libgcc/config/arm/fp16.c
index ba89796..a656988 100644
--- a/libgcc/config/arm/fp16.c
+++ b/libgcc/config/arm/fp16.c
@@ -43,6 +43,15 @@  binary32 =
   23    /* significand.  */
 };
 
+static const struct format
+binary64 =
+{
+  64,    /* size.  */
+  1023,  /* bias.  */
+  11,    /* exponent.  */
+  52     /* significand.  */
+};
+
 static inline unsigned short
 __gnu_float2h_internal (const struct format* fmt,
 			unsigned long long a, int ieee)
@@ -136,6 +145,12 @@  __gnu_f2h_internal (unsigned int a, int ieee)
   return __gnu_float2h_internal (&binary32, (unsigned long long) a, ieee);
 }
 
+static inline unsigned short
+__gnu_d2h_internal (unsigned long long a, int ieee)
+{
+  return __gnu_float2h_internal (&binary64, a, ieee);
+}
+
 unsigned int
 __gnu_h2f_internal(unsigned short a, int ieee)
 {
@@ -184,3 +199,15 @@  __gnu_h2f_alternative(unsigned short a)
 {
   return __gnu_h2f_internal(a, 0);
 }
+
+unsigned short
+__gnu_d2h_ieee (unsigned long long a)
+{
+  return __gnu_d2h_internal (a, 1);
+}
+
+unsigned short
+__gnu_d2h_alternative (unsigned long long x)
+{
+  return __gnu_d2h_internal (x, 0);
+}