From patchwork Fri Nov 4 14:37:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 15606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp442503wru; Fri, 4 Nov 2022 07:38:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM48QSRoSYLG0xRU9P2Zy6NCIBT48B27Gn9qro4A5pqRULU/u/K7iJXRacIdbjmff8wVxHxp X-Received: by 2002:a17:906:c2c1:b0:7ae:37aa:711 with SMTP id ch1-20020a170906c2c100b007ae37aa0711mr103817ejb.329.1667572708014; Fri, 04 Nov 2022 07:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667572708; cv=none; d=google.com; s=arc-20160816; b=RkNvdT51sKa2k6LiJmvB06Z7ulLS5zMaFrWtFsDGCzsxupqc0sSCgqG6lGVtqbchJ1 uNOA5edbqSmwHueFViWwhJCwiBbMA0gi2Ujoowf3C6axVTdRIUshUQsnRJjhkkMiXhBo rSjrc4WjMoI0Oe558T2ZJ/g/m5I+D0rwwO209RtaMvYCwysUZhJT0Teha/2bSeQuKaHn KJ31eFRkXonX4FFEI0pSB8eIb/0fJEM+PLfpakdMM4sJbdNyLVlURbsiw36zKPWNXKTE iOB06m/jrVQgVtfSYSlJFRfFmsZJjh3opxOmQDRq/aJfckDwkwp/6DJ/yXYphcXkcNyN c+AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=bosiCVjj2yO2obtNQffSWQrnsMabf40XpvaqldYW4kk=; b=CJWUc5eAEIzNmjNCJBDq/MB/T9HS/J4ZAAv97bkLxrcZsU49aTw3swxqmUfsPcurcC Xi4aw7QNIJPdC+MXmUhqi0NH64cE/dlJDR5DYbPPguEDh9iLPXmpUFXe9Ol2blJ3SOsX OPTZR9bwGPgDjmFFSXOAqQsw4M/h77cZ846qVRkzBoXNuf8p55/6GUtcRZ+WJcSPIgSt DyFi7X6ILUh/VIeDp5wqytdoGH9wVGjDxjsr4oCKCWpnDnhZhvbj31/mV2wnUjfHWLGM Xg7t8eOhjWh6Aj+g/iUOhabfPbAtlox3POc1vQpDLppyLJ+6icrYjmrNvyAWnIqpFMCf 4PYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eEQfcklS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id nc33-20020a1709071c2100b007ae165c79c8si5994344ejc.940.2022.11.04.07.38.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 07:38:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eEQfcklS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC8FB385842A for ; Fri, 4 Nov 2022 14:38:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC8FB385842A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667572706; bh=bosiCVjj2yO2obtNQffSWQrnsMabf40XpvaqldYW4kk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=eEQfcklSzQUeRSEFgP4Z7vm+oytpIPWE3u2AGFxDVcpqikKzSMxImGdjSSgr0wiml jpiu9i85ro/vbsTxG6qR5oXpOugqYt76xvdhYgvgX6ZFh2bw3KElytv0sDCNAOdlJ4 XcpqM0lfbR6RZcYhWUQsKGaWTWsyDxV6OewtPfzQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id D47F93858413 for ; Fri, 4 Nov 2022 14:37:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D47F93858413 Received: from xry111-x57s1.. (unknown [IPv6:240e:358:11ed:a500:dc73:854d:832e:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 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 7787766807; Fri, 4 Nov 2022 10:37:33 -0400 (EDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] LoongArch: Add fcopysign instructions Date: Fri, 4 Nov 2022 22:37:19 +0800 Message-Id: <20221104143719.1709284-1-xry111@xry111.site> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FROM_SUSPICIOUS_NTLD, FROM_SUSPICIOUS_NTLD_FP, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Gcc-patches From: Xi Ruoyao Reply-To: Xi Ruoyao Cc: Chenghua Xu , Xiaolin Tang , Lulu Cheng , Wang Xuerui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748576719924541025?= X-GMAIL-MSGID: =?utf-8?q?1748576719924541025?= 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. --- Bootstrapped and regtested on loongarch64-linux-gnu. Ok for trunk? gcc/config/loongarch/loongarch.md | 22 ++++++++++++++++++- .../gcc.target/loongarch/fcopysign.c | 16 ++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/fcopysign.c diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.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" [ UNSPEC_FCLASS UNSPEC_FMAX UNSPEC_FMIN + UNSPEC_FCOPYSIGN ;; Override return address for exception handling. UNSPEC_EH_RETURN @@ -214,6 +215,7 @@ (define_attr "qword_mode" "no,yes" ;; 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 @@ (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,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 @@ (define_insn "abs2" (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))] + "" + "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); +}