From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 3BE503858C00 for ; Sun, 6 Nov 2022 02:23:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3BE503858C00 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1667701404; bh=JLgv7PW8rr+3ZoKcAs8+ZrLSGckEr+7CgUmZjiqJvg4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=T98dXxEolF3lYosSPfmJVUBNmnpSeO7snJY78Abxyw/AL0voxgzutk0rGLxqENk2g ecCXwKkzLDA+U0XW361qIVgufmDPaCmG9VOBZmBUVgH2zV4Lh8wHPLQQfzEuu4o81x RbZSeP7SC546LnGLytr4PYp56f6OuF+mGresC+vk= Received: from [IPv6:240e:358:11b5:d900:dc73:854d:832e:3] (unknown [IPv6:240e:358:11b5:d900:dc73:854d:832e:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 8C9BD65931; Sat, 5 Nov 2022 22:23:20 -0400 (EDT) Message-ID: <1933e87a41f76870a848401eb37dead832a389e8.camel@xry111.site> Subject: Re: [PATCH] LoongArch: Add fcopysign instructions From: Xi Ruoyao To: Lulu Cheng , gcc-patches@gcc.gnu.org Cc: Wang Xuerui , Chenghua Xu , Xiaolin Tang Date: Sun, 06 Nov 2022 10:23:11 +0800 In-Reply-To: <490fbb16-36e1-aa12-6a9d-ead6fbd56c6e@loongson.cn> References: <20221104143719.1709284-1-xry111@xry111.site> <490fbb16-36e1-aa12-6a9d-ead6fbd56c6e@loongson.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,GIT_PATCH_0,KAM_SHORT,LIKELY_SPAM_FROM,PDS_OTHER_BAD_TLD,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sun, 2022-11-06 at 09:57 +0800, Lulu Cheng wrote: >=20 > =E5=9C=A8 2022/11/4 =E4=B8=8B=E5=8D=8810:37, Xi Ruoyao =E5=86=99=E9=81=93= : > > Add fcopysign.{s,d} with the names copysign{sf,df}3 so GCC will expand > > __builtin_copysign{f,} to a single instruction. > >=20 > > Link: https://sourceware.org/pipermail/libc-alpha/2022-November/143177.= html > >=20 > > gcc/ChangeLog: > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* config/loongarch/loon= garch.md (UNSPEC_FCOPYSIGN): New unspec. > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(type): Add fcopysign. > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(copysign3): New = instruction template. > >=20 > > gcc/testsuite/ChangeLog: > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* gcc.target/loongarch/= fcopysign.c: New test. > > --- > >=20 > > Bootstrapped and regtested on loongarch64-linux-gnu.=C2=A0 Ok for trunk= ? > >=20 > > =C2=A0=C2=A0 gcc/config/loongarch/loongarch.md=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 22 ++++++++++++++++++- > > =C2=A0=C2=A0 .../gcc.target/loongarch/fcopysign.c=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 16 ++++++++++++++ > > =C2=A0=C2=A0 2 files changed, 37 insertions(+), 1 deletion(-) > > =C2=A0=C2=A0 create mode 100644 gcc/testsuite/gcc.target/loongarch/fcop= ysign.c > >=20 > > diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/l= oongarch.md > > index 214b14bddd3..042e6e74491 100644 > > --- a/gcc/config/loongarch/loongarch.md > > +++ b/gcc/config/loongarch/loongarch.md > > @@ -37,6 +37,7 @@ (define_c_enum "unspec" [ > > =C2=A0=C2=A0=C2=A0=C2=A0 UNSPEC_FCLASS > > =C2=A0=C2=A0=C2=A0=C2=A0 UNSPEC_FMAX > > =C2=A0=C2=A0=C2=A0=C2=A0 UNSPEC_FMIN > > +=C2=A0 UNSPEC_FCOPYSIGN > > =C2=A0=C2=A0=20 > > =C2=A0=C2=A0=C2=A0=C2=A0 ;; Override return address for exception handl= ing. > > =C2=A0=C2=A0=C2=A0=C2=A0 UNSPEC_EH_RETURN > > @@ -214,6 +215,7 @@ (define_attr "qword_mode" "no,yes" > > =C2=A0=C2=A0 ;; fabs=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0floating point absolute value > > =C2=A0=C2=A0 ;; fneg=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0floating point negation > > =C2=A0=C2=A0 ;; fcmp=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0floating point compare > > +;; fcopysign=C2=A0=C2=A0=C2=A0floating point copysign > > =C2=A0=C2=A0 ;; fcvt=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0floating point convert > > =C2=A0=C2=A0 ;; fsqrt=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0floating point squar= e root > > =C2=A0=C2=A0 ;; frsqrt=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 floating poi= nt reciprocal square root > > @@ -226,7 +228,7 @@ (define_attr "type" > > =C2=A0=C2=A0=C2=A0=C2=A0 "unknown,branch,jump,call,load,fpload,fpidxloa= d,store,fpstore,fpidxstore, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 prefetch,prefetchx,condmove,mgtf,mftg,co= nst,arith,logical, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 shift,slt,signext,clz,trap,imul,idiv,mov= e, > > -=C2=A0=C2=A0 fmove,fadd,fmul,fmadd,fdiv,frdiv,fabs,fneg,fcmp,fcvt,fsqr= t, > > +=C2=A0=C2=A0 fmove,fadd,fmul,fmadd,fdiv,frdiv,fabs,fneg,fcmp,fcopysign= ,fcvt,fsqrt, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 frsqrt,accext,accmod,multi,atomic,synclo= op,nop,ghost" > > =C2=A0=C2=A0=C2=A0=C2=A0 (cond [(eq_attr "jirl" "!unset") (const_string= "call") > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (eq_attr "got" "load")= (const_string "load") > > @@ -976,6 +978,24 @@ (define_insn "abs2" > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (set_attr "mode" "")]) > > =C2=A0=C2=A0 =0C > > =C2=A0=C2=A0 ;; > > +;;=C2=A0 .................... > > +;; > > +;;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0FLOATING POINT COPYSIGN > > +;; > > +;;=C2=A0 .................... > > + > > +(define_insn "copysign3" > > +=C2=A0 [(set (match_operand:ANYF 0 "register_operand" "=3Df") > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(unspec:ANYF [(match_operand= :ANYF 1 "register_operand" "f") > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (match_operand:ANYF 2 "= register_operand" "f")] > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 UNSPEC_FCOPYSIGN))] > > +=C2=A0 "" >=20 > We need to add "TARGET_HARD_FLOAT" here. It seems not strictly needed because ANYF expands to nothing if !TARGET_HARD_FLOAT. We also don't have an explicit TARGET_HARD_FLOAT in fadd.{s,d} etc. But I agree that adding it improves the readability. >=20 > Otherwise LGTM. >=20 >=20 > Thanks! --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University