public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2] RISC-V missing __builtin_lceil and __builtin_lfloor
@ 2022-11-08  4:36 Kevin Lee
  2022-11-09  9:48 ` Xi Ruoyao
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Lee @ 2022-11-08  4:36 UTC (permalink / raw)
  To: gcc-patches; +Cc: palmer, kito.cheng, gnu-toolchain, Kevin Lee

The patch in 
https://gcc.gnu.org/pipermail/gcc-patches/2022-August/599755.html was
corrupted. I am resending the cleaner version as patch v2. Thank you! 

gcc/ChangeLog:

	Michael Collison <collison@rivosinc.com>
	* config/riscv/iterators.md (RINT): Additional iterators.
	(rint_pattern): Additional attributes.
	(rint_rm): Ditto.
	* config/riscv/riscv.md: New attributes.

gcc/testsuite/ChangeLog:

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

diff --git a/gcc/config/riscv/iterators.md b/gcc/config/riscv/iterators.md
index 50380ecfac9..3dd705eaf81 100644
--- a/gcc/config/riscv/iterators.md
+++ b/gcc/config/riscv/iterators.md
@@ -233,9 +233,11 @@ (define_code_attr bitmanip_insn [(smin "min")
 ;; -------------------------------------------------------------------
 
 ;; 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")])
+(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/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 798f7370a08..07e72af8950 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -60,6 +60,9 @@ (define_c_enum "unspec" [
   UNSPEC_FMIN
   UNSPEC_FMAX
 
+  UNSPEC_LCEIL
+  UNSPEC_LFLOOR
+
   ;; Stack tie
   UNSPEC_TIE
 ])
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..4715de746fb
--- /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] 3+ messages in thread

* Re: [PATCH v2] RISC-V missing __builtin_lceil and __builtin_lfloor
  2022-11-08  4:36 [PATCH v2] RISC-V missing __builtin_lceil and __builtin_lfloor Kevin Lee
@ 2022-11-09  9:48 ` Xi Ruoyao
  2022-11-11 18:55   ` Kevin Lee
  0 siblings, 1 reply; 3+ messages in thread
From: Xi Ruoyao @ 2022-11-09  9:48 UTC (permalink / raw)
  To: Kevin Lee, gcc-patches; +Cc: palmer, kito.cheng, gnu-toolchain

On Mon, 2022-11-07 at 20:36 -0800, Kevin Lee wrote:
> The patch in 
> https://gcc.gnu.org/pipermail/gcc-patches/2022-August/599755.html was
> corrupted. I am resending the cleaner version as patch v2. Thank you! 

Hi Kevin,

I "shamelessly copied" your idea in
https://gcc.gnu.org/pipermail/gcc-patches/2022-November/605456.html. 
During the review we found an issue.

Consider

$ cat x.c
long x(double d)
{
	return __builtin_ceil(d);
}

With the patch:

$ ./gcc/cc1 x.c -nostdinc -mabi=lp64d -march=rv64g -O -fno-fp-int-builtin-inexact
$ cat x.s
	.file	"x.c"
	.option nopic
	.text
	.align	2
	.globl	x
	.type	x, @function
x:
	fcvt.l.d a0,fa0,rup
	ret
	.size	x, .-x
	.ident	"GCC: (GNU) 13.0.0 20221109 (experimental)"
	.section	.note.GNU-stack,"",@progbits

-fno-fp-int-builtin-inexact does not allow __builtin_ceil to raise
inexact exception.  But fcvt.l.d may raise one.

> gcc/ChangeLog:
> 
>         Michael Collison <collison@rivosinc.com>
>         * config/riscv/iterators.md (RINT): Additional iterators.
>         (rint_pattern): Additional attributes.
>         (rint_rm): Ditto.
>         * config/riscv/riscv.md: New attributes.
> 
> gcc/testsuite/ChangeLog:
> 
>         Kevin Lee <kevinl@rivosinc.com>
>         * gcc.target/riscv/lfloor-lceil.c: New test.
> ---
>  gcc/config/riscv/iterators.md                 |  8 +-
>  gcc/config/riscv/riscv.md                     |  3 +
>  gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79
> +++++++++++++++++++
>  3 files changed, 87 insertions(+), 3 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c
> 
> diff --git a/gcc/config/riscv/iterators.md
> b/gcc/config/riscv/iterators.md
> index 50380ecfac9..3dd705eaf81 100644
> --- a/gcc/config/riscv/iterators.md
> +++ b/gcc/config/riscv/iterators.md
> @@ -233,9 +233,11 @@ (define_code_attr bitmanip_insn [(smin "min")
>  ;; ------------------------------------------------------------------
> -
>  
>  ;; 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")])
> +(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/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
> index 798f7370a08..07e72af8950 100644
> --- a/gcc/config/riscv/riscv.md
> +++ b/gcc/config/riscv/riscv.md
> @@ -60,6 +60,9 @@ (define_c_enum "unspec" [
>    UNSPEC_FMIN
>    UNSPEC_FMAX
>  
> +  UNSPEC_LCEIL
> +  UNSPEC_LFLOOR
> +
>    ;; Stack tie
>    UNSPEC_TIE
>  ])
> 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..4715de746fb
> --- /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" } } */

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

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

* Re: [PATCH v2] RISC-V missing __builtin_lceil and __builtin_lfloor
  2022-11-09  9:48 ` Xi Ruoyao
@ 2022-11-11 18:55   ` Kevin Lee
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Lee @ 2022-11-11 18:55 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: gcc-patches, palmer, kito.cheng, gnu-toolchain

On Wed, Nov 9, 2022 at 1:49 AM Xi Ruoyao <xry111@xry111.site> wrote:
>
> On Mon, 2022-11-07 at 20:36 -0800, Kevin Lee wrote:
> I "shamelessly copied" your idea in
> https://gcc.gnu.org/pipermail/gcc-patches/2022-November/605456.html.
> During the review we found an issue.
>

> -fno-fp-int-builtin-inexact does not allow __builtin_ceil to raise
> inexact exception.  But fcvt.l.d may raise one.

Your solution of activating only for the fp-int-builtin-inexact seems
to be a good way to handle the issue. Thank you for the example. I'll
create a new patch based on the fix.

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

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

end of thread, other threads:[~2022-11-11 18:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08  4:36 [PATCH v2] RISC-V missing __builtin_lceil and __builtin_lfloor Kevin Lee
2022-11-09  9:48 ` Xi Ruoyao
2022-11-11 18:55   ` 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).