From patchwork Mon May 15 14:32:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 681951 Delivered-To: patch@linaro.org Received: by 2002:adf:fd8f:0:0:0:0:0 with SMTP id d15csp1150140wrr; Mon, 15 May 2023 07:38:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4FxGIUiPJhWhmTe1b8WVFHORDSt9dpjmXBtvSfeTTr91yXC7Bk1Ako9Z5M1IlCroG7f0vh X-Received: by 2002:a7b:ca51:0:b0:3f4:2148:e8e5 with SMTP id m17-20020a7bca51000000b003f42148e8e5mr20534015wml.1.1684161528511; Mon, 15 May 2023 07:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684161528; cv=none; d=google.com; s=arc-20160816; b=bVDi7QOTP2QdDARRyEm/IpL5y20KKlyQWLOx4xGbOpVNOpe7Q4Fakh6mKlx8VhN2V+ TLYY2eGGTaaQlUZwEcdrg7YvpDegeOQPP3CWcqBWAaUEyC6HpC+GWVvIebuEbi10JOhK kJRSn53ri+eKY5oraxLylW4Q3PBLXE11tJb/OoaUcz9erNjXbYS7VJFDEhuFM6McEf2U gXa/vePby6/qWPXlofvImZDR29XeJFo3h1ijUNiSWYX2ZobK1ck5gfYu2pfhvBzO2E/d QOKP/kn48VAPDcvGVqIp5jdsTZEtMnCyeZbQpLVfq80o6K/FrK5L4IveUoTGOaqlvvze Ispg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DMoWoQ65Io3QGIn4AARUwI/lV3SXmcaQgibucuZllj0=; b=Yb8iS24ow51Sb0K9AdKJP31yYytzB4HZLSAbX+9JXWA17C4eFExLvRQXJDbgtjOXzo PNbV74PfqvbD37beLocxgyD6eS3Gc/HZWiybnwUI88ybDEKGoaHCam0ANO/xjz49RlHa fZbQIEf8NJsrj+WZNxeLhZ6OfAJWaX5MgvVAh7T5og1dhZE71jEdiXhR2CRdegg8E0IH A4gQgGA/Sd8X6AsHTwgIpRpkqZbdGHAbmf/61nGTxfrVfZy0FCsCWi1WgfM9nrGGZoYO 6KZH9AJwwcm3Cm5p70u7FJwMRTgs9R0ywsh7Ny5ZMXBLUNLOxc+Zz/wtpGphztfjbCMV bfnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iFPd+TIF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i2-20020a05600c354200b003f16fc56e81si10219464wmq.4.2023.05.15.07.38.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 May 2023 07:38:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iFPd+TIF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pyZIc-0000Rs-Nu; Mon, 15 May 2023 10:35:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pyZHS-0006xb-Ft for qemu-devel@nongnu.org; Mon, 15 May 2023 10:34:36 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pyZGT-0004ur-5e for qemu-devel@nongnu.org; Mon, 15 May 2023 10:33:40 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1ab1ce53ca6so91622325ad.0 for ; Mon, 15 May 2023 07:33:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684161207; x=1686753207; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DMoWoQ65Io3QGIn4AARUwI/lV3SXmcaQgibucuZllj0=; b=iFPd+TIF2ky4pI0KR/xAtEw8XBlXrQnDOhq7Rpm2BD88C6AnIOBLbMOconYCQ5s9f9 OYUt2UxfEGWceiTNmOhFe80Ql/Ws7Mo5uONbYVyz6cRYOUXCPCoIYZayCtz5mbl8KqJs YSwQQXKuW9YLIgw0Pf/YRBDhAXpDOI9bky8Q6m3icKjGhRPYoToxEEtT7/wWoJRR6NEJ MwftKv/dzEU0o0/jxqekloG+9zkPWjpxwVVFkpgTUTDpv8/sdxOwoWFeSE9MQ60ExIYR 1wt/jHvPJoQDfal8AryeOOIr9kQYTHIk81AEUf5SWDO8OKzYj6Ra6LrcllYv1w4/Dxlz 3mXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684161207; x=1686753207; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DMoWoQ65Io3QGIn4AARUwI/lV3SXmcaQgibucuZllj0=; b=bu15FZ0c0qnuPRJWbIBy+lbCYkYJB4gjnqGAyfa/vtcrBB74CyhovHgtYdMgcEPcTG jCPrdT6P7B/HY71SP2iAR3xFOq6AFXiDjSBvEn44/dBZIx5FW/6WbtH2z8JXtNLtxl7V ipueH6FKC96JQfdRcvFzziMCF78EatRSSIVPBczz4tfdF/+ye7FMuYtZHMN68u6v+RBK uPpgCiIyDCaxAa7+CFwbZZuW/eemCHXNAN2R+nkRDe4aAVbyYkSk/1a2XO8uQcpqgUPr +Nk2dJz5hmxDdDmHC04fKA6EXJGDlq9V9pcY05+umpykpnc5JKvf5thqATlXHwi1x/DA 7zCQ== X-Gm-Message-State: AC+VfDyY+WIcLiMi4IgA1y40itQQdgOqKhS/5Grg/lVIAM/eXzs0k3yr wgxiQNFAYEEUg5dH5p52dBc+uLhiFdh+Ml0/aFg= X-Received: by 2002:a17:903:22cd:b0:1a2:19c1:a974 with SMTP id y13-20020a17090322cd00b001a219c1a974mr41100139plg.68.1684161206843; Mon, 15 May 2023 07:33:26 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:9902:96ac:8d8c:4366]) by smtp.gmail.com with ESMTPSA id ik9-20020a170902ab0900b001ab0aec388bsm13694335plb.135.2023.05.15.07.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 07:33:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH v5 14/54] accel/tcg: Add have_lse2 support in ldst_atomicity Date: Mon, 15 May 2023 07:32:33 -0700 Message-Id: <20230515143313.734053-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230515143313.734053-1-richard.henderson@linaro.org> References: <20230515143313.734053-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add fast paths for FEAT_LSE2, using the detection in tcg. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- accel/tcg/ldst_atomicity.c.inc | 37 ++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/accel/tcg/ldst_atomicity.c.inc b/accel/tcg/ldst_atomicity.c.inc index c3b2b35823..baa935ab8b 100644 --- a/accel/tcg/ldst_atomicity.c.inc +++ b/accel/tcg/ldst_atomicity.c.inc @@ -41,6 +41,8 @@ * but we're using tcg/tci/ instead. */ # define HAVE_al16_fast false +#elif defined(__aarch64__) +# define HAVE_al16_fast likely(have_lse2) #elif defined(__x86_64__) && defined(CONFIG_INT128) # define HAVE_al16_fast likely(have_atomic16) #else @@ -48,6 +50,8 @@ #endif #if defined(CONFIG_ATOMIC128) || defined(CONFIG_CMPXCHG128) # define HAVE_al16 true +#elif defined(__aarch64__) +# define HAVE_al16 true #else # define HAVE_al16 false #endif @@ -186,6 +190,14 @@ load_atomic16(void *pv) r.u = qatomic_read__nocheck(p); return r.s; +#elif defined(__aarch64__) + uint64_t l, h; + + /* Via HAVE_al16_fast, FEAT_LSE2 is present: LDP becomes atomic. */ + asm("ldp %0, %1, %2" : "=r"(l), "=r"(h) : "m"(*(__uint128_t *)pv)); + + qemu_build_assert(!HOST_BIG_ENDIAN); + return int128_make128(l, h); #elif defined(__x86_64__) && defined(CONFIG_INT128) Int128Alias r; @@ -428,6 +440,18 @@ load_atom_extract_al16_or_al8(void *pv, int s) r = qatomic_read__nocheck(p16); } return r >> shr; +#elif defined(__aarch64__) + /* + * Via HAVE_al16_fast, FEAT_LSE2 is present. + * LDP becomes single-copy atomic if 16-byte aligned, and + * single-copy atomic on the parts if 8-byte aligned. + */ + uintptr_t pi = (uintptr_t)pv; + int shr = (pi & 7) * 8; + uint64_t l, h; + + asm("ldp %0, %1, %2" : "=r"(l), "=r"(h) : "m"(*(__uint128_t *)(pi & ~7))); + return (l >> shr) | (h << (-shr & 63)); #elif defined(__x86_64__) && defined(CONFIG_INT128) uintptr_t pi = (uintptr_t)pv; int shr = (pi & 7) * 8; @@ -783,10 +807,15 @@ store_atomic16(void *pv, Int128Alias val) l = int128_getlo(val.s); h = int128_gethi(val.s); - asm("0: ldxp %0, xzr, %1\n\t" - "stxp %w0, %2, %3, %1\n\t" - "cbnz %w0, 0b" - : "=&r"(t), "=Q"(*(__uint128_t *)pv) : "r"(l), "r"(h)); + if (HAVE_al16_fast) { + /* Via HAVE_al16_fast, FEAT_LSE2 is present: STP becomes atomic. */ + asm("stp %1, %2, %0" : "=Q"(*(__uint128_t *)pv) : "r"(l), "r"(h)); + } else { + asm("0: ldxp %0, xzr, %1\n\t" + "stxp %w0, %2, %3, %1\n\t" + "cbnz %w0, 0b" + : "=&r"(t), "=Q"(*(__uint128_t *)pv) : "r"(l), "r"(h)); + } return; } #elif defined(CONFIG_CMPXCHG128)