From patchwork Fri Jan 15 00:08:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1426735 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org 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=c4f7e7gx; 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 4DH1kT75Tpz9sVw for ; Fri, 15 Jan 2021 11:09:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 357C83870919; Fri, 15 Jan 2021 00:09:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 357C83870919 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1610669340; bh=rJqJ1J7EJwpJMsHmSDSnsmzwxpqd1X3gcEpvT4C4c10=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=c4f7e7gxxTPSu2FVLX25QgPPYTT1BgjXc1JUPxAvH9H429ymSjEGPbn/amAxIu3Lq WnSxtIG2Y+WFt/XvbeVjlvs5ooA4uw0vPRZOMeJwSftxbn56A3DuTSBpbSBq0pH2hs BDXllpZVCGvJcNjaOAckMK8zB3WF/YENtSRCq1l0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 6406A387090F for ; Fri, 15 Jan 2021 00:08:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6406A387090F Received: by mail-ot1-x335.google.com with SMTP id x13so6944929oto.8 for ; Thu, 14 Jan 2021 16:08:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rJqJ1J7EJwpJMsHmSDSnsmzwxpqd1X3gcEpvT4C4c10=; b=bn1mcDzvEIV+ps2fmwLBPwh0KCrtGRmKnI9eGl5IpmmWqobVs4VzdP+tUwFn8SgR24 zG7Ib/uRWZFANeEjWwGJRgp6KIHWMT6HcLMDxFEriRWTSak9UYFh1FjXSUCUs8rW7C6J vEQtNtTYl5KfI+20wB+m42vBFDW8kKD/K13qZox559Tqu/yatEfddSx6NDHd7vsghZxf nOn8OZe8czlgbQyWSnbs1D5Zv5Txfwu+IAjZA6NLkv8a9tj4wf5QrFtvgrIwysrJRuAx 4hZKqxAUx4JSSIrNQt1EufDz/UB5DTewRIPvnohkmVjmEVfjeVhH/y7dS4eE+rW3oa1Y zbKg== X-Gm-Message-State: AOAM533kGk99imoiUgY/Vu2rL1tdI7mKSjjn3SfzhI5SKMZreBzBaRA1 PmmbcMy/str5c/IJjYdsqzYt45gAMbW4JbeTI3E= X-Google-Smtp-Source: ABdhPJxrw5dvKs3Z1SaDmvI/5vP7lHkIDKvK8qiO4KdwM1no6r7UJ7jjUXStMtZztNAkdwBUmCKLrVj8gi8mHfFpqVc= X-Received: by 2002:a05:6830:1d71:: with SMTP id l17mr6324838oti.269.1610669336758; Thu, 14 Jan 2021 16:08:56 -0800 (PST) MIME-Version: 1.0 References: <20210114210431.463242-1-hjl.tools@gmail.com> <20210114210431.463242-4-hjl.tools@gmail.com> <20210114230117.GD1034503@tucnak> In-Reply-To: <20210114230117.GD1034503@tucnak> Date: Thu, 14 Jan 2021 16:08:20 -0800 Message-ID: Subject: V2 [PATCH 3/3] Build x86 libatomic with -march=i486 or better To: Jakub Jelinek X-Spam-Status: No, score=-3036.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Uros Bizjak , GCC Patches Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" On Thu, Jan 14, 2021 at 3:01 PM Jakub Jelinek wrote: > > On Thu, Jan 14, 2021 at 01:04:31PM -0800, H.J. Lu via Gcc-patches wrote: > > If x86 libatomic isn't compiled with -march=i486 or better, append > > -march=i486 XCFLAGS for x86 libatomic build. Set try_ifunc to yes > > if -mcx16 isn't used to compile x86-64 libatomic or -march=i686 or > > better isn't used to compile x86 libatomic. > > > > PR target/70454 > > * configure.tgt (XCFLAGS): Append -march=i486 to compile x86 > > libatomic if needed. > > (try_ifunc): Set to yes only if needed. > > --- > > libatomic/configure.tgt | 73 ++++++++++++++++++++++++++++------------- > > 1 file changed, 50 insertions(+), 23 deletions(-) > > > > diff --git a/libatomic/configure.tgt b/libatomic/configure.tgt > > index 2f24817b454..1f3a3ad6c7c 100644 > > --- a/libatomic/configure.tgt > > +++ b/libatomic/configure.tgt > > @@ -81,32 +81,59 @@ case "${target_cpu}" in > > ARCH=sparc > > ;; > > > > - i[3456]86) > > - case " ${CC} ${CFLAGS} " in > > - *" -m64 "*|*" -mx32 "*) > > - ;; > > - *) > > - if test -z "$with_arch"; then > > - XCFLAGS="${XCFLAGS} -march=i486 -mtune=${target_cpu}" > > - XCFLAGS="${XCFLAGS} -fomit-frame-pointer" > > - fi > > - esac > > - ARCH=x86 > > - # ??? Detect when -march=i686 is already enabled. > > - try_ifunc=yes > > - ;; > > - x86_64) > > - case " ${CC} ${CFLAGS} " in > > - *" -m32 "*) > > + i[3456]86 | x86_64) > > + # Need i486 or better. > > + cat > conftestx.c < > +#if defined __x86_64__ || defined __i486__ || defined __pentium__ \ > > + || defined __pentiumpro__ || defined __pentium4__ \ > > + || defined __geode__ || defined __SSE__ > > +# error Need i486 or better > > +#endif > > Rather than hoping we got all the defines right, wouldn't it be better to > compile with -S a testcase like: > int > foo (int *p, int x, int y) > { > return __sync_val_compare_and_swap (p, x, y); > } > and if there is __sync_val_compare_and_swap_4 in the assembly assume > -march=i486 needs to be added? > I.e. test for what exactly we need (working atomics). > > Jakub > Here is the updated patch. OK for master? Thanks. From f847185c4faa94b6dbb52327c13d5d5bfec9b259 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 2 May 2016 09:44:07 -0700 Subject: [PATCH] Build x86 libatomic with -march=i486 or better If x86 libatomic isn't compiled with -march=i486 or better, append -march=i486 XCFLAGS for x86 libatomic build. Set try_ifunc to yes if -mcx16 isn't used to compile x86-64 libatomic or -march=i686 or better isn't used to compile x86 libatomic. PR target/70454 * configure.tgt (XCFLAGS): Append -march=i486 to compile x86 libatomic if needed. (try_ifunc): Set to yes only if needed. --- libatomic/configure.tgt | 74 ++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/libatomic/configure.tgt b/libatomic/configure.tgt index 2f24817b454..3530c992264 100644 --- a/libatomic/configure.tgt +++ b/libatomic/configure.tgt @@ -81,32 +81,60 @@ case "${target_cpu}" in ARCH=sparc ;; - i[3456]86) - case " ${CC} ${CFLAGS} " in - *" -m64 "*|*" -mx32 "*) - ;; - *) - if test -z "$with_arch"; then - XCFLAGS="${XCFLAGS} -march=i486 -mtune=${target_cpu}" - XCFLAGS="${XCFLAGS} -fomit-frame-pointer" - fi - esac - ARCH=x86 - # ??? Detect when -march=i686 is already enabled. - try_ifunc=yes - ;; - x86_64) - case " ${CC} ${CFLAGS} " in - *" -m32 "*) + i[3456]86 | x86_64) + # Need i486 or better. + cat > conftestx.c < /dev/null 2>&1 \ + && grep -q __sync_val_compare_and_swap conftestx.s /dev/null; then + if test "${target_cpu}" = x86_64; then XCFLAGS="${XCFLAGS} -march=i486 -mtune=generic" XCFLAGS="${XCFLAGS} -fomit-frame-pointer" - ;; - *) - ;; - esac + else + XCFLAGS="${XCFLAGS} -march=i486 -mtune=${target_cpu}" + XCFLAGS="${XCFLAGS} -fomit-frame-pointer" + fi + fi + # Detect if -march=i686/-mcx16 is already enabled. + cat > conftestx.c < /dev/null 2>&1; then + if grep cmpxchg16b conftestx.s >/dev/null; then + # This is the 64-bit library. + try_ifunc=no + elif grep i686 conftestx.s >/dev/null; then + # This is the 32-bit library. + try_ifunc=no + else + try_ifunc=yes + fi + fi + rm -f conftestx.c conftestx.s ARCH=x86 - # ??? Detect when -mcx16 is already enabled. - try_ifunc=yes ;; *) ARCH="${target_cpu}" ;; -- 2.29.2