From patchwork Thu Jul 1 06:16:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1499403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=lwq3N4vS; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GFqGv4SdDz9sVb for ; Thu, 1 Jul 2021 17:15:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C97A3848027 for ; Thu, 1 Jul 2021 07:14:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C97A3848027 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1625123699; bh=gdDrhoHzpco2PqgVG/52gzxAWeezPNj+nbDK8ARlIZ4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lwq3N4vSAzt7Wr8thgSR/A+2VPGRjJViFPIFbEwT9zW6D6Ppgc9c9R9Xcr5F+CDf7 RkSx0H0IZ/w7tSEJHlmfEJQM0PL4cvHpWMwSN2dvmc/2jmv8KEQVdw6Rjp9aB+olvn GnQTZE+2Xbc/fP4Gw4dN9ciOQm++eya+btnzJ3Zs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id C8ED23840020 for ; Thu, 1 Jul 2021 06:18:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8ED23840020 X-IronPort-AV: E=McAfee;i="6200,9189,10031"; a="294115052" X-IronPort-AV: E=Sophos;i="5.83,313,1616482800"; d="scan'208";a="294115052" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2021 23:18:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,313,1616482800"; d="scan'208";a="420288009" Received: from scymds01.sc.intel.com ([10.148.94.138]) by fmsmga007.fm.intel.com with ESMTP; 30 Jun 2021 23:18:16 -0700 Received: from shliclel320.sh.intel.com (shliclel320.sh.intel.com [10.239.236.50]) by scymds01.sc.intel.com with ESMTP id 1616GmfW031625; Wed, 30 Jun 2021 23:18:15 -0700 To: gcc-patches@gcc.gnu.org Subject: [PATCH 53/62] AVX512FP16: Add expander for sqrthf2. Date: Thu, 1 Jul 2021 14:16:39 +0800 Message-Id: <20210701061648.9447-54-hongtao.liu@intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210701061648.9447-1-hongtao.liu@intel.com> References: <20210701061648.9447-1-hongtao.liu@intel.com> X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: liuhongt via Gcc-patches From: liuhongt Reply-To: liuhongt Cc: jakub@redhat.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ChangeLog: * config/i386/i386-features.c (i386-features.c): Handle E_HFmode. * config/i386/i386.md (sqrthf2): New expander. (*sqrt2_sse): Extend to MODEFH. * config/i386/sse.md (*_vmsqrt2): Extend to VFH_128. gcc/testsuite/ChangeLog: * gcc.target/i386/avx512fp16-builtin-sqrt-1.c: New test. * gcc.target/i386/avx512fp16vl-builtin-sqrt-1.c: New test. --- gcc/config/i386/i386-features.c | 15 +++++++++++---- gcc/config/i386/i386.md | 12 +++++++++--- gcc/config/i386/sse.md | 8 ++++---- .../i386/avx512fp16-builtin-sqrt-1.c | 18 ++++++++++++++++++ .../i386/avx512fp16vl-builtin-sqrt-1.c | 19 +++++++++++++++++++ 5 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16-builtin-sqrt-1.c create mode 100644 gcc/testsuite/gcc.target/i386/avx512fp16vl-builtin-sqrt-1.c diff --git a/gcc/config/i386/i386-features.c b/gcc/config/i386/i386-features.c index a25769ae478..0b5a1a3af53 100644 --- a/gcc/config/i386/i386-features.c +++ b/gcc/config/i386/i386-features.c @@ -2238,15 +2238,22 @@ remove_partial_avx_dependency (void) rtx zero; machine_mode dest_vecmode; - if (dest_mode == E_SFmode) + switch (dest_mode) { + case E_HFmode: + dest_vecmode = V8HFmode; + zero = gen_rtx_SUBREG (V8HFmode, v4sf_const0, 0); + break; + case E_SFmode: dest_vecmode = V4SFmode; zero = v4sf_const0; - } - else - { + break; + case E_DFmode: dest_vecmode = V2DFmode; zero = gen_rtx_SUBREG (V2DFmode, v4sf_const0, 0); + break; + default: + gcc_unreachable (); } /* Change source to vector mode. */ diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index a85c23d74f1..81c893c60de 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -16561,9 +16561,9 @@ (define_expand "rsqrtsf2" }) (define_insn "*sqrt2_sse" - [(set (match_operand:MODEF 0 "register_operand" "=v,v,v") - (sqrt:MODEF - (match_operand:MODEF 1 "nonimmediate_operand" "0,v,m")))] + [(set (match_operand:MODEFH 0 "register_operand" "=v,v,v") + (sqrt:MODEFH + (match_operand:MODEFH 1 "nonimmediate_operand" "0,v,m")))] "SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH" "@ %vsqrt\t{%d1, %0|%0, %d1} @@ -16583,6 +16583,12 @@ (define_insn "*sqrt2_sse" ] (symbol_ref "true")))]) +(define_expand "sqrthf2" + [(set (match_operand:HF 0 "register_operand") + (sqrt:HF + (match_operand:HF 1 "nonimmediate_operand")))] + "TARGET_AVX512FP16") + (define_expand "sqrt2" [(set (match_operand:MODEF 0 "register_operand") (sqrt:MODEF diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index 2c3dba5bdb0..b47e7f0b82a 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -2389,12 +2389,12 @@ (define_insn "_vmsqrt2" (set_attr "mode" "")]) (define_insn "*_vmsqrt2" - [(set (match_operand:VF_128 0 "register_operand" "=x,v") - (vec_merge:VF_128 - (vec_duplicate:VF_128 + [(set (match_operand:VFH_128 0 "register_operand" "=x,v") + (vec_merge:VFH_128 + (vec_duplicate:VFH_128 (sqrt: (match_operand: 1 "nonimmediate_operand" "xm,"))) - (match_operand:VF_128 2 "register_operand" "0,v") + (match_operand:VFH_128 2 "register_operand" "0,v") (const_int 1)))] "TARGET_SSE" "@ diff --git a/gcc/testsuite/gcc.target/i386/avx512fp16-builtin-sqrt-1.c b/gcc/testsuite/gcc.target/i386/avx512fp16-builtin-sqrt-1.c new file mode 100644 index 00000000000..38cdf23fef7 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx512fp16-builtin-sqrt-1.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast -mavx512fp16" } */ + +_Float16 +f1 (_Float16 x) +{ + return __builtin_sqrtf16 (x); +} + +void +f2 (_Float16* __restrict psrc, _Float16* __restrict pdst) +{ + for (int i = 0; i != 32; i++) + pdst[i] = __builtin_sqrtf16 (psrc[i]); +} + +/* { dg-final { scan-assembler-times "vsqrtsh\[^\n\r\]*xmm\[0-9\]" 1 } } */ +/* { dg-final { scan-assembler-times "vsqrtph\[^\n\r\]*zmm\[0-9\]" 1 } } */ diff --git a/gcc/testsuite/gcc.target/i386/avx512fp16vl-builtin-sqrt-1.c b/gcc/testsuite/gcc.target/i386/avx512fp16vl-builtin-sqrt-1.c new file mode 100644 index 00000000000..08deb3ea470 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx512fp16vl-builtin-sqrt-1.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast -mavx512fp16 -mavx512vl" } */ + +void +f1 (_Float16* __restrict psrc, _Float16* __restrict pdst) +{ + for (int i = 0; i != 8; i++) + pdst[i] = __builtin_sqrtf16 (psrc[i]); +} + +void +f2 (_Float16* __restrict psrc, _Float16* __restrict pdst) +{ + for (int i = 0; i != 16; i++) + pdst[i] = __builtin_sqrtf16 (psrc[i]); +} + +/* { dg-final { scan-assembler-times "vsqrtph\[^\n\r\]*xmm\[0-9\]" 1 } } */ +/* { dg-final { scan-assembler-times "vsqrtph\[^\n\r\]*ymm\[0-9\]" 1 } } */