From patchwork Mon Mar 25 09:44:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Mei X-Patchwork-Id: 1915470 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oss.cipunited.com header.i=@oss.cipunited.com header.a=rsa-sha256 header.s=feishu2303200042 header.b=TYBTQ+KD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V37NW03c4z1yWy for ; Mon, 25 Mar 2024 20:46:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 364B43858417 for ; Mon, 25 Mar 2024 09:45:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from va-1-14.ptr.blmpb.com (va-1-14.ptr.blmpb.com [209.127.230.14]) by sourceware.org (Postfix) with ESMTPS id B7CF93858404 for ; Mon, 25 Mar 2024 09:45:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B7CF93858404 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=oss.cipunited.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=oss.cipunited.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B7CF93858404 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.127.230.14 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711359935; cv=none; b=mmrbyMPJNh7+vUGSH2gPjJkerA62ZMAZEsfsFA3N1Tc4TTE9cqZzmNH11x8Gl3qOMATw4+/9a5HRAo6Cj0WE3Xe6Y8FqQkf1qozyjt8IBjQMYS0B2kpc1I/lO67SEG4F/R3l+z7VX/Q8SM9oHnqkfOQZSeS0vZgAQ/1GCEsHPBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711359935; c=relaxed/simple; bh=C/S50g9Xu+4poVmWoB6EZFYaYty4mVntJ4oOf0abeao=; h=DKIM-Signature:Subject:Date:Message-Id:To:From:Mime-Version; b=ip+fcnrexh0UYec7XbkfaqMNJQ4+khQCl9N2bLn+WXhxk6IZud9IqYJ6cwJdTx85fzisepAbwBBTSAy5yEBeK2NbSrKE7nmEQp7b8jbAkaWkT3Y9mgHHvw9z5xzaVUNrDsvsy7DtJuCD4My/lHqwwlm6jQMcbjlOXVIdi33/zlQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2303200042; d=oss.cipunited.com; t=1711359923; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=x/fwdnnVYhLQTfak6gAozqj+cL31NbvLSjBADiOGCRg=; b=TYBTQ+KDST9Tf0ygUP55RXqNmxNNitlbB5eNXalIGhbpJVzOT2ey40sNdeUwDY9FFqrZKd FgL0kCwyNUAkD5tAD6LwBencCdW4Fk7uOBVvkCtfZPEK+Y6cZaWKqctFcrlnrEzuD/d7lF 5Fruwr6EPXzjOW6F6jbMCk/c2CRYhbR3cOMw49Iih0YAcjd/P0xUNyl5VpvetIIvE1u1bo fWQrE8rD8YFE7nKn1iI5m5X6arf3UM2DqLVreUDgzBRqbbYSZ1kHcaG5EfofFa84bIjTrS CU29l9xnts5DFqInYpHsZKAsoG+5Is4bsffvJiMwW4VMosPIC4yYFdwAoNbE/A== Subject: [PATCH v2] MIPS: Add MIN/MAX.fmt instructions support for MIPS R6 Date: Mon, 25 Mar 2024 17:44:48 +0800 Cc: "YunQiang Su" , "Xi Ruoyao" Message-Id: <20240325094448.1292735-1-jie.mei@oss.cipunited.com> To: X-Original-From: Jie Mei Received: from fedora.wok.cipunited.com ([123.52.19.173]) by smtp.feishu.cn with ESMTPS; Mon, 25 Mar 2024 17:45:21 +0800 From: "Jie Mei" Mime-Version: 1.0 X-Lms-Return-Path: X-Mailer: git-send-email 2.41.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch adds the smin/smax RTL mode for the min/max.fmt instructions. Also, since the min/max.fmt instrucions applies to the IEEE 754-2008 "minNum" and "maxNum" operations, this patch also provides the new "fmin3" and "fmax3" modes. gcc/ChangeLog: * config/mips/i6400.md (i6400_fpu_minmax): New define_insn_reservation. * config/mips/mips.h (ISA_HAS_FMIN_FMAX): Define new macro. * config/mips/mips.md (UNSPEC_FMIN): New unspec. (UNSPEC_FMAX): Same as above. (type): Add fminmax. (smin3): Generates MIN.fmt instructions. (smax3): Generates MAX.fmt instructions. (fmin3): Generates MIN.fmt instructions. (fmax3): Generates MAX.fmt instructions. * config/mips/p6600.md (p6600_fpu_fabs): Include fminmax type. gcc/testsuite/ChangeLog: * gcc.target/mips/mips-minmax.c: New test for MIPS R6. --- gcc/config/mips/i6400.md | 6 +++ gcc/config/mips/mips.h | 2 + gcc/config/mips/mips.md | 50 ++++++++++++++++++++- gcc/config/mips/p6600.md | 2 +- gcc/testsuite/gcc.target/mips/mips-minmax.c | 40 +++++++++++++++++ 5 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/mips/mips-minmax.c diff --git a/gcc/config/mips/i6400.md b/gcc/config/mips/i6400.md index 9f216fe0210..d6f691ee217 100644 --- a/gcc/config/mips/i6400.md +++ b/gcc/config/mips/i6400.md @@ -219,6 +219,12 @@ (eq_attr "type" "fabs,fneg,fmove")) "i6400_fpu_short, i6400_fpu_apu") +;; min, max +(define_insn_reservation "i6400_fpu_minmax" 2 + (and (eq_attr "cpu" "i6400") + (eq_attr "type" "fminmax")) + "i6400_fpu_short+i6400_fpu_logic") + ;; fadd, fsub, fcvt (define_insn_reservation "i6400_fpu_fadd" 4 (and (eq_attr "cpu" "i6400") diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h index 7145d23c650..5ce984ac99b 100644 --- a/gcc/config/mips/mips.h +++ b/gcc/config/mips/mips.h @@ -1259,6 +1259,8 @@ struct mips_cpu_info { #define ISA_HAS_9BIT_DISPLACEMENT (mips_isa_rev >= 6 \ || ISA_HAS_MIPS16E2) +#define ISA_HAS_FMIN_FMAX (mips_isa_rev >= 6) + /* ISA has data indexed prefetch instructions. This controls use of 'prefx', along with TARGET_HARD_FLOAT and TARGET_DOUBLE_FLOAT. (prefx is a cop1x instruction, so can only be used if FP is diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md index b0fb5850a9e..26f758c90dd 100644 --- a/gcc/config/mips/mips.md +++ b/gcc/config/mips/mips.md @@ -97,6 +97,10 @@ UNSPEC_GET_FCSR UNSPEC_SET_FCSR + ;; Floating-point unspecs. + UNSPEC_FMIN + UNSPEC_FMAX + ;; HI/LO moves. UNSPEC_MFHI UNSPEC_MTHI @@ -370,6 +374,7 @@ ;; frsqrt floating point reciprocal square root ;; frsqrt1 floating point reciprocal square root step1 ;; frsqrt2 floating point reciprocal square root step2 +;; fminmax floating point min/max ;; dspmac DSP MAC instructions not saturating the accumulator ;; dspmacsat DSP MAC instructions that saturate the accumulator ;; accext DSP accumulator extract instructions @@ -387,8 +392,8 @@ prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical, shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move, fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt, - frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat, - multi,atomic,syncloop,nop,ghost,multimem, + frsqrt,frsqrt1,frsqrt2,fminmax,dspmac,dspmacsat,accext,accmod,dspalu, + dspalusat,multi,atomic,syncloop,nop,ghost,multimem, simd_div,simd_fclass,simd_flog2,simd_fadd,simd_fcvt,simd_fmul,simd_fmadd, simd_fdiv,simd_bitins,simd_bitmov,simd_insert,simd_sld,simd_mul,simd_fcmp, simd_fexp2,simd_int_arith,simd_bit,simd_shift,simd_splat,simd_fill, @@ -7971,6 +7976,47 @@ [(set_attr "move_type" "load") (set_attr "insn_count" "2")]) +;; +;; Float point MIN/MAX +;; + +(define_insn "smin3" + [(set (match_operand:SCALARF 0 "register_operand" "=f") + (smin:SCALARF (match_operand:SCALARF 1 "register_operand" "f") + (match_operand:SCALARF 2 "register_operand" "f")))] + "ISA_HAS_FMIN_FMAX" + "min.\t%0,%1,%2" + [(set_attr "type" "fminmax") + (set_attr "mode" "")]) + +(define_insn "smax3" + [(set (match_operand:SCALARF 0 "register_operand" "=f") + (smax:SCALARF (match_operand:SCALARF 1 "register_operand" "f") + (match_operand:SCALARF 2 "register_operand" "f")))] + "ISA_HAS_FMIN_FMAX" + "max.\t%0,%1,%2" + [(set_attr "type" "fminmax") + (set_attr "mode" "")]) + +(define_insn "fmin3" + [(set (match_operand:SCALARF 0 "register_operand" "=f") + (unspec:SCALARF [(use (match_operand:SCALARF 1 "register_operand" "f")) + (use (match_operand:SCALARF 2 "register_operand" "f"))] + UNSPEC_FMIN))] + "ISA_HAS_FMIN_FMAX" + "min.\t%0,%1,%2" + [(set_attr "type" "fminmax") + (set_attr "mode" "")]) + +(define_insn "fmax3" + [(set (match_operand:SCALARF 0 "register_operand" "=f") + (unspec:SCALARF [(use (match_operand:SCALARF 1 "register_operand" "f")) + (use (match_operand:SCALARF 2 "register_operand" "f"))] + UNSPEC_FMAX))] + "ISA_HAS_FMIN_FMAX" + "max.\t%0,%1,%2" + [(set_attr "type" "fminmax") + (set_attr "mode" "")]) ;; 2 HI loads are joined. (define_peephole2 diff --git a/gcc/config/mips/p6600.md b/gcc/config/mips/p6600.md index a9e3262cc18..c502f0eb5c6 100644 --- a/gcc/config/mips/p6600.md +++ b/gcc/config/mips/p6600.md @@ -170,7 +170,7 @@ ;; fabs, fneg, fcmp (define_insn_reservation "p6600_fpu_fabs" 2 (and (eq_attr "cpu" "p6600") - (ior (eq_attr "type" "fabs,fneg,fcmp,fmove") + (ior (eq_attr "type" "fabs,fneg,fcmp,fmove,fminmax") (and (eq_attr "type" "condmove") (eq_attr "mode" "SF,DF")))) "p6600_fpu_short, p6600_fpu_apu") diff --git a/gcc/testsuite/gcc.target/mips/mips-minmax.c b/gcc/testsuite/gcc.target/mips/mips-minmax.c new file mode 100644 index 00000000000..087ed299d8f --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/mips-minmax.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-mhard-float -fno-finite-math-only -march=mips32r6" } */ +/* { dg-skip-if "code quality test" { *-*-* } { "-O0" } { "" } } */ + +/* Test MIN.D. */ + +/* { dg-final { scan-assembler "\tmin\\.d\t" } } */ +double +test01 (double x, double y) +{ + return __builtin_fmin (x, y); +} + +/* Test MIN.S. */ + +/* { dg-final { scan-assembler "\tmin\\.s\t" } } */ +float +test02 (float x, float y) +{ + return __builtin_fminf (x, y); +} + +/* Test MAX.D. */ + +/* { dg-final { scan-assembler "\tmax\\.d\t" } } */ +double +test03 (double x, double y) +{ + return __builtin_fmax (x, y); +} + +/* Test MAX.S. */ + +/* { dg-final { scan-assembler "\tmax\\.s\t" } } */ +float +test04 (float x, float y) +{ + return __builtin_fmaxf (x, y); +} +