From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7856) id EF4FA3858D38; Sun, 6 Nov 2022 08:03:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF4FA3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667721838; bh=S3I3YIgU4mVpYctQIQRKKIUu2+KvMnWMjNc7MpDnulY=; h=From:To:Subject:Date:From; b=ULQpkbrvCMY7EaRHOVBqevi/xKLgY1qPXraAWxH4+OTmuoMSLasTs8xBgiog8/hMB 1TDRS5Xt12kOMOLzwWf3+ukdR3zlnw6mxc/JJyebY01T+MMhXuckjDG/J/DIN3azmq 3Ksmsgbxnt2XOL/DAz9Om8OBpZNePJQxr2mJjpC8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Xi Ruoyao To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3702] LoongArch: Add fcopysign instructions X-Act-Checkin: gcc X-Git-Author: Xi Ruoyao X-Git-Refname: refs/heads/master X-Git-Oldrev: 07b0096e5b6749d88f5a22f694401abd6aaca551 X-Git-Newrev: 3628025ac604cf76a3fa30ffcc5899f01d3ffee4 Message-Id: <20221106080358.EF4FA3858D38@sourceware.org> Date: Sun, 6 Nov 2022 08:03:58 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3628025ac604cf76a3fa30ffcc5899f01d3ffee4 commit r13-3702-g3628025ac604cf76a3fa30ffcc5899f01d3ffee4 Author: Xi Ruoyao Date: Fri Nov 4 15:12:22 2022 +0800 LoongArch: Add fcopysign instructions Add fcopysign.{s,d} with the names copysign{sf,df}3 so GCC will expand __builtin_copysign{f,} to a single instruction. Link: https://sourceware.org/pipermail/libc-alpha/2022-November/143177.html gcc/ChangeLog: * config/loongarch/loongarch.md (UNSPEC_FCOPYSIGN): New unspec. (type): Add fcopysign. (copysign3): New instruction template. gcc/testsuite/ChangeLog: * gcc.target/loongarch/fcopysign.c: New test. Diff: --- gcc/config/loongarch/loongarch.md | 22 +++++++++++++++++++++- gcc/testsuite/gcc.target/loongarch/fcopysign.c | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index 214b14bddd3..bda34d0f3db 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -37,6 +37,7 @@ UNSPEC_FCLASS UNSPEC_FMAX UNSPEC_FMIN + UNSPEC_FCOPYSIGN ;; Override return address for exception handling. UNSPEC_EH_RETURN @@ -214,6 +215,7 @@ ;; fabs floating point absolute value ;; fneg floating point negation ;; fcmp floating point compare +;; fcopysign floating point copysign ;; fcvt floating point convert ;; fsqrt floating point square root ;; frsqrt floating point reciprocal square root @@ -226,7 +228,7 @@ "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,fcvt,fsqrt, + fmove,fadd,fmul,fmadd,fdiv,frdiv,fabs,fneg,fcmp,fcopysign,fcvt,fsqrt, frsqrt,accext,accmod,multi,atomic,syncloop,nop,ghost" (cond [(eq_attr "jirl" "!unset") (const_string "call") (eq_attr "got" "load") (const_string "load") @@ -976,6 +978,24 @@ (set_attr "mode" "")]) ;; +;; .................... +;; +;; FLOATING POINT COPYSIGN +;; +;; .................... + +(define_insn "copysign3" + [(set (match_operand:ANYF 0 "register_operand" "=f") + (unspec:ANYF [(match_operand:ANYF 1 "register_operand" "f") + (match_operand:ANYF 2 "register_operand" "f")] + UNSPEC_FCOPYSIGN))] + "TARGET_HARD_FLOAT" + "fcopysign.\t%0,%1,%2" + [(set_attr "type" "fcopysign") + (set_attr "mode" "")]) + + +;; ;; ................... ;; ;; Count leading zeroes. diff --git a/gcc/testsuite/gcc.target/loongarch/fcopysign.c b/gcc/testsuite/gcc.target/loongarch/fcopysign.c new file mode 100644 index 00000000000..058ba2cf573 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/fcopysign.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-mdouble-float" } */ +/* { dg-final { scan-assembler "fcopysign\\.s" } } */ +/* { dg-final { scan-assembler "fcopysign\\.d" } } */ + +double +my_copysign (double a, double b) +{ + return __builtin_copysign (a, b); +} + +float +my_copysignf (float a, float b) +{ + return __builtin_copysignf (a, b); +}