[v2,1/4] LoongArch: Rename frint_<fmt> to rint<mode>2

Message ID 20221109135329.952128-2-xry111@xry111.site
State Accepted
Headers
Series LoongArch: Add some floating-point operations |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Xi Ruoyao Nov. 9, 2022, 1:53 p.m. UTC
  Use standard name so __builtin_rint{,f} can be expanded to one
instruction.

gcc/ChangeLog:

	* config/loongarch/loongarch.md (frint_<fmt>): Rename to ..
	(rint<mode>2): .. this.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/frint.c: New test.
---
 gcc/config/loongarch/loongarch.md          |  4 ++--
 gcc/testsuite/gcc.target/loongarch/frint.c | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/frint.c
  

Comments

chenglulu Nov. 10, 2022, 8:15 a.m. UTC | #1
LGTM!

Thanks.

在 2022/11/9 下午9:53, Xi Ruoyao 写道:
> Use standard name so __builtin_rint{,f} can be expanded to one
> instruction.
>
> gcc/ChangeLog:
>
> 	* config/loongarch/loongarch.md (frint_<fmt>): Rename to ..
> 	(rint<mode>2): .. this.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/loongarch/frint.c: New test.
> ---
>   gcc/config/loongarch/loongarch.md          |  4 ++--
>   gcc/testsuite/gcc.target/loongarch/frint.c | 16 ++++++++++++++++
>   2 files changed, 18 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.target/loongarch/frint.c
>
> diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
> index bda34d0f3db..a14ab14ac24 100644
> --- a/gcc/config/loongarch/loongarch.md
> +++ b/gcc/config/loongarch/loongarch.md
> @@ -2012,8 +2012,8 @@ (define_insn "lui_h_hi12"
>     [(set_attr "type" "move")]
>   )
>   
> -;; Convert floating-point numbers to integers
> -(define_insn "frint_<fmt>"
> +;; Round floating-point numbers to integers
> +(define_insn "rint<mode>2"
>     [(set (match_operand:ANYF 0 "register_operand" "=f")
>   	(unspec:ANYF [(match_operand:ANYF 1 "register_operand" "f")]
>   		      UNSPEC_FRINT))]
> diff --git a/gcc/testsuite/gcc.target/loongarch/frint.c b/gcc/testsuite/gcc.target/loongarch/frint.c
> new file mode 100644
> index 00000000000..3ee6a8f973a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/frint.c
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-mdouble-float" } */
> +/* { dg-final { scan-assembler "frint\\.s" } } */
> +/* { dg-final { scan-assembler "frint\\.d" } } */
> +
> +double
> +my_rint (double a)
> +{
> +  return __builtin_rint (a);
> +}
> +
> +float
> +my_rintf (float a)
> +{
> +  return __builtin_rintf (a);
> +}
  

Patch

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index bda34d0f3db..a14ab14ac24 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -2012,8 +2012,8 @@  (define_insn "lui_h_hi12"
   [(set_attr "type" "move")]
 )
 
-;; Convert floating-point numbers to integers
-(define_insn "frint_<fmt>"
+;; Round floating-point numbers to integers
+(define_insn "rint<mode>2"
   [(set (match_operand:ANYF 0 "register_operand" "=f")
 	(unspec:ANYF [(match_operand:ANYF 1 "register_operand" "f")]
 		      UNSPEC_FRINT))]
diff --git a/gcc/testsuite/gcc.target/loongarch/frint.c b/gcc/testsuite/gcc.target/loongarch/frint.c
new file mode 100644
index 00000000000..3ee6a8f973a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/frint.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+/* { dg-options "-mdouble-float" } */
+/* { dg-final { scan-assembler "frint\\.s" } } */
+/* { dg-final { scan-assembler "frint\\.d" } } */
+
+double
+my_rint (double a)
+{
+  return __builtin_rint (a);
+}
+
+float
+my_rintf (float a)
+{
+  return __builtin_rintf (a);
+}