From patchwork Wed May 3 07:06:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 678650 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp908043wrs; Wed, 3 May 2023 00:21:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6QYTKXD4tOiHYMG0xuTxNTZA0akECodyvBaaHFJbDnBGAhZrIISlqgEKlcvgfpR2jfZRv2 X-Received: by 2002:a05:6214:411b:b0:61b:6fcd:34af with SMTP id kc27-20020a056214411b00b0061b6fcd34afmr3745343qvb.9.1683098482439; Wed, 03 May 2023 00:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683098482; cv=none; d=google.com; s=arc-20160816; b=zNeO/f9+PnIfMhpIKgEWgskOGfnrunwkEg2RAJNQnND98+gNWkHsuDtnwp1bWBjWWu aX1DKpy6c4ldGVZm6krPsqCwfhY/3E3/RUKlJ7AZ02oUv+NgiFOf2FxbljRaH67lX/Vm W5uswNSCY4YI2X4cajkjxY8rAKfXLcIwRZnEwekAiDNXO44kDnQtxiJafSwScsF83cwX w4UFBEJsEezzsaxJvni2ud4Ez9GDHA83RZ3bp/5TgCSx69yibOhGcGyl4sEDLD7PFMyA GsWCReoNEr1e9h0ki0uBByDhdgWDWrJEjGghIfGxICMvo77iIz0m+FBorub0abG/AVJq ZRfg== 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=sA2aOIeGNBWRjeeou5Y4ut1mvsbxM8pXHUcMzyX3UOg=; b=bVzbgw1Y/ZuUozKwsy8ClWwCuru//8EMwNohLqH5/zRMNIMRpwCHZy09/xSrmWj6hf qXRuJxV5U9z/ZRSNORFP4QDJWjvUoGoET4pbcgrTdnIPjQXBkAwVar7dKtg6gCEdncZ4 0IEGNy4NUmv6OR2GrjVHPePPSv5KKyM8apvK4RQilOF0g7P/BO4KrzGrKSlmGRb71F7q o+rixxyc72cAVJcBwu3PFfNothOr1jb2XAu/Dz5YBjOUxaa0taQ6Dqkz70F4al7UXo5P NitlD3FB5IHF2vIfrEKBXmqNttx6MXLjseuL7C8pTVDCOmLvy9Udrsy7fpgb4o/yVXTn 4+mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FukclqHg; 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 j14-20020a05621419ce00b0056ec21e1722si18561945qvc.110.2023.05.03.00.21.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 May 2023 00:21:22 -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=FukclqHg; 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 1pu6bA-000167-9C; Wed, 03 May 2023 03:08:24 -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 1pu6aS-0006jk-Oc for qemu-devel@nongnu.org; Wed, 03 May 2023 03:07:40 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pu6a2-0005ie-Nm for qemu-devel@nongnu.org; Wed, 03 May 2023 03:07:40 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3063433fa66so1517232f8f.3 for ; Wed, 03 May 2023 00:07:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683097632; x=1685689632; 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=sA2aOIeGNBWRjeeou5Y4ut1mvsbxM8pXHUcMzyX3UOg=; b=FukclqHgBMT9J/gxByhlAW2U8thk+ABrtRkcfnxFr9R/QrINexGHP7u2veZidVDaYC U9ucU0LxbW/v1JjS58bUGmMN8IOgphTKlmCT9lfQ6zGCJqjfkFvFICB6I6golAny07kW 0qMwNy8sJGenc5qG7FNhiVDEN64XQNx6/q5fnMZiJCrF2tERMSPxo8EQx91m2S3QO5+U pCZfCUTmEzZ9m8eanYAHFaHiq6hl9Di1RUBWlY9p3i+3LUv4cQShawg7p2rRBSZ6ToEq sIYQKIL8NUZEA4nn5e25h3pZ0LsH6btSash9rwni0DafQ1x9rQPmnsbee3Ydaj1ee0qh x5dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683097632; x=1685689632; 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=sA2aOIeGNBWRjeeou5Y4ut1mvsbxM8pXHUcMzyX3UOg=; b=gAaPmeNpU2gU523RK+HZY5FRwoi2KOdjAtgVAJvT2sIlqYUYvPgCvn3C6HzjvLvfjk 4yBNdcUuQvCnz8D27LwbblU87f0uvhvQ4X0FUfCS4C7gUzQju4di58cLNVuT6b8xSUP3 UxUl4Unjtz0N8BRRDgyuX/VA4rPuD7l6KAsIOQ/VLqSCXtyoaAEIwEnvS9ygTlFjA6L0 MT7Gr7omkjbPrjaLywDtOengvb7ZzTg5JkteNnkaOnAbfHeub5g6W8sSrYejgVVd5DPq 04yvV535qiPwD27mJ0n4JzJGRfHeKPzpW971GAWQB7QUlN0mQDrINUoFYp0LYYm31vKV CGtg== X-Gm-Message-State: AC+VfDz4q2WGrSWn8Ia7GZWZM0Qa2Sp7wlLrtAkO5vfxYapnvmXPoENe YP1oanPfkBdLy3mgzNv71J6ArWip5cb+KqYzE0D1/Q== X-Received: by 2002:adf:e484:0:b0:306:320b:5dbd with SMTP id i4-20020adfe484000000b00306320b5dbdmr5508212wrm.71.1683097632016; Wed, 03 May 2023 00:07:12 -0700 (PDT) Received: from stoup.Home ([2a02:c7c:74db:8d00:c01d:9d74:b630:9087]) by smtp.gmail.com with ESMTPSA id q3-20020a1cf303000000b003f3157988f8sm921184wmq.26.2023.05.03.00.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 00:07:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name, gaosong@loongson.cn, philmd@linaro.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH v4 19/57] accel/tcg: Add have_lse2 support in ldst_atomicity Date: Wed, 3 May 2023 08:06:18 +0100 Message-Id: <20230503070656.1746170-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230503070656.1746170-1-richard.henderson@linaro.org> References: <20230503070656.1746170-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42c.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 --- 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 2426b09aef..7ed5d4282d 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 @@ -170,6 +174,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; @@ -412,6 +424,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; @@ -767,10 +791,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)