public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor
@ 2022-08-16  0:44 Kevin Lee
  2022-09-17 21:07 ` Palmer Dabbelt
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Lee @ 2022-08-16  0:44 UTC (permalink / raw)
  To: gcc-patches

Hello,
Currently, __builtin_lceil and __builtin_lfloor doesn't generate an
existing instruction fcvt, but rather calls ceil and floor from the
library. This patch adds the missing iterator and attributes for lceil and
lfloor to produce the optimized code.
 The test cases check the correct generation of the fcvt instruction for
float/double to int/long/long long. Passed the test in riscv-linux.
Could this patch be committed?

gcc/ChangeLog:
       Michael Collison  <collison@rivosinc.com>
        * config/riscv/riscv.md (RINT): Add iterator for lceil and lround.
        (rint_pattern): Add ceil and floor.
        (rint_rm): Add rup and rdn.

gcc/testsuite/ChangeLog:
        Kevin Lee  <kevinl@rivosinc.com>
        * gcc.target/riscv/lfloor-lceil.c: New test.
---
 gcc/config/riscv/riscv.md                     | 13 ++-
 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++
 2 files changed, 88 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c

diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index c6399b1389e..070004fa7fe 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -43,6 +43,9 @@ (define_c_enum "unspec" [
   UNSPEC_LRINT
   UNSPEC_LROUND

+  UNSPEC_LCEIL
+  UNSPEC_LFLOOR
+
   ;; Stack tie
   UNSPEC_TIE
 ])
@@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")])
 ;; the controlling mode.
 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")])

-;; Iterator and attributes for floating-point rounding instructions.
-(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND])
-(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
"round")])
-(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")])
+;; Iterator and attributes for floating-point rounding instructions.f
+(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL
UNSPEC_LFLOOR])
+(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
"round")
+                             (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR
"floor")])
+(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")
+                        (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")])

 ;; Iterator and attributes for quiet comparisons.
 (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET UNSPEC_FLE_QUIET])
diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
new file mode 100644
index 00000000000..4d81c12cefa
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
@@ -0,0 +1,79 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc -mabi=lp64d" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+int
+ceil1(float i)
+{
+  return __builtin_lceil(i);
+}
+
+long
+ceil2(float i)
+{
+  return __builtin_lceil(i);
+}
+
+long long
+ceil3(float i)
+{
+  return __builtin_lceil(i);
+}
+
+int
+ceil4(double i)
+{
+  return __builtin_lceil(i);
+}
+
+long
+ceil5(double i)
+{
+  return __builtin_lceil(i);
+}
+
+long long
+ceil6(double i)
+{
+  return __builtin_lceil(i);
+}
+
+int
+floor1(float i)
+{
+  return __builtin_lfloor(i);
+}
+
+long
+floor2(float i)
+{
+  return __builtin_lfloor(i);
+}
+
+long long
+floor3(float i)
+{
+  return __builtin_lfloor(i);
+}
+
+int
+floor4(double i)
+{
+  return __builtin_lfloor(i);
+}
+
+long
+floor5(double i)
+{
+  return __builtin_lfloor(i);
+}
+
+long long
+floor6(double i)
+{
+  return __builtin_lfloor(i);
+}
+
+/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */
+/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */
+/* { dg-final { scan-assembler-not "call" } } */
-- 
2.25.1

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

* Re: [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor
  2022-08-16  0:44 [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor Kevin Lee
@ 2022-09-17 21:07 ` Palmer Dabbelt
  2022-09-17 21:16   ` Kito Cheng
  0 siblings, 1 reply; 6+ messages in thread
From: Palmer Dabbelt @ 2022-09-17 21:07 UTC (permalink / raw)
  To: kevinl; +Cc: gcc-patches

On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote:
> Hello,
> Currently, __builtin_lceil and __builtin_lfloor doesn't generate an
> existing instruction fcvt, but rather calls ceil and floor from the
> library. This patch adds the missing iterator and attributes for lceil and
> lfloor to produce the optimized code.
>  The test cases check the correct generation of the fcvt instruction for
> float/double to int/long/long long. Passed the test in riscv-linux.
> Could this patch be committed?

Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>

Not sure if Kito had any comments for this one, but it looks good to me.

> gcc/ChangeLog:
>        Michael Collison  <collison@rivosinc.com>
>         * config/riscv/riscv.md (RINT): Add iterator for lceil and lround.
>         (rint_pattern): Add ceil and floor.
>         (rint_rm): Add rup and rdn.
>
> gcc/testsuite/ChangeLog:
>         Kevin Lee  <kevinl@rivosinc.com>
>         * gcc.target/riscv/lfloor-lceil.c: New test.
> ---
>  gcc/config/riscv/riscv.md                     | 13 ++-
>  gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++
>  2 files changed, 88 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
>
> diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
> index c6399b1389e..070004fa7fe 100644
> --- a/gcc/config/riscv/riscv.md
> +++ b/gcc/config/riscv/riscv.md
> @@ -43,6 +43,9 @@ (define_c_enum "unspec" [
>    UNSPEC_LRINT
>    UNSPEC_LROUND
>
> +  UNSPEC_LCEIL
> +  UNSPEC_LFLOOR
> +
>    ;; Stack tie
>    UNSPEC_TIE
>  ])
> @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")])
>  ;; the controlling mode.
>  (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")])
>
> -;; Iterator and attributes for floating-point rounding instructions.
> -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND])
> -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
> "round")])
> -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")])
> +;; Iterator and attributes for floating-point rounding instructions.f
> +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL
> UNSPEC_LFLOOR])
> +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
> "round")
> +                             (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR
> "floor")])
> +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")
> +                        (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")])
>
>  ;; Iterator and attributes for quiet comparisons.
>  (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET UNSPEC_FLE_QUIET])
> diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> new file mode 100644
> index 00000000000..4d81c12cefa
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> @@ -0,0 +1,79 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv64gc -mabi=lp64d" } */
> +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
> +
> +int
> +ceil1(float i)
> +{
> +  return __builtin_lceil(i);
> +}
> +
> +long
> +ceil2(float i)
> +{
> +  return __builtin_lceil(i);
> +}
> +
> +long long
> +ceil3(float i)
> +{
> +  return __builtin_lceil(i);
> +}
> +
> +int
> +ceil4(double i)
> +{
> +  return __builtin_lceil(i);
> +}
> +
> +long
> +ceil5(double i)
> +{
> +  return __builtin_lceil(i);
> +}
> +
> +long long
> +ceil6(double i)
> +{
> +  return __builtin_lceil(i);
> +}
> +
> +int
> +floor1(float i)
> +{
> +  return __builtin_lfloor(i);
> +}
> +
> +long
> +floor2(float i)
> +{
> +  return __builtin_lfloor(i);
> +}
> +
> +long long
> +floor3(float i)
> +{
> +  return __builtin_lfloor(i);
> +}
> +
> +int
> +floor4(double i)
> +{
> +  return __builtin_lfloor(i);
> +}
> +
> +long
> +floor5(double i)
> +{
> +  return __builtin_lfloor(i);
> +}
> +
> +long long
> +floor6(double i)
> +{
> +  return __builtin_lfloor(i);
> +}
> +
> +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */
> +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */
> +/* { dg-final { scan-assembler-not "call" } } */

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

* Re: [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor
  2022-09-17 21:07 ` Palmer Dabbelt
@ 2022-09-17 21:16   ` Kito Cheng
  2022-10-02 20:42     ` Palmer Dabbelt
  0 siblings, 1 reply; 6+ messages in thread
From: Kito Cheng @ 2022-09-17 21:16 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: kevinl, GCC Patches

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

LGTM, thanks, I guess I just missed this before

Palmer Dabbelt <palmer@dabbelt.com> 於 2022年9月17日 週六 23:07 寫道:

> On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote:
> > Hello,
> > Currently, __builtin_lceil and __builtin_lfloor doesn't generate an
> > existing instruction fcvt, but rather calls ceil and floor from the
> > library. This patch adds the missing iterator and attributes for lceil
> and
> > lfloor to produce the optimized code.
> >  The test cases check the correct generation of the fcvt instruction for
> > float/double to int/long/long long. Passed the test in riscv-linux.
> > Could this patch be committed?
>
> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
> Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
>
> Not sure if Kito had any comments for this one, but it looks good to me.
>
> > gcc/ChangeLog:
> >        Michael Collison  <collison@rivosinc.com>
> >         * config/riscv/riscv.md (RINT): Add iterator for lceil and
> lround.
> >         (rint_pattern): Add ceil and floor.
> >         (rint_rm): Add rup and rdn.
> >
> > gcc/testsuite/ChangeLog:
> >         Kevin Lee  <kevinl@rivosinc.com>
> >         * gcc.target/riscv/lfloor-lceil.c: New test.
> > ---
> >  gcc/config/riscv/riscv.md                     | 13 ++-
> >  gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++
> >  2 files changed, 88 insertions(+), 4 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> >
> > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
> > index c6399b1389e..070004fa7fe 100644
> > --- a/gcc/config/riscv/riscv.md
> > +++ b/gcc/config/riscv/riscv.md
> > @@ -43,6 +43,9 @@ (define_c_enum "unspec" [
> >    UNSPEC_LRINT
> >    UNSPEC_LROUND
> >
> > +  UNSPEC_LCEIL
> > +  UNSPEC_LFLOOR
> > +
> >    ;; Stack tie
> >    UNSPEC_TIE
> >  ])
> > @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")])
> >  ;; the controlling mode.
> >  (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")])
> >
> > -;; Iterator and attributes for floating-point rounding instructions.
> > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND])
> > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
> > "round")])
> > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")])
> > +;; Iterator and attributes for floating-point rounding instructions.f
> > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL
> > UNSPEC_LFLOOR])
> > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
> > "round")
> > +                             (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR
> > "floor")])
> > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")
> > +                        (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")])
> >
> >  ;; Iterator and attributes for quiet comparisons.
> >  (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET
> UNSPEC_FLE_QUIET])
> > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> > new file mode 100644
> > index 00000000000..4d81c12cefa
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> > @@ -0,0 +1,79 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-march=rv64gc -mabi=lp64d" } */
> > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
> > +
> > +int
> > +ceil1(float i)
> > +{
> > +  return __builtin_lceil(i);
> > +}
> > +
> > +long
> > +ceil2(float i)
> > +{
> > +  return __builtin_lceil(i);
> > +}
> > +
> > +long long
> > +ceil3(float i)
> > +{
> > +  return __builtin_lceil(i);
> > +}
> > +
> > +int
> > +ceil4(double i)
> > +{
> > +  return __builtin_lceil(i);
> > +}
> > +
> > +long
> > +ceil5(double i)
> > +{
> > +  return __builtin_lceil(i);
> > +}
> > +
> > +long long
> > +ceil6(double i)
> > +{
> > +  return __builtin_lceil(i);
> > +}
> > +
> > +int
> > +floor1(float i)
> > +{
> > +  return __builtin_lfloor(i);
> > +}
> > +
> > +long
> > +floor2(float i)
> > +{
> > +  return __builtin_lfloor(i);
> > +}
> > +
> > +long long
> > +floor3(float i)
> > +{
> > +  return __builtin_lfloor(i);
> > +}
> > +
> > +int
> > +floor4(double i)
> > +{
> > +  return __builtin_lfloor(i);
> > +}
> > +
> > +long
> > +floor5(double i)
> > +{
> > +  return __builtin_lfloor(i);
> > +}
> > +
> > +long long
> > +floor6(double i)
> > +{
> > +  return __builtin_lfloor(i);
> > +}
> > +
> > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */
> > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */
> > +/* { dg-final { scan-assembler-not "call" } } */
>

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

* Re: [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor
  2022-09-17 21:16   ` Kito Cheng
@ 2022-10-02 20:42     ` Palmer Dabbelt
  2022-10-02 20:47       ` Kevin Lee
  0 siblings, 1 reply; 6+ messages in thread
From: Palmer Dabbelt @ 2022-10-02 20:42 UTC (permalink / raw)
  To: Kito Cheng; +Cc: kevinl, gcc-patches

On Sat, 17 Sep 2022 14:16:13 PDT (-0700), Kito Cheng wrote:
> LGTM, thanks, I guess I just missed this before

No worries, I'd just stubmled on it looking through old stuff.

Kevin: Looks like this got corrupted, possibly from copy/paste into 
gmail.  I resurrect it, but there's a floating-point test failure in 
gfortran.  Looks like it predates this, but I'm trying to bisect it to 
at least have a root cause before just ignoring it.  I've got this 
floating around on a branch and hopefully that'll remind me to commit 
it after I sort that out.

>
> Palmer Dabbelt <palmer@dabbelt.com> 於 2022年9月17日 週六 23:07 寫道:
>
>> On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote:
>> > Hello,
>> > Currently, __builtin_lceil and __builtin_lfloor doesn't generate an
>> > existing instruction fcvt, but rather calls ceil and floor from the
>> > library. This patch adds the missing iterator and attributes for lceil
>> and
>> > lfloor to produce the optimized code.
>> >  The test cases check the correct generation of the fcvt instruction for
>> > float/double to int/long/long long. Passed the test in riscv-linux.
>> > Could this patch be committed?
>>
>> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
>> Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
>>
>> Not sure if Kito had any comments for this one, but it looks good to me.
>>
>> > gcc/ChangeLog:
>> >        Michael Collison  <collison@rivosinc.com>
>> >         * config/riscv/riscv.md (RINT): Add iterator for lceil and
>> lround.
>> >         (rint_pattern): Add ceil and floor.
>> >         (rint_rm): Add rup and rdn.
>> >
>> > gcc/testsuite/ChangeLog:
>> >         Kevin Lee  <kevinl@rivosinc.com>
>> >         * gcc.target/riscv/lfloor-lceil.c: New test.
>> > ---
>> >  gcc/config/riscv/riscv.md                     | 13 ++-
>> >  gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++
>> >  2 files changed, 88 insertions(+), 4 deletions(-)
>> >  create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
>> >
>> > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
>> > index c6399b1389e..070004fa7fe 100644
>> > --- a/gcc/config/riscv/riscv.md
>> > +++ b/gcc/config/riscv/riscv.md
>> > @@ -43,6 +43,9 @@ (define_c_enum "unspec" [
>> >    UNSPEC_LRINT
>> >    UNSPEC_LROUND
>> >
>> > +  UNSPEC_LCEIL
>> > +  UNSPEC_LFLOOR
>> > +
>> >    ;; Stack tie
>> >    UNSPEC_TIE
>> >  ])
>> > @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")])
>> >  ;; the controlling mode.
>> >  (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")])
>> >
>> > -;; Iterator and attributes for floating-point rounding instructions.
>> > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND])
>> > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
>> > "round")])
>> > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")])
>> > +;; Iterator and attributes for floating-point rounding instructions.f
>> > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL
>> > UNSPEC_LFLOOR])
>> > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
>> > "round")
>> > +                             (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR
>> > "floor")])
>> > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")
>> > +                        (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")])
>> >
>> >  ;; Iterator and attributes for quiet comparisons.
>> >  (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET
>> UNSPEC_FLE_QUIET])
>> > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
>> > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
>> > new file mode 100644
>> > index 00000000000..4d81c12cefa
>> > --- /dev/null
>> > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
>> > @@ -0,0 +1,79 @@
>> > +/* { dg-do compile } */
>> > +/* { dg-options "-march=rv64gc -mabi=lp64d" } */
>> > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
>> > +
>> > +int
>> > +ceil1(float i)
>> > +{
>> > +  return __builtin_lceil(i);
>> > +}
>> > +
>> > +long
>> > +ceil2(float i)
>> > +{
>> > +  return __builtin_lceil(i);
>> > +}
>> > +
>> > +long long
>> > +ceil3(float i)
>> > +{
>> > +  return __builtin_lceil(i);
>> > +}
>> > +
>> > +int
>> > +ceil4(double i)
>> > +{
>> > +  return __builtin_lceil(i);
>> > +}
>> > +
>> > +long
>> > +ceil5(double i)
>> > +{
>> > +  return __builtin_lceil(i);
>> > +}
>> > +
>> > +long long
>> > +ceil6(double i)
>> > +{
>> > +  return __builtin_lceil(i);
>> > +}
>> > +
>> > +int
>> > +floor1(float i)
>> > +{
>> > +  return __builtin_lfloor(i);
>> > +}
>> > +
>> > +long
>> > +floor2(float i)
>> > +{
>> > +  return __builtin_lfloor(i);
>> > +}
>> > +
>> > +long long
>> > +floor3(float i)
>> > +{
>> > +  return __builtin_lfloor(i);
>> > +}
>> > +
>> > +int
>> > +floor4(double i)
>> > +{
>> > +  return __builtin_lfloor(i);
>> > +}
>> > +
>> > +long
>> > +floor5(double i)
>> > +{
>> > +  return __builtin_lfloor(i);
>> > +}
>> > +
>> > +long long
>> > +floor6(double i)
>> > +{
>> > +  return __builtin_lfloor(i);
>> > +}
>> > +
>> > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */
>> > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */
>> > +/* { dg-final { scan-assembler-not "call" } } */
>>

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

* Re: [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor
  2022-10-02 20:42     ` Palmer Dabbelt
@ 2022-10-02 20:47       ` Kevin Lee
  2022-11-08  2:06         ` Kevin Lee
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Lee @ 2022-10-02 20:47 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: Kito Cheng, gcc-patches

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

Thank you for the update Palmer. I'll certainly look into the corrupted
patch issue and the floating-point test failure in gfortran.

On Sun, Oct 2, 2022 at 1:42 PM Palmer Dabbelt <palmer@dabbelt.com> wrote:

> On Sat, 17 Sep 2022 14:16:13 PDT (-0700), Kito Cheng wrote:
> > LGTM, thanks, I guess I just missed this before
>
> No worries, I'd just stubmled on it looking through old stuff.
>
> Kevin: Looks like this got corrupted, possibly from copy/paste into
> gmail.  I resurrect it, but there's a floating-point test failure in
> gfortran.  Looks like it predates this, but I'm trying to bisect it to
> at least have a root cause before just ignoring it.  I've got this
> floating around on a branch and hopefully that'll remind me to commit
> it after I sort that out.
>
> >
> > Palmer Dabbelt <palmer@dabbelt.com> 於 2022年9月17日 週六 23:07 寫道:
> >
> >> On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote:
> >> > Hello,
> >> > Currently, __builtin_lceil and __builtin_lfloor doesn't generate an
> >> > existing instruction fcvt, but rather calls ceil and floor from the
> >> > library. This patch adds the missing iterator and attributes for lceil
> >> and
> >> > lfloor to produce the optimized code.
> >> >  The test cases check the correct generation of the fcvt instruction
> for
> >> > float/double to int/long/long long. Passed the test in riscv-linux.
> >> > Could this patch be committed?
> >>
> >> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
> >> Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
> >>
> >> Not sure if Kito had any comments for this one, but it looks good to me.
> >>
> >> > gcc/ChangeLog:
> >> >        Michael Collison  <collison@rivosinc.com>
> >> >         * config/riscv/riscv.md (RINT): Add iterator for lceil and
> >> lround.
> >> >         (rint_pattern): Add ceil and floor.
> >> >         (rint_rm): Add rup and rdn.
> >> >
> >> > gcc/testsuite/ChangeLog:
> >> >         Kevin Lee  <kevinl@rivosinc.com>
> >> >         * gcc.target/riscv/lfloor-lceil.c: New test.
> >> > ---
> >> >  gcc/config/riscv/riscv.md                     | 13 ++-
> >> >  gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79
> +++++++++++++++++++
> >> >  2 files changed, 88 insertions(+), 4 deletions(-)
> >> >  create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> >> >
> >> > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
> >> > index c6399b1389e..070004fa7fe 100644
> >> > --- a/gcc/config/riscv/riscv.md
> >> > +++ b/gcc/config/riscv/riscv.md
> >> > @@ -43,6 +43,9 @@ (define_c_enum "unspec" [
> >> >    UNSPEC_LRINT
> >> >    UNSPEC_LROUND
> >> >
> >> > +  UNSPEC_LCEIL
> >> > +  UNSPEC_LFLOOR
> >> > +
> >> >    ;; Stack tie
> >> >    UNSPEC_TIE
> >> >  ])
> >> > @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF
> "DF")])
> >> >  ;; the controlling mode.
> >> >  (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")])
> >> >
> >> > -;; Iterator and attributes for floating-point rounding instructions.
> >> > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND])
> >> > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
> >> > "round")])
> >> > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND
> "rmm")])
> >> > +;; Iterator and attributes for floating-point rounding instructions.f
> >> > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL
> >> > UNSPEC_LFLOOR])
> >> > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
> >> > "round")
> >> > +                             (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR
> >> > "floor")])
> >> > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")
> >> > +                        (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")])
> >> >
> >> >  ;; Iterator and attributes for quiet comparisons.
> >> >  (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET
> >> UNSPEC_FLE_QUIET])
> >> > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> >> > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> >> > new file mode 100644
> >> > index 00000000000..4d81c12cefa
> >> > --- /dev/null
> >> > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> >> > @@ -0,0 +1,79 @@
> >> > +/* { dg-do compile } */
> >> > +/* { dg-options "-march=rv64gc -mabi=lp64d" } */
> >> > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
> >> > +
> >> > +int
> >> > +ceil1(float i)
> >> > +{
> >> > +  return __builtin_lceil(i);
> >> > +}
> >> > +
> >> > +long
> >> > +ceil2(float i)
> >> > +{
> >> > +  return __builtin_lceil(i);
> >> > +}
> >> > +
> >> > +long long
> >> > +ceil3(float i)
> >> > +{
> >> > +  return __builtin_lceil(i);
> >> > +}
> >> > +
> >> > +int
> >> > +ceil4(double i)
> >> > +{
> >> > +  return __builtin_lceil(i);
> >> > +}
> >> > +
> >> > +long
> >> > +ceil5(double i)
> >> > +{
> >> > +  return __builtin_lceil(i);
> >> > +}
> >> > +
> >> > +long long
> >> > +ceil6(double i)
> >> > +{
> >> > +  return __builtin_lceil(i);
> >> > +}
> >> > +
> >> > +int
> >> > +floor1(float i)
> >> > +{
> >> > +  return __builtin_lfloor(i);
> >> > +}
> >> > +
> >> > +long
> >> > +floor2(float i)
> >> > +{
> >> > +  return __builtin_lfloor(i);
> >> > +}
> >> > +
> >> > +long long
> >> > +floor3(float i)
> >> > +{
> >> > +  return __builtin_lfloor(i);
> >> > +}
> >> > +
> >> > +int
> >> > +floor4(double i)
> >> > +{
> >> > +  return __builtin_lfloor(i);
> >> > +}
> >> > +
> >> > +long
> >> > +floor5(double i)
> >> > +{
> >> > +  return __builtin_lfloor(i);
> >> > +}
> >> > +
> >> > +long long
> >> > +floor6(double i)
> >> > +{
> >> > +  return __builtin_lfloor(i);
> >> > +}
> >> > +
> >> > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */
> >> > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */
> >> > +/* { dg-final { scan-assembler-not "call" } } */
> >>
>

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

* Re: [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor
  2022-10-02 20:47       ` Kevin Lee
@ 2022-11-08  2:06         ` Kevin Lee
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Lee @ 2022-11-08  2:06 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: Kito Cheng, gcc-patches

> Kevin: Looks like this got corrupted, possibly from copy/paste into
> gmail.  I resurrect it, but there's a floating-point test failure in
> gfortran.  Looks like it predates this, but I'm trying to bisect it to
> at least have a root cause before just ignoring it.  I've got this
> floating around on a branch and hopefully that'll remind me to commit
> it after I sort that out.

Currently, the testsuite doesn't show additional failures. It seems
like the corrupted patch caused the issue. I will post the clean patch
as v2. Thank you for the review!

On Sun, Oct 2, 2022 at 1:47 PM Kevin Lee <kevinl@rivosinc.com> wrote:
>
> Thank you for the update Palmer. I'll certainly look into the corrupted patch issue and the floating-point test failure in gfortran.
>
> On Sun, Oct 2, 2022 at 1:42 PM Palmer Dabbelt <palmer@dabbelt.com> wrote:
>>
>> On Sat, 17 Sep 2022 14:16:13 PDT (-0700), Kito Cheng wrote:
>> > LGTM, thanks, I guess I just missed this before
>>
>> No worries, I'd just stubmled on it looking through old stuff.
>>
>> Kevin: Looks like this got corrupted, possibly from copy/paste into
>> gmail.  I resurrect it, but there's a floating-point test failure in
>> gfortran.  Looks like it predates this, but I'm trying to bisect it to
>> at least have a root cause before just ignoring it.  I've got this
>> floating around on a branch and hopefully that'll remind me to commit
>> it after I sort that out.
>>
>> >
>> > Palmer Dabbelt <palmer@dabbelt.com> 於 2022年9月17日 週六 23:07 寫道:
>> >
>> >> On Mon, 15 Aug 2022 17:44:35 PDT (-0700), kevinl@rivosinc.com wrote:
>> >> > Hello,
>> >> > Currently, __builtin_lceil and __builtin_lfloor doesn't generate an
>> >> > existing instruction fcvt, but rather calls ceil and floor from the
>> >> > library. This patch adds the missing iterator and attributes for lceil
>> >> and
>> >> > lfloor to produce the optimized code.
>> >> >  The test cases check the correct generation of the fcvt instruction for
>> >> > float/double to int/long/long long. Passed the test in riscv-linux.
>> >> > Could this patch be committed?
>> >>
>> >> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
>> >> Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
>> >>
>> >> Not sure if Kito had any comments for this one, but it looks good to me.
>> >>
>> >> > gcc/ChangeLog:
>> >> >        Michael Collison  <collison@rivosinc.com>
>> >> >         * config/riscv/riscv.md (RINT): Add iterator for lceil and
>> >> lround.
>> >> >         (rint_pattern): Add ceil and floor.
>> >> >         (rint_rm): Add rup and rdn.
>> >> >
>> >> > gcc/testsuite/ChangeLog:
>> >> >         Kevin Lee  <kevinl@rivosinc.com>
>> >> >         * gcc.target/riscv/lfloor-lceil.c: New test.
>> >> > ---
>> >> >  gcc/config/riscv/riscv.md                     | 13 ++-
>> >> >  gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 +++++++++++++++++++
>> >> >  2 files changed, 88 insertions(+), 4 deletions(-)
>> >> >  create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
>> >> >
>> >> > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
>> >> > index c6399b1389e..070004fa7fe 100644
>> >> > --- a/gcc/config/riscv/riscv.md
>> >> > +++ b/gcc/config/riscv/riscv.md
>> >> > @@ -43,6 +43,9 @@ (define_c_enum "unspec" [
>> >> >    UNSPEC_LRINT
>> >> >    UNSPEC_LROUND
>> >> >
>> >> > +  UNSPEC_LCEIL
>> >> > +  UNSPEC_LFLOOR
>> >> > +
>> >> >    ;; Stack tie
>> >> >    UNSPEC_TIE
>> >> >  ])
>> >> > @@ -345,10 +348,12 @@ (define_mode_attr UNITMODE [(SF "SF") (DF "DF")])
>> >> >  ;; the controlling mode.
>> >> >  (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (TF "DI")])
>> >> >
>> >> > -;; Iterator and attributes for floating-point rounding instructions.
>> >> > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND])
>> >> > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
>> >> > "round")])
>> >> > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")])
>> >> > +;; Iterator and attributes for floating-point rounding instructions.f
>> >> > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL
>> >> > UNSPEC_LFLOOR])
>> >> > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND
>> >> > "round")
>> >> > +                             (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR
>> >> > "floor")])
>> >> > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm")
>> >> > +                        (UNSPEC_LCEIL "rup") (UNSPEC_LFLOOR "rdn")])
>> >> >
>> >> >  ;; Iterator and attributes for quiet comparisons.
>> >> >  (define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET
>> >> UNSPEC_FLE_QUIET])
>> >> > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
>> >> > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
>> >> > new file mode 100644
>> >> > index 00000000000..4d81c12cefa
>> >> > --- /dev/null
>> >> > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
>> >> > @@ -0,0 +1,79 @@
>> >> > +/* { dg-do compile } */
>> >> > +/* { dg-options "-march=rv64gc -mabi=lp64d" } */
>> >> > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
>> >> > +
>> >> > +int
>> >> > +ceil1(float i)
>> >> > +{
>> >> > +  return __builtin_lceil(i);
>> >> > +}
>> >> > +
>> >> > +long
>> >> > +ceil2(float i)
>> >> > +{
>> >> > +  return __builtin_lceil(i);
>> >> > +}
>> >> > +
>> >> > +long long
>> >> > +ceil3(float i)
>> >> > +{
>> >> > +  return __builtin_lceil(i);
>> >> > +}
>> >> > +
>> >> > +int
>> >> > +ceil4(double i)
>> >> > +{
>> >> > +  return __builtin_lceil(i);
>> >> > +}
>> >> > +
>> >> > +long
>> >> > +ceil5(double i)
>> >> > +{
>> >> > +  return __builtin_lceil(i);
>> >> > +}
>> >> > +
>> >> > +long long
>> >> > +ceil6(double i)
>> >> > +{
>> >> > +  return __builtin_lceil(i);
>> >> > +}
>> >> > +
>> >> > +int
>> >> > +floor1(float i)
>> >> > +{
>> >> > +  return __builtin_lfloor(i);
>> >> > +}
>> >> > +
>> >> > +long
>> >> > +floor2(float i)
>> >> > +{
>> >> > +  return __builtin_lfloor(i);
>> >> > +}
>> >> > +
>> >> > +long long
>> >> > +floor3(float i)
>> >> > +{
>> >> > +  return __builtin_lfloor(i);
>> >> > +}
>> >> > +
>> >> > +int
>> >> > +floor4(double i)
>> >> > +{
>> >> > +  return __builtin_lfloor(i);
>> >> > +}
>> >> > +
>> >> > +long
>> >> > +floor5(double i)
>> >> > +{
>> >> > +  return __builtin_lfloor(i);
>> >> > +}
>> >> > +
>> >> > +long long
>> >> > +floor6(double i)
>> >> > +{
>> >> > +  return __builtin_lfloor(i);
>> >> > +}
>> >> > +
>> >> > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */
>> >> > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */
>> >> > +/* { dg-final { scan-assembler-not "call" } } */
>> >>

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

end of thread, other threads:[~2022-11-08  2:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16  0:44 [PATCH] RISC-V missing __builtin_lceil and __builtin_lfloor Kevin Lee
2022-09-17 21:07 ` Palmer Dabbelt
2022-09-17 21:16   ` Kito Cheng
2022-10-02 20:42     ` Palmer Dabbelt
2022-10-02 20:47       ` Kevin Lee
2022-11-08  2:06         ` Kevin Lee

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