unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH v2 0/4] LoongArch: Add some floating-point operations
       [not found]   ` <235d9f8e-040c-2917-8444-654b33aa124e@loongson.cn>
@ 2022-11-14  8:05     ` Xi Ruoyao via Libc-alpha
  2022-11-16  9:17       ` tangxiaolin
  2022-11-16 13:00       ` tangxiaolin
  0 siblings, 2 replies; 4+ messages in thread
From: Xi Ruoyao via Libc-alpha @ 2022-11-14  8:05 UTC (permalink / raw)
  To: tangxiaolin, libc-alpha; +Cc: Lulu Cheng, Wang Xuerui, Chenghua Xu, caiyinyu

[-- Attachment #1: Type: text/plain, Size: 3049 bytes --]

On Mon, 2022-11-14 at 10:41 +0800, tangxiaolin wrote:
> How about I do this work on Glibc?

[Moving the discussion to libc-alpha.]

Go for it.  I'm attaching my draft patches and you can use them as a
starting point.

rint change is trivial.  for lrint and llrint I'm not sure if we should
add USE_LRINTL_BUILTIN and USE_LRINTF128_BUILTIN (with zero value) as
well.  Likewise for logb.

scalbn is a little complicated: I'd prefer to expand M_SCALBN to
__builtin_scalbn directly instead of calling __scalbn (to avoid the
overhead calling a function with only two instructions) but it seems not
easy: some files calling M_SCALBN are compiled with -fmath-errno, with
which the compiler will refuse to expand __builtin_scalbn.

> 在 2022/11/12 下午3:08, Xi Ruoyao 写道:
> > On Wed, 2022-11-09 at 21:53 +0800, Xi Ruoyao wrote:
> > > These patches allow to expand the following builtins to floating
> > > point
> > > instructions for LoongArch:
> > > 
> > > - __builtin_rint{,f}
> > > - __builtin_{l,ll}rint{,f}
> > > - __builtin_{l,ll}floor{,f}
> > > - __builtin_{l,ll}ceil{,f}
> > > - __builtin_scalb{n,ln}{,f}
> > > - __builtin_logb{,f}
> > > 
> > > Bootstrapped and regtested on loongarch64-linux-gnu.  And a
> > > modified
> > > Glibc using the builtins for rint{,f}, {l,ll}rint{,f}, and
> > > logb{,f}
> > > also survived Glibc test suite.
> > > 
> > > Please review ASAP because GCC 13 stage 1 will end on Nov. 13th.
> > > 
> > > v1 -> v2: Only use ftint{rm,rp} instructions if floor and ceil are
> > > allowed to raise inexact exception.
> > > 
> > > Xi Ruoyao (4):
> > >    LoongArch: Rename frint_<fmt> to rint<mode>2
> > >    LoongArch: Add ftint{,rm,rp}.{w,l}.{s,d} instructions
> > >    LoongArch: Add fscaleb.{s,d} instructions as ldexp{sf,df}3
> > >    LoongArch: Add flogb.{s,d} instructions and expand logb{sf,df}2
> > > 
> > >   gcc/config/loongarch/loongarch.md             | 95
> > > ++++++++++++++++++-
> > >   gcc/testsuite/gcc.target/loongarch/flogb.c    | 18 ++++
> > >   gcc/testsuite/gcc.target/loongarch/frint.c    | 16 ++++
> > >   gcc/testsuite/gcc.target/loongarch/fscaleb.c  | 48 ++++++++++
> > >   .../gcc.target/loongarch/ftint-no-inexact.c   | 44 +++++++++
> > >   gcc/testsuite/gcc.target/loongarch/ftint.c    | 44 +++++++++
> > >   6 files changed, 261 insertions(+), 4 deletions(-)
> > >   create mode 100644 gcc/testsuite/gcc.target/loongarch/flogb.c
> > >   create mode 100644 gcc/testsuite/gcc.target/loongarch/frint.c
> > >   create mode 100644 gcc/testsuite/gcc.target/loongarch/fscaleb.c
> > >   create mode 100644 gcc/testsuite/gcc.target/loongarch/ftint-no-
> > > inexact.c
> > >   create mode 100644 gcc/testsuite/gcc.target/loongarch/ftint.c
> > > 
> > Pushed r13-3922.
> > 
> > I'll be busy in the following week.  Will do the work on Glibc side
> > after Nov. 20.
> > 
> 

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

[-- Attachment #2: 0005-LoongArch-Use-__builtin_logb-f-with-GCC-13.patch --]
[-- Type: text/x-patch, Size: 799 bytes --]

From e8ab00c0f68f1d294432ddaf68c0c691ed37df19 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@xry111.site>
Date: Wed, 9 Nov 2022 02:02:00 +0800
Subject: [PATCH 5/5] LoongArch: Use __builtin_logb{,f} with GCC >= 13

---
 sysdeps/loongarch/fpu/math-use-builtins-logb.h | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-logb.h

diff --git a/sysdeps/loongarch/fpu/math-use-builtins-logb.h b/sysdeps/loongarch/fpu/math-use-builtins-logb.h
new file mode 100644
index 0000000000..70a9306dfa
--- /dev/null
+++ b/sysdeps/loongarch/fpu/math-use-builtins-logb.h
@@ -0,0 +1,7 @@
+#if __GNUC_PREREQ (13, 0)
+#  define USE_LOGB_BUILTIN 1
+#  define USE_LOGBF_BUILTIN 1
+#else
+#  define USE_LOGB_BUILTIN 0
+#  define USE_LOGBF_BUILTIN 0
+#endif
-- 
2.37.0


[-- Attachment #3: 0004-math-Allow-using-compiler-builtins-for-logb-f.patch --]
[-- Type: text/x-patch, Size: 2553 bytes --]

From a5b8dff144d01ecc5eb76a8e27f7a207a7200807 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@xry111.site>
Date: Wed, 9 Nov 2022 02:01:32 +0800
Subject: [PATCH 4/5] math: Allow using compiler builtins for logb{,f}

---
 sysdeps/generic/math-use-builtins-logb.h | 2 ++
 sysdeps/generic/math-use-builtins.h      | 1 +
 sysdeps/ieee754/dbl-64/s_logb.c          | 5 +++++
 sysdeps/ieee754/flt-32/s_logbf.c         | 5 +++++
 4 files changed, 13 insertions(+)
 create mode 100644 sysdeps/generic/math-use-builtins-logb.h

diff --git a/sysdeps/generic/math-use-builtins-logb.h b/sysdeps/generic/math-use-builtins-logb.h
new file mode 100644
index 0000000000..f8fc9ae7cb
--- /dev/null
+++ b/sysdeps/generic/math-use-builtins-logb.h
@@ -0,0 +1,2 @@
+#define USE_LOGB_BUILTIN 0
+#define USE_LOGBF_BUILTIN 0
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 3acec1d538..a9cd510c2a 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -38,5 +38,6 @@
 #include <math-use-builtins-fmin.h>
 #include <math-use-builtins-fabs.h>
 #include <math-use-builtins-lrint.h>
+#include <math-use-builtins-logb.h>
 
 #endif /* MATH_USE_BUILTINS_H  */
diff --git a/sysdeps/ieee754/dbl-64/s_logb.c b/sysdeps/ieee754/dbl-64/s_logb.c
index 82cabd206a..a9b18bf97b 100644
--- a/sysdeps/ieee754/dbl-64/s_logb.c
+++ b/sysdeps/ieee754/dbl-64/s_logb.c
@@ -21,10 +21,14 @@
 #include <math_private.h>
 #include <libm-alias-double.h>
 #include <fix-int-fp-convert-zero.h>
+#include <math-use-builtins.h>
 
 double
 __logb (double x)
 {
+#if USE_LOGB_BUILTIN
+  return __builtin_logb (x);
+#else
   int64_t ix, ex;
 
   EXTRACT_WORDS64 (ix, x);
@@ -42,6 +46,7 @@ __logb (double x)
   if (FIX_INT_FP_CONVERT_ZERO && ex == 1023)
     return 0.0;
   return (double) (ex - 1023);
+#endif
 }
 #ifndef __logb
 libm_alias_double (__logb, logb)
diff --git a/sysdeps/ieee754/flt-32/s_logbf.c b/sysdeps/ieee754/flt-32/s_logbf.c
index a06f975797..cf58596c8f 100644
--- a/sysdeps/ieee754/flt-32/s_logbf.c
+++ b/sysdeps/ieee754/flt-32/s_logbf.c
@@ -16,10 +16,14 @@
 #include <math_private.h>
 #include <libm-alias-float.h>
 #include <fix-int-fp-convert-zero.h>
+#include <math-use-builtins.h>
 
 float
 __logbf (float x)
 {
+#if USE_LOGBF_BUILTIN
+  return __builtin_logbf (x);
+#else
   int32_t ix, rix;
 
   GET_FLOAT_WORD (ix, x);
@@ -37,5 +41,6 @@ __logbf (float x)
   if (FIX_INT_FP_CONVERT_ZERO && rix == 127)
     return 0.0f;
   return (float) (rix - 127);
+#endif
 }
 libm_alias_float (__logb, logb)
-- 
2.37.0


[-- Attachment #4: 0003-LoongArch-Use-__builtin_-l-ll-rint-f-with-GCC-13.patch --]
[-- Type: text/x-patch, Size: 951 bytes --]

From d8e948afe78222323f72fa1a40ff7e169f7c06cc Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@xry111.site>
Date: Wed, 9 Nov 2022 01:18:52 +0800
Subject: [PATCH 3/5] LoongArch: Use __builtin_{l,ll}rint{,f} with GCC >= 13

---
 sysdeps/loongarch/fpu/math-use-builtins-lrint.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-lrint.h

diff --git a/sysdeps/loongarch/fpu/math-use-builtins-lrint.h b/sysdeps/loongarch/fpu/math-use-builtins-lrint.h
new file mode 100644
index 0000000000..0c8187d09e
--- /dev/null
+++ b/sysdeps/loongarch/fpu/math-use-builtins-lrint.h
@@ -0,0 +1,11 @@
+#if __GNUC_PREREQ (13, 0)
+#  define USE_LRINT_BUILTIN 1
+#  define USE_LRINTF_BUILTIN 1
+#  define USE_LLRINT_BUILTIN 1
+#  define USE_LLRINTF_BUILTIN 1
+#else
+#  define USE_LRINT_BUILTIN 0
+#  define USE_LRINTF_BUILTIN 0
+#  define USE_LLRINT_BUILTIN 0
+#  define USE_LLRINTF_BUILTIN 0
+#endif
-- 
2.37.0


[-- Attachment #5: 0002-math-Allow-using-compiler-builtins-for-l-ll-rint-f.patch --]
[-- Type: text/x-patch, Size: 4632 bytes --]

From dd83a647441d4f6137095bf7a37f75840cd051db Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@xry111.site>
Date: Wed, 9 Nov 2022 01:18:11 +0800
Subject: [PATCH 2/5] math: Allow using compiler builtins for {l,ll}rint{,f}

---
 sysdeps/generic/math-use-builtins-lrint.h | 4 ++++
 sysdeps/generic/math-use-builtins.h       | 1 +
 sysdeps/ieee754/dbl-64/s_llrint.c         | 7 +++++++
 sysdeps/ieee754/dbl-64/s_lrint.c          | 7 +++++++
 sysdeps/ieee754/flt-32/s_llrintf.c        | 7 +++++++
 sysdeps/ieee754/flt-32/s_lrintf.c         | 7 +++++++
 6 files changed, 33 insertions(+)
 create mode 100644 sysdeps/generic/math-use-builtins-lrint.h

diff --git a/sysdeps/generic/math-use-builtins-lrint.h b/sysdeps/generic/math-use-builtins-lrint.h
new file mode 100644
index 0000000000..3159ba977a
--- /dev/null
+++ b/sysdeps/generic/math-use-builtins-lrint.h
@@ -0,0 +1,4 @@
+#define USE_LRINT_BUILTIN 0
+#define USE_LRINTF_BUILTIN 0
+#define USE_LLRINT_BUILTIN 0
+#define USE_LLRINTF_BUILTIN 0
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 6bd424d900..3acec1d538 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -37,5 +37,6 @@
 #include <math-use-builtins-fmax.h>
 #include <math-use-builtins-fmin.h>
 #include <math-use-builtins-fabs.h>
+#include <math-use-builtins-lrint.h>
 
 #endif /* MATH_USE_BUILTINS_H  */
diff --git a/sysdeps/ieee754/dbl-64/s_llrint.c b/sysdeps/ieee754/dbl-64/s_llrint.c
index dc8d9948df..1c041e3b26 100644
--- a/sysdeps/ieee754/dbl-64/s_llrint.c
+++ b/sysdeps/ieee754/dbl-64/s_llrint.c
@@ -25,17 +25,23 @@
 #include <math_private.h>
 #include <libm-alias-double.h>
 #include <fix-fp-int-convert-overflow.h>
+#include <math-use-builtins.h>
 
+#if !USE_LLRINT_BUILTIN
 static const double two52[2] =
 {
   4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
  -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
 };
+#endif
 
 
 long long int
 __llrint (double x)
 {
+#if USE_LLRINT_BUILTIN
+  return __builtin_llrint (x);
+#else
   int32_t j0;
   uint32_t i1, i0;
   long long int result;
@@ -95,6 +101,7 @@ __llrint (double x)
     }
 
   return sx ? -result : result;
+#endif
 }
 
 libm_alias_double (__llrint, llrint)
diff --git a/sysdeps/ieee754/dbl-64/s_lrint.c b/sysdeps/ieee754/dbl-64/s_lrint.c
index d4272916cd..fdb2d86f3f 100644
--- a/sysdeps/ieee754/dbl-64/s_lrint.c
+++ b/sysdeps/ieee754/dbl-64/s_lrint.c
@@ -25,17 +25,23 @@
 #include <math_private.h>
 #include <libm-alias-double.h>
 #include <fix-fp-int-convert-overflow.h>
+#include <math-use-builtins.h>
 
+#if !USE_LRINT_BUILTIN
 static const double two52[2] =
 {
   4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
  -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
 };
+#endif
 
 
 long int
 __lrint (double x)
 {
+#if USE_LRINT_BUILTIN
+  return __builtin_lrint (x);
+#else
   int32_t j0;
   uint32_t i0, i1;
   double w;
@@ -119,6 +125,7 @@ __lrint (double x)
     }
 
   return sx ? -result : result;
+#endif
 }
 
 libm_alias_double (__lrint, lrint)
diff --git a/sysdeps/ieee754/flt-32/s_llrintf.c b/sysdeps/ieee754/flt-32/s_llrintf.c
index 226b8261d3..12654848b8 100644
--- a/sysdeps/ieee754/flt-32/s_llrintf.c
+++ b/sysdeps/ieee754/flt-32/s_llrintf.c
@@ -25,17 +25,23 @@
 #include <math_private.h>
 #include <libm-alias-float.h>
 #include <fix-fp-int-convert-overflow.h>
+#include <math-use-builtins.h>
 
+#if !USE_LLRINTF_BUILTIN
 static const float two23[2] =
 {
   8.3886080000e+06, /* 0x4B000000 */
  -8.3886080000e+06, /* 0xCB000000 */
 };
+#endif
 
 
 long long int
 __llrintf (float x)
 {
+#if USE_LLRINTF_BUILTIN
+  return __builtin_llrintf (x);
+#else
   int32_t j0;
   uint32_t i0;
   float w;
@@ -82,6 +88,7 @@ __llrintf (float x)
     }
 
   return sx ? -result : result;
+#endif
 }
 
 libm_alias_float (__llrint, llrint)
diff --git a/sysdeps/ieee754/flt-32/s_lrintf.c b/sysdeps/ieee754/flt-32/s_lrintf.c
index 7438b272b2..7b0ff994bd 100644
--- a/sysdeps/ieee754/flt-32/s_lrintf.c
+++ b/sysdeps/ieee754/flt-32/s_lrintf.c
@@ -25,17 +25,23 @@
 #include <math_private.h>
 #include <libm-alias-float.h>
 #include <fix-fp-int-convert-overflow.h>
+#include <math-use-builtins.h>
 
+#if !USE_LRINTF_BUILTIN
 static const float two23[2] =
 {
   8.3886080000e+06, /* 0x4B000000 */
  -8.3886080000e+06, /* 0xCB000000 */
 };
+#endif
 
 
 long int
 __lrintf (float x)
 {
+#if USE_LRINTF_BUILTIN
+  return __builtin_lrintf (x);
+#else
   int32_t j0;
   uint32_t i0;
   float w;
@@ -82,6 +88,7 @@ __lrintf (float x)
     }
 
   return sx ? -result : result;
+#endif
 }
 
 libm_alias_float (__lrint, lrint)
-- 
2.37.0


[-- Attachment #6: 0001-LoongArch-Use-__builtin_rint-f-with-GCC-13.patch --]
[-- Type: text/x-patch, Size: 862 bytes --]

From a8d6d6a05cf7cd3acbc5428ce7324ec3867be067 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@xry111.site>
Date: Wed, 9 Nov 2022 01:00:09 +0800
Subject: [PATCH 1/5] LoongArch: Use __builtin_rint{,f} with GCC >= 13

---
 sysdeps/loongarch/fpu/math-use-builtins-rint.h | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-rint.h

diff --git a/sysdeps/loongarch/fpu/math-use-builtins-rint.h b/sysdeps/loongarch/fpu/math-use-builtins-rint.h
new file mode 100644
index 0000000000..cd91482f5f
--- /dev/null
+++ b/sysdeps/loongarch/fpu/math-use-builtins-rint.h
@@ -0,0 +1,9 @@
+#if __GNUC_PREREQ (13, 0)
+#  define USE_RINT_BUILTIN 1
+#  define USE_RINTF_BUILTIN 1
+#else
+#  define USE_RINT_BUILTIN 0
+#  define USE_RINTF_BUILTIN 0
+#endif
+#define USE_RINTL_BUILTIN 0
+#define USE_RINTF128_BUILTIN 0
-- 
2.37.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/4] LoongArch: Add some floating-point operations
  2022-11-14  8:05     ` [PATCH v2 0/4] LoongArch: Add some floating-point operations Xi Ruoyao via Libc-alpha
@ 2022-11-16  9:17       ` tangxiaolin
  2022-11-16 13:00       ` tangxiaolin
  1 sibling, 0 replies; 4+ messages in thread
From: tangxiaolin @ 2022-11-16  9:17 UTC (permalink / raw)
  To: Xi Ruoyao, libc-alpha; +Cc: Lulu Cheng, Wang Xuerui, Chenghua Xu, caiyinyu

Thanks a lot. These patches look very good,  honestly I have nothing to add.

For lrint and llrint, If you ask my suggestion, I would say adding  
USE_LRINTL_BUILTIN and USE_LRINTF128_BUILTIN (with zero value) is better 
for consistency with other functions like ceil.

I did an experiment, 'scalbn' is indeed not easy to deal with, and I don't have a better idea so far.I tend to add inline assembler for this function instead of builtin if you don't have a better idea.

What do you think?

在 2022/11/14 下午4:05, Xi Ruoyao 写道:
> On Mon, 2022-11-14 at 10:41 +0800, tangxiaolin wrote:
>> How about I do this work on Glibc?
> [Moving the discussion to libc-alpha.]
>
> Go for it.  I'm attaching my draft patches and you can use them as a
> starting point.
>
> rint change is trivial.  for lrint and llrint I'm not sure if we should
> add USE_LRINTL_BUILTIN and USE_LRINTF128_BUILTIN (with zero value) as
> well.  Likewise for logb.
>
> scalbn is a little complicated: I'd prefer to expand M_SCALBN to
> __builtin_scalbn directly instead of calling __scalbn (to avoid the
> overhead calling a function with only two instructions) but it seems not
> easy: some files calling M_SCALBN are compiled with -fmath-errno, with
> which the compiler will refuse to expand __builtin_scalbn.
>
>> 在 2022/11/12 下午3:08, Xi Ruoyao 写道:
>>> On Wed, 2022-11-09 at 21:53 +0800, Xi Ruoyao wrote:
>>>> These patches allow to expand the following builtins to floating
>>>> point
>>>> instructions for LoongArch:
>>>>
>>>> - __builtin_rint{,f}
>>>> - __builtin_{l,ll}rint{,f}
>>>> - __builtin_{l,ll}floor{,f}
>>>> - __builtin_{l,ll}ceil{,f}
>>>> - __builtin_scalb{n,ln}{,f}
>>>> - __builtin_logb{,f}
>>>>
>>>> Bootstrapped and regtested on loongarch64-linux-gnu.  And a
>>>> modified
>>>> Glibc using the builtins for rint{,f}, {l,ll}rint{,f}, and
>>>> logb{,f}
>>>> also survived Glibc test suite.
>>>>
>>>> Please review ASAP because GCC 13 stage 1 will end on Nov. 13th.
>>>>
>>>> v1 -> v2: Only use ftint{rm,rp} instructions if floor and ceil are
>>>> allowed to raise inexact exception.
>>>>
>>>> Xi Ruoyao (4):
>>>>     LoongArch: Rename frint_<fmt> to rint<mode>2
>>>>     LoongArch: Add ftint{,rm,rp}.{w,l}.{s,d} instructions
>>>>     LoongArch: Add fscaleb.{s,d} instructions as ldexp{sf,df}3
>>>>     LoongArch: Add flogb.{s,d} instructions and expand logb{sf,df}2
>>>>
>>>>    gcc/config/loongarch/loongarch.md             | 95
>>>> ++++++++++++++++++-
>>>>    gcc/testsuite/gcc.target/loongarch/flogb.c    | 18 ++++
>>>>    gcc/testsuite/gcc.target/loongarch/frint.c    | 16 ++++
>>>>    gcc/testsuite/gcc.target/loongarch/fscaleb.c  | 48 ++++++++++
>>>>    .../gcc.target/loongarch/ftint-no-inexact.c   | 44 +++++++++
>>>>    gcc/testsuite/gcc.target/loongarch/ftint.c    | 44 +++++++++
>>>>    6 files changed, 261 insertions(+), 4 deletions(-)
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/flogb.c
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/frint.c
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/fscaleb.c
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/ftint-no-
>>>> inexact.c
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/ftint.c
>>>>
>>> Pushed r13-3922.
>>>
>>> I'll be busy in the following week.  Will do the work on Glibc side
>>> after Nov. 20.
>>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/4] LoongArch: Add some floating-point operations
  2022-11-14  8:05     ` [PATCH v2 0/4] LoongArch: Add some floating-point operations Xi Ruoyao via Libc-alpha
  2022-11-16  9:17       ` tangxiaolin
@ 2022-11-16 13:00       ` tangxiaolin
  2022-11-16 14:39         ` Xi Ruoyao via Libc-alpha
  1 sibling, 1 reply; 4+ messages in thread
From: tangxiaolin @ 2022-11-16 13:00 UTC (permalink / raw)
  To: Xi Ruoyao, libc-alpha; +Cc: Lulu Cheng, Wang Xuerui, Chenghua Xu, caiyinyu

I notice that use __builtin_lrint to expand __lrint to:
          ftint.l.d       $fa0, $fa0
          movfr2gr.d      $a0, $fa0
          jirl            $zero, $ra, 0

Operations of 'ftint.l.d'  is convertToIntegerExactTiesToEven(x)/ 
convertToIntegerExactTowardZero(x)/

convertToIntegerExactTowardPositive(x)/convertToIntegerExactTowardNegative(x) 
according to

FCSR RM(LoongArch Manual).

However, the operation of function rint, lrint, llrint is 
roundToIntegralExact according to  ISO/IEC TS

18661-1: 2014 and The GNU C Library Reference Manual. It's a little bit 
difference between those two

operations, but we still can pass all testcases so far. I'm a little 
worried about it.(As we know that

operations of  'frint.{d,s}' is exactly roundToIntegralExact, however we 
discard it.)



在 2022/11/14 下午4:05, Xi Ruoyao 写道:
> On Mon, 2022-11-14 at 10:41 +0800, tangxiaolin wrote:
>> How about I do this work on Glibc?
> [Moving the discussion to libc-alpha.]
>
> Go for it.  I'm attaching my draft patches and you can use them as a
> starting point.
>
> rint change is trivial.  for lrint and llrint I'm not sure if we should
> add USE_LRINTL_BUILTIN and USE_LRINTF128_BUILTIN (with zero value) as
> well.  Likewise for logb.
>
> scalbn is a little complicated: I'd prefer to expand M_SCALBN to
> __builtin_scalbn directly instead of calling __scalbn (to avoid the
> overhead calling a function with only two instructions) but it seems not
> easy: some files calling M_SCALBN are compiled with -fmath-errno, with
> which the compiler will refuse to expand __builtin_scalbn.
>
>> 在 2022/11/12 下午3:08, Xi Ruoyao 写道:
>>> On Wed, 2022-11-09 at 21:53 +0800, Xi Ruoyao wrote:
>>>> These patches allow to expand the following builtins to floating
>>>> point
>>>> instructions for LoongArch:
>>>>
>>>> - __builtin_rint{,f}
>>>> - __builtin_{l,ll}rint{,f}
>>>> - __builtin_{l,ll}floor{,f}
>>>> - __builtin_{l,ll}ceil{,f}
>>>> - __builtin_scalb{n,ln}{,f}
>>>> - __builtin_logb{,f}
>>>>
>>>> Bootstrapped and regtested on loongarch64-linux-gnu.  And a
>>>> modified
>>>> Glibc using the builtins for rint{,f}, {l,ll}rint{,f}, and
>>>> logb{,f}
>>>> also survived Glibc test suite.
>>>>
>>>> Please review ASAP because GCC 13 stage 1 will end on Nov. 13th.
>>>>
>>>> v1 -> v2: Only use ftint{rm,rp} instructions if floor and ceil are
>>>> allowed to raise inexact exception.
>>>>
>>>> Xi Ruoyao (4):
>>>>     LoongArch: Rename frint_<fmt> to rint<mode>2
>>>>     LoongArch: Add ftint{,rm,rp}.{w,l}.{s,d} instructions
>>>>     LoongArch: Add fscaleb.{s,d} instructions as ldexp{sf,df}3
>>>>     LoongArch: Add flogb.{s,d} instructions and expand logb{sf,df}2
>>>>
>>>>    gcc/config/loongarch/loongarch.md             | 95
>>>> ++++++++++++++++++-
>>>>    gcc/testsuite/gcc.target/loongarch/flogb.c    | 18 ++++
>>>>    gcc/testsuite/gcc.target/loongarch/frint.c    | 16 ++++
>>>>    gcc/testsuite/gcc.target/loongarch/fscaleb.c  | 48 ++++++++++
>>>>    .../gcc.target/loongarch/ftint-no-inexact.c   | 44 +++++++++
>>>>    gcc/testsuite/gcc.target/loongarch/ftint.c    | 44 +++++++++
>>>>    6 files changed, 261 insertions(+), 4 deletions(-)
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/flogb.c
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/frint.c
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/fscaleb.c
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/ftint-no-
>>>> inexact.c
>>>>    create mode 100644 gcc/testsuite/gcc.target/loongarch/ftint.c
>>>>
>>> Pushed r13-3922.
>>>
>>> I'll be busy in the following week.  Will do the work on Glibc side
>>> after Nov. 20.
>>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/4] LoongArch: Add some floating-point operations
  2022-11-16 13:00       ` tangxiaolin
@ 2022-11-16 14:39         ` Xi Ruoyao via Libc-alpha
  0 siblings, 0 replies; 4+ messages in thread
From: Xi Ruoyao via Libc-alpha @ 2022-11-16 14:39 UTC (permalink / raw)
  To: tangxiaolin, libc-alpha; +Cc: Lulu Cheng, Wang Xuerui, Chenghua Xu, caiyinyu

On Wed, 2022-11-16 at 21:00 +0800, tangxiaolin wrote:
> I notice that use __builtin_lrint to expand __lrint to:
>           ftint.l.d       $fa0, $fa0
>           movfr2gr.d      $a0, $fa0
>           jirl            $zero, $ra, 0
> 
> Operations of 'ftint.l.d'  is convertToIntegerExactTiesToEven(x)/ 
> convertToIntegerExactTowardZero(x)/convertToIntegerExactTowardPositive
> (x)/convertToIntegerExactTowardNegative(x) according to FCSR
> RM(LoongArch Manual).
> 
> However, the operation of function rint, lrint, llrint is
> roundToIntegralExact according to  ISO/IEC TS 18661-1: 2014 and The
> GNU C Library Reference Manual. It's a little bit difference between
> those two operations, but we still can pass all testcases so far. I'm
> a little worried about it. (As we know that operations of 
> 'frint.{d,s}' is exactly roundToIntegralExact, however we 
> discard it.)

TS 18661 says:

   — The lrint and llrint functions in <math.h> provide the IEC 60559 conversions, which
   honor the directed rounding mode, from floating point to the long int and long long int
   integer formats. The lrint and llrint functions can be used to implement IEC 60559
   conversions from floating to other integer formats.

Note that it mentions "conversions" explicitly.  In IEC 60559
convertToInteger* are called "conversions", but roundToIntegral* are
just called "rounding operations".  And the plural form of "conversions"
also suggests that we need to pick a proper conversion operation
according to the rounding mode.

So I think the semantics of lrint aligns with ftint.{s/d}.


> 
> 
> 
> 在 2022/11/14 下午4:05, Xi Ruoyao 写道:
> > On Mon, 2022-11-14 at 10:41 +0800, tangxiaolin wrote:
> > > How about I do this work on Glibc?
> > [Moving the discussion to libc-alpha.]
> > 
> > Go for it.  I'm attaching my draft patches and you can use them as a
> > starting point.
> > 
> > rint change is trivial.  for lrint and llrint I'm not sure if we
> > should
> > add USE_LRINTL_BUILTIN and USE_LRINTF128_BUILTIN (with zero value)
> > as
> > well.  Likewise for logb.
> > 
> > scalbn is a little complicated: I'd prefer to expand M_SCALBN to
> > __builtin_scalbn directly instead of calling __scalbn (to avoid the
> > overhead calling a function with only two instructions) but it seems
> > not
> > easy: some files calling M_SCALBN are compiled with -fmath-errno,
> > with
> > which the compiler will refuse to expand __builtin_scalbn.
> > 
> > > 在 2022/11/12 下午3:08, Xi Ruoyao 写道:
> > > > On Wed, 2022-11-09 at 21:53 +0800, Xi Ruoyao wrote:
> > > > > These patches allow to expand the following builtins to
> > > > > floating
> > > > > point
> > > > > instructions for LoongArch:
> > > > > 
> > > > > - __builtin_rint{,f}
> > > > > - __builtin_{l,ll}rint{,f}
> > > > > - __builtin_{l,ll}floor{,f}
> > > > > - __builtin_{l,ll}ceil{,f}
> > > > > - __builtin_scalb{n,ln}{,f}
> > > > > - __builtin_logb{,f}
> > > > > 
> > > > > Bootstrapped and regtested on loongarch64-linux-gnu.  And a
> > > > > modified
> > > > > Glibc using the builtins for rint{,f}, {l,ll}rint{,f}, and
> > > > > logb{,f}
> > > > > also survived Glibc test suite.
> > > > > 
> > > > > Please review ASAP because GCC 13 stage 1 will end on Nov.
> > > > > 13th.
> > > > > 
> > > > > v1 -> v2: Only use ftint{rm,rp} instructions if floor and ceil
> > > > > are
> > > > > allowed to raise inexact exception.
> > > > > 
> > > > > Xi Ruoyao (4):
> > > > >     LoongArch: Rename frint_<fmt> to rint<mode>2
> > > > >     LoongArch: Add ftint{,rm,rp}.{w,l}.{s,d} instructions
> > > > >     LoongArch: Add fscaleb.{s,d} instructions as ldexp{sf,df}3
> > > > >     LoongArch: Add flogb.{s,d} instructions and expand
> > > > > logb{sf,df}2
> > > > > 
> > > > >    gcc/config/loongarch/loongarch.md             | 95
> > > > > ++++++++++++++++++-
> > > > >    gcc/testsuite/gcc.target/loongarch/flogb.c    | 18 ++++
> > > > >    gcc/testsuite/gcc.target/loongarch/frint.c    | 16 ++++
> > > > >    gcc/testsuite/gcc.target/loongarch/fscaleb.c  | 48
> > > > > ++++++++++
> > > > >    .../gcc.target/loongarch/ftint-no-inexact.c   | 44
> > > > > +++++++++
> > > > >    gcc/testsuite/gcc.target/loongarch/ftint.c    | 44
> > > > > +++++++++
> > > > >    6 files changed, 261 insertions(+), 4 deletions(-)
> > > > >    create mode 100644
> > > > > gcc/testsuite/gcc.target/loongarch/flogb.c
> > > > >    create mode 100644
> > > > > gcc/testsuite/gcc.target/loongarch/frint.c
> > > > >    create mode 100644
> > > > > gcc/testsuite/gcc.target/loongarch/fscaleb.c
> > > > >    create mode 100644
> > > > > gcc/testsuite/gcc.target/loongarch/ftint-no-
> > > > > inexact.c
> > > > >    create mode 100644
> > > > > gcc/testsuite/gcc.target/loongarch/ftint.c
> > > > > 
> > > > Pushed r13-3922.
> > > > 
> > > > I'll be busy in the following week.  Will do the work on Glibc
> > > > side
> > > > after Nov. 20.
> > > > 
> 

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-16 14:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20221109135329.952128-1-xry111@xry111.site>
     [not found] ` <1a465d2a0bea2a47aadaa727c0689ac48d5982c5.camel@xry111.site>
     [not found]   ` <235d9f8e-040c-2917-8444-654b33aa124e@loongson.cn>
2022-11-14  8:05     ` [PATCH v2 0/4] LoongArch: Add some floating-point operations Xi Ruoyao via Libc-alpha
2022-11-16  9:17       ` tangxiaolin
2022-11-16 13:00       ` tangxiaolin
2022-11-16 14:39         ` Xi Ruoyao via Libc-alpha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).