public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Lulu Cheng <chenglulu@loongson.cn>
To: Xi Ruoyao <xry111@xry111.site>, gcc-patches@gcc.gnu.org
Cc: Wang Xuerui <i@xen0n.name>, Chenghua Xu <xuchenghua@loongson.cn>,
	Xiaolin Tang <tangxiaolin@loongson.cn>
Subject: Re: [PATCH v2 4/4] LoongArch: Add flogb.{s,d} instructions and expand logb{sf,df}2
Date: Sat, 12 Nov 2022 14:51:35 +0800	[thread overview]
Message-ID: <41dd4f29-2b9c-9217-77d6-22777a8fbd53@loongson.cn> (raw)
In-Reply-To: <20221109135329.952128-5-xry111@xry111.site>

LGTM!

Thanks.

在 2022/11/9 下午9:53, Xi Ruoyao 写道:
> On LoongArch, flogb instructions extract the exponent of a non-negative
> floating point value, but produces NaN for negative values.  So we need
> to add a fabs instruction when we expand logb.
>
> gcc/ChangeLog:
>
> 	* config/loongarch/loongarch.md (UNSPEC_FLOGB): New unspec.
> 	(type): Add flogb.
> 	(logb_non_negative<mode>2): New instruction template.
> 	(logb<mode>2): New define_expand.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/loongarch/flogb.c: New test.
> ---
>   gcc/config/loongarch/loongarch.md          | 35 ++++++++++++++++++++--
>   gcc/testsuite/gcc.target/loongarch/flogb.c | 18 +++++++++++
>   2 files changed, 51 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.target/loongarch/flogb.c
>
> diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
> index c141c9adde2..682ab961741 100644
> --- a/gcc/config/loongarch/loongarch.md
> +++ b/gcc/config/loongarch/loongarch.md
> @@ -42,6 +42,7 @@ (define_c_enum "unspec" [
>     UNSPEC_FTINTRM
>     UNSPEC_FTINTRP
>     UNSPEC_FSCALEB
> +  UNSPEC_FLOGB
>   
>     ;; Override return address for exception handling.
>     UNSPEC_EH_RETURN
> @@ -217,6 +218,7 @@ (define_attr "qword_mode" "no,yes"
>   ;; fdiv		floating point divide
>   ;; frdiv	floating point reciprocal divide
>   ;; fabs		floating point absolute value
> +;; flogb	floating point exponent extract
>   ;; fneg		floating point negation
>   ;; fcmp		floating point compare
>   ;; fcopysign	floating point copysign
> @@ -233,8 +235,8 @@ (define_attr "type"
>     "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
>      prefetch,prefetchx,condmove,mgtf,mftg,const,arith,logical,
>      shift,slt,signext,clz,trap,imul,idiv,move,
> -   fmove,fadd,fmul,fmadd,fdiv,frdiv,fabs,fneg,fcmp,fcopysign,fcvt,fscaleb,
> -   fsqrt,frsqrt,accext,accmod,multi,atomic,syncloop,nop,ghost"
> +   fmove,fadd,fmul,fmadd,fdiv,frdiv,fabs,flogb,fneg,fcmp,fcopysign,fcvt,
> +   fscaleb,fsqrt,frsqrt,accext,accmod,multi,atomic,syncloop,nop,ghost"
>     (cond [(eq_attr "jirl" "!unset") (const_string "call")
>   	 (eq_attr "got" "load") (const_string "load")
>   
> @@ -1039,6 +1041,35 @@ (define_insn "ldexp<mode>3"
>      (set_attr "mode" "<UNITMODE>")])
>   \f
>   ;;
> +;;  ....................
> +;;
> +;;	FLOATING POINT EXPONENT EXTRACT
> +;;
> +;;  ....................
> +
> +(define_insn "logb_non_negative<mode>2"
> +  [(set (match_operand:ANYF 0 "register_operand" "=f")
> +	(unspec:ANYF [(match_operand:ANYF 1 "register_operand" "f")]
> +		     UNSPEC_FLOGB))]
> +  "TARGET_HARD_FLOAT"
> +  "flogb.<fmt>\t%0,%1"
> +  [(set_attr "type" "flogb")
> +   (set_attr "mode" "<UNITMODE>")])
> +
> +(define_expand "logb<mode>2"
> +  [(set (match_operand:ANYF 0 "register_operand")
> +	(unspec:ANYF [(abs:ANYF (match_operand:ANYF 1 "register_operand"))]
> +		     UNSPEC_FLOGB))]
> +  "TARGET_HARD_FLOAT"
> +{
> +  rtx tmp = gen_reg_rtx (<MODE>mode);
> +
> +  emit_insn (gen_abs<mode>2 (tmp, operands[1]));
> +  emit_insn (gen_logb_non_negative<mode>2 (operands[0], tmp));
> +  DONE;
> +})
> +\f
> +;;
>   ;;  ...................
>   ;;
>   ;;  Count leading zeroes.
> diff --git a/gcc/testsuite/gcc.target/loongarch/flogb.c b/gcc/testsuite/gcc.target/loongarch/flogb.c
> new file mode 100644
> index 00000000000..1daefe54e13
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/flogb.c
> @@ -0,0 +1,18 @@
> +/* { dg-do compile } */
> +/* { dg-options "-mdouble-float -fno-math-errno" } */
> +/* { dg-final { scan-assembler "fabs\\.s" } } */
> +/* { dg-final { scan-assembler "fabs\\.d" } } */
> +/* { dg-final { scan-assembler "flogb\\.s" } } */
> +/* { dg-final { scan-assembler "flogb\\.d" } } */
> +
> +double
> +my_logb (double a)
> +{
> +  return __builtin_logb (a);
> +}
> +
> +float
> +my_logbf (float a)
> +{
> +  return __builtin_logbf (a);
> +}


  reply	other threads:[~2022-11-12  6:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 13:53 [PATCH v2 0/4] LoongArch: Add some floating-point operations Xi Ruoyao
2022-11-09 13:53 ` [PATCH v2 1/4] LoongArch: Rename frint_<fmt> to rint<mode>2 Xi Ruoyao
2022-11-10  8:15   ` Lulu Cheng
2022-11-09 13:53 ` [PATCH v2 2/4] LoongArch: Add ftint{,rm,rp}.{w,l}.{s,d} instructions Xi Ruoyao
2022-11-10  6:41   ` Lulu Cheng
2022-11-10  8:49     ` Xi Ruoyao
2022-11-11  0:07       ` Joseph Myers
2022-11-11  5:29         ` Xi Ruoyao
2022-11-12  1:58           ` Lulu Cheng
2022-11-09 13:53 ` [PATCH v2 3/4] LoongArch: Add fscaleb.{s,d} instructions as ldexp{sf,df}3 Xi Ruoyao
2022-11-12  3:54   ` Lulu Cheng
2022-11-12  4:40     ` Xi Ruoyao
2022-11-12  6:52       ` Lulu Cheng
2022-11-09 13:53 ` [PATCH v2 4/4] LoongArch: Add flogb.{s,d} instructions and expand logb{sf,df}2 Xi Ruoyao
2022-11-12  6:51   ` Lulu Cheng [this message]
2022-11-12  7:08 ` [PATCH v2 0/4] LoongArch: Add some floating-point operations Xi Ruoyao
2022-11-12  7:14   ` Lulu Cheng
2022-11-14  2:41   ` tangxiaolin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41dd4f29-2b9c-9217-77d6-22777a8fbd53@loongson.cn \
    --to=chenglulu@loongson.cn \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=i@xen0n.name \
    --cc=tangxiaolin@loongson.cn \
    --cc=xry111@xry111.site \
    --cc=xuchenghua@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).