soft-fp: Add floattixf.c and floatuntixf.c
diff mbox series

Message ID 20190121194255.13036-1-hjl.tools@gmail.com
State New
Headers show
Series
  • soft-fp: Add floattixf.c and floatuntixf.c
Related show

Commit Message

H.J. Lu Jan. 21, 2019, 7:42 p.m. UTC
TI->XF conversions in libgcc2.c:

XFtype
__floatdixf (DWtype u)
{
  XFtype d = (Wtype) (u >> W_TYPE_SIZE);
  d *= Wtype_MAXp1_F;
  d += (UWtype)u;
  return d;
}

have no rounding mode support.  Add floattixf.c and floatuntixf.c to
soft-fp to support rounding mode.

	* soft-fp/floattixf.c: New file.
	* soft-fp/floatuntixf.c: Likewise.
---
 soft-fp/floattixf.c   | 45 +++++++++++++++++++++++++++++++++++++++++++
 soft-fp/floatuntixf.c | 45 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 soft-fp/floattixf.c
 create mode 100644 soft-fp/floatuntixf.c

Comments

Joseph Myers Jan. 21, 2019, 10:39 p.m. UTC | #1
On Mon, 21 Jan 2019, H.J. Lu wrote:

> TI->XF conversions in libgcc2.c:
> 
> XFtype
> __floatdixf (DWtype u)
> {
>   XFtype d = (Wtype) (u >> W_TYPE_SIZE);
>   d *= Wtype_MAXp1_F;
>   d += (UWtype)u;
>   return d;
> }
> 
> have no rounding mode support.  Add floattixf.c and floatuntixf.c to

That doesn't need rounding mode support.  XFmode has 64-bit precision, so 
all 64-bit integer values can be represented exactly in XFmode, so that 
function only has a single possibly inexact operation (the addition), so 
only a single rounding, which will use the hardware rounding mode.  (The 
x87 rounding mode, not the SSE rounding mode, of course, but nothing 
should make those two rounding modes different other than a limited amount 
of code inside glibc that optimizes by knowing that certain code only ever 
uses one of the floating-point units so only needs that rounding mode 
changed.)

> soft-fp to support rounding mode.

I see no reasonable use for XFmode soft-fp functions in libgcc (other than 
the conversions to/from TFmode, of course); XFmode is only used in libgcc 
when it's a hardware type, which means the libgcc2.c functions that are 
based around hardware operations are preferable.
H.J. Lu Jan. 21, 2019, 11:24 p.m. UTC | #2
On Mon, Jan 21, 2019 at 2:39 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Mon, 21 Jan 2019, H.J. Lu wrote:
>
> > TI->XF conversions in libgcc2.c:
> >
> > XFtype
> > __floatdixf (DWtype u)
> > {
> >   XFtype d = (Wtype) (u >> W_TYPE_SIZE);
> >   d *= Wtype_MAXp1_F;
> >   d += (UWtype)u;
> >   return d;
> > }
> >
> > have no rounding mode support.  Add floattixf.c and floatuntixf.c to
>
> That doesn't need rounding mode support.  XFmode has 64-bit precision, so
> all 64-bit integer values can be represented exactly in XFmode, so that
> function only has a single possibly inexact operation (the addition), so
> only a single rounding, which will use the hardware rounding mode.  (The
> x87 rounding mode, not the SSE rounding mode, of course, but nothing
> should make those two rounding modes different other than a limited amount
> of code inside glibc that optimizes by knowing that certain code only ever
> uses one of the floating-point units so only needs that rounding mode
> changed.)
>
> > soft-fp to support rounding mode.
>
> I see no reasonable use for XFmode soft-fp functions in libgcc (other than
> the conversions to/from TFmode, of course); XFmode is only used in libgcc
> when it's a hardware type, which means the libgcc2.c functions that are
> based around hardware operations are preferable.
>

You are right.  I withdrew this patch.

Thanks.

Patch
diff mbox series

diff --git a/soft-fp/floattixf.c b/soft-fp/floattixf.c
new file mode 100644
index 0000000000..39ac95daeb
--- /dev/null
+++ b/soft-fp/floattixf.c
@@ -0,0 +1,45 @@ 
+/* Software floating-point emulation.
+   Convert a 128bit signed integer to IEEE extended.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "extended.h"
+
+XFtype
+__floattixf (TItype i)
+{
+  FP_DECL_EX;
+  FP_DECL_E (A);
+  XFtype a;
+
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_E (A, i, TI_BITS, UTItype);
+  FP_PACK_RAW_E (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
diff --git a/soft-fp/floatuntixf.c b/soft-fp/floatuntixf.c
new file mode 100644
index 0000000000..783fea9997
--- /dev/null
+++ b/soft-fp/floatuntixf.c
@@ -0,0 +1,45 @@ 
+/* Software floating-point emulation.
+   Convert a 128bit unsigned integer to IEEE extended.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "extended.h"
+
+XFtype
+__floatuntixf (UTItype i)
+{
+  FP_DECL_EX;
+  FP_DECL_E (A);
+  XFtype a;
+
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_E (A, i, TI_BITS, UTItype);
+  FP_PACK_RAW_E (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}