From patchwork Wed Dec 14 02:18:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 33018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp488935wrn; Tue, 13 Dec 2022 18:22:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf5n2MCTLFDBkA7r+j4xTlN9V26zXhnAbl1cmIbNm5uAZzlG8x1Kft7lrGcY/BTs35Qn08Rm X-Received: by 2002:a05:6402:2408:b0:467:6a1a:d994 with SMTP id t8-20020a056402240800b004676a1ad994mr20000558eda.7.1670984522105; Tue, 13 Dec 2022 18:22:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670984522; cv=none; d=google.com; s=arc-20160816; b=SX5PR7ZofXMOGn4ySmjCEo6BY2m0k/2duLsqmJX14zv2ApJ1g41kHByi+sLuqnd/0B 0OA6HroeFERXnbtvjDzK7l4amBSwS8XRkGw2NV5Lay2hJjtSCzu0TKQFxde/ygdzcqcH 6uiII9O85RoNJ3xD9Io+fRme/h2OwThrskoIP9MweSBIjtP2Pm4GfvoKLYjIi2Jb838g MRSwVfVqS7tt82sWSwIlR9U0O//lvdk0KMt8XP4qSkcrF7KT1ZncXpig/gwxGlUy35if AVEGl+YVPd2sT7CpUv9yiMAyz8tagLnib8Mz+Jw+QCE0llaRPn7nse/JHI3JhrKTMH8N bPRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=mSmp7T4XzCSBpdSKht0LNLeom3GY5D3vdmv7yo91T38=; b=ymSygJTheoO+vYhzc+o8L8W/PYlKQu+i/GmdI2T/E8dBqzIxNB5Q7rYaNyvNQetuUe oLDYhjZ3zGyie9Jf5+xnPeId7a4Jh9vBVM/xL3BPAbGbCylSBafIqjAn9phHM9BZ3+LA U97cg5Uw6onJZikJF4RGcMm8NiK/oNht+bedbPrI2pgyx/8b7V1ZC/4DhDRzGW1j7ZBv wHS4Gv7Jp5w9V6cJUcKlte1MwNjHQQkk9kBkJC9zTk/G7m07ku94PowkjmabsC5RvZar B2wL6Wbwe6Zi3m4MAIL89Q0otQNSYkyQxdPbbHwAqyhb/r879IzOwxjQUg40eg7aMhNu ORlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KZVBvEPN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id h13-20020a056402280d00b0046b7410c015si12856691ede.18.2022.12.13.18.22.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 18:22:02 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KZVBvEPN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 29CE3383962B for ; Wed, 14 Dec 2022 02:22:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29CE3383962B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670984521; bh=mSmp7T4XzCSBpdSKht0LNLeom3GY5D3vdmv7yo91T38=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=KZVBvEPN6EBTFc0GOo1FaZbsDpoZE69Umew6aBS3yE9sLXV1nXPR2iI6+Klb3VuN5 e0vngjjGMDaFxV0WAA5PLVXN3Z6Q/AupRfurO1rj4TGEMAY3ngUHa882bbhi/6QPKt ZvC5In0so2qKNKfH0AVCmPcfKQD2HATGYuPqm6l4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by sourceware.org (Postfix) with ESMTPS id 08E0F383A0F6 for ; Wed, 14 Dec 2022 02:20:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 08E0F383A0F6 X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="305933314" X-IronPort-AV: E=Sophos;i="5.96,243,1665471600"; d="scan'208";a="305933314" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2022 18:20:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="755733763" X-IronPort-AV: E=Sophos;i="5.96,243,1665471600"; d="scan'208";a="755733763" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga002.fm.intel.com with ESMTP; 13 Dec 2022 18:20:43 -0800 Received: from shliclel4051.sh.intel.com (shliclel4051.sh.intel.com [10.239.240.51]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 5D454100571F; Wed, 14 Dec 2022 10:20:42 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com, ubizjak@gmail.com Subject: [PATCH] [x86] x86: Don't add crtfastmath.o for -shared and add a new option -mdaz-ftz to enable FTZ and DAZ flags in MXCSR. Date: Wed, 14 Dec 2022 10:18:42 +0800 Message-Id: <20221214021842.1015348-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: liuhongt via Gcc-patches From: liuhongt Reply-To: liuhongt 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?1752154265925678710?= X-GMAIL-MSGID: =?utf-8?q?1752154265925678710?= Don't add crtfastmath.o for -shared to avoid changing the MXCSR register when loading a shared library. crtfastmath.o will be used only when building executables. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ok for trunk? gcc/ChangeLog: PR target/55522 PR target/36821 * config/i386/gnu-user-common.h (GNU_USER_TARGET_MATHFILE_SPEC): Link crtfastmath.o when -mdaz-ftz is specified, not link it when -shared is specified. * config/i386/i386.opt (mdaz-ftz): New option. * doc/invoke.texi (x86 options): Document mftz-daz. --- gcc/config/i386/gnu-user-common.h | 2 +- gcc/config/i386/i386.opt | 4 ++++ gcc/doc/invoke.texi | 10 +++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gcc/config/i386/gnu-user-common.h b/gcc/config/i386/gnu-user-common.h index cab9be2bfb7..02e4a2192a4 100644 --- a/gcc/config/i386/gnu-user-common.h +++ b/gcc/config/i386/gnu-user-common.h @@ -47,7 +47,7 @@ along with GCC; see the file COPYING3. If not see /* Similar to standard GNU userspace, but adding -ffast-math support. */ #define GNU_USER_TARGET_MATHFILE_SPEC \ - "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ + "%{Ofast|ffast-math|funsafe-math-optimizations|mdaz-ftz:%{!shared:crtfastmath.o%s}} \ %{mpc32:crtprec32.o%s} \ %{mpc64:crtprec64.o%s} \ %{mpc80:crtprec80.o%s}" diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index fb4e57ada7c..8fd222db857 100644 --- a/gcc/config/i386/i386.opt +++ b/gcc/config/i386/i386.opt @@ -420,6 +420,10 @@ mpc80 Target RejectNegative Set 80387 floating-point precision to 80-bit. +mdaz-ftz +Target RejectNegative +Set the FTZ and DAZ Flags. + mpreferred-stack-boundary= Target RejectNegative Joined UInteger Var(ix86_preferred_stack_boundary_arg) Attempt to keep stack aligned to this power of 2. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index cb40b38b73a..670e3767fbd 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1433,7 +1433,7 @@ See RS/6000 and PowerPC Options. -m96bit-long-double -mlong-double-64 -mlong-double-80 -mlong-double-128 @gol -mregparm=@var{num} -msseregparm @gol -mveclibabi=@var{type} -mvect8-ret-in-mem @gol --mpc32 -mpc64 -mpc80 -mstackrealign @gol +-mpc32 -mpc64 -mpc80 -mdaz-ftz -mstackrealign @gol -momit-leaf-frame-pointer -mno-red-zone -mno-tls-direct-seg-refs @gol -mcmodel=@var{code-model} -mabi=@var{name} -maddress-mode=@var{mode} @gol -m32 -m64 -mx32 -m16 -miamcu -mlarge-data-threshold=@var{num} @gol @@ -32752,6 +32752,14 @@ are enabled by default; routines in such libraries could suffer significant loss of accuracy, typically through so-called ``catastrophic cancellation'', when this option is used to set the precision to less than extended precision. +@item -mdaz-ftz +@opindex mdaz-ftz + +the flush-to-zero (FTZ) and denormals-are-zero (DAZ) flags in the MXCSR register +are used to control floating-point calculations.SSE and AVX instructions +including scalar and vector instructions could benefit from enabling the FTZ +and DAZ flags when @option{-mdaz-ftz} is specified. + @item -mstackrealign @opindex mstackrealign Realign the stack at entry. On the x86, the @option{-mstackrealign}