From patchwork Wed May 24 01:14:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 685305 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2505wrt; Tue, 23 May 2023 18:15:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ591aCMeayLQYMuwOP04sZTFtmg5wDd/e7HDSCmz6FbuDFQUC5cn1r1l9JWcscZt4rph6C1 X-Received: by 2002:ad4:5d48:0:b0:616:4c4b:c9b9 with SMTP id jk8-20020ad45d48000000b006164c4bc9b9mr29650300qvb.37.1684890959716; Tue, 23 May 2023 18:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684890959; cv=none; d=google.com; s=arc-20160816; b=rHk7+5mCwMZpSXw+J+7ME+2MH05UayEb/G7jGh/Gw6Jt9YLVqi02gFrGb54qNSWXb/ +wWpaJPD6vLTprLFnyX/SXmD5z8xoSwoyUtTB+MHnRIZ12HcXQK15iT+Ld/mTqag9ELa B/3rz55NHFGRmYp60GNb8p9HuKWRMTYZHJoGISdEjbLWYXWWAKHD56PO6Ls80cxHsr4w jE/ft2i2mxNg2+fMntaoUzRtKwsAlL5RUKEljX48rd6gJycsZTEccN/yQIpQqK9Xna/i rfxzCYlfayXo1pHFTAmme7VnXhAWVduLmeXbt9kB+45lwzaQZ3Ix6notukpAOAOc2f67 pD6A== 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=ly+VK0VMO/TuoOVvjQ+uSzdztuTYMwcqrfWrGWGkIGA=; b=pPsZNPzQSF6ythDpecA+H4EORxOddqBBoIWIoNIFInwgdCxTD2PDqANJJmq3B9zEvh b4Jq15WxkD29d9oQoSOQ7Kmad64GUNMIYXgY7iYDoMgAlFJPsURwKUvpoC2l+jFYLfci lE6Mszl6tQu1g7PupLnhXaxc07EZDhzmNjJ36Dhh949RHXvc1ew5KWQk56avDF8LRm0w rE5Ek0n2sdTPUtTk3rxECXpGP3COFDVwj1WFo6+U/3/3h7fMSu39Q5BSUBcAGW7Jmf+S wnqVQYITMd9lnTk/L5kB0fmmx12Fi9jKYMqZgtDcHSM6eGuPY66OPhFVLZEUuTCxjwY0 lkUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tvE0sIaa; 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 jf10-20020a0562142a4a00b006259c239216si1509408qvb.446.2023.05.23.18.15.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 May 2023 18:15:59 -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=tvE0sIaa; 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 1q1d5k-00005h-3V; Tue, 23 May 2023 21:15:04 -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 1q1d5j-00005H-4a for qemu-devel@nongnu.org; Tue, 23 May 2023 21:15:03 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1d5c-0001jN-79 for qemu-devel@nongnu.org; Tue, 23 May 2023 21:15:02 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-64d5f65a2f7so163012b3a.1 for ; Tue, 23 May 2023 18:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684890894; x=1687482894; 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=ly+VK0VMO/TuoOVvjQ+uSzdztuTYMwcqrfWrGWGkIGA=; b=tvE0sIaa0irnsXrB+OiIf8PLWgS3fsoNDU3/YwPvpNO+eG3/NYAxizSasDkaZS2Lnj Wsgl9Lr28Qlc3xrJCgntX4ebRLeK34PD3vouTtsAiMVVlcViANk6WQgTvsy9dkE0oo1d vQNiU1fbZdPfbLwkcF2dc7jLA8J0wb1MK7ueooyVbfqrjLq41ZDQGnnwTJRr/+mYTBJp YaW/YD7uSB0Xq32G04Hk9GyAAlRB2Eco2S0Ho05mLwyUTx/LO5W2QC4OFSzQjOin67Lq CSNwrRXOazsPbkHDSfOMc1WnwDmzs1FGW/NINuUWIwF7oqUZo7pN/Q3WzQQPZEHwmnxQ BfTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684890894; x=1687482894; 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=ly+VK0VMO/TuoOVvjQ+uSzdztuTYMwcqrfWrGWGkIGA=; b=gCANEJSe0uJ6Q6yaTc+aOsJH6fO9Lt5v84MdAE38YJJWo9hLyXO/Ua6smmeY8d26IS AmuNqs3cnV54wbdiB6cJa6QRJQX5bPMphiBJIqxK+DqZIU7IlLWYJY59W2gyw+JjyxiT 0v04mmxDnY8Xe7MJPmHCzK8fXVu4iQrkMVPHyi+Zbgs83DnDZlaejtraiVa09vs2m2Xb T+76Uu+dnwWncCiNQ+tSfzyzs1LkSvy2uSW9y9duB18ID+n9+SmkdPltQOmwl9qASCpo ad+hEZVQpMNZWvyUS2QzDnndQ1pSi2S6q0mVmYwMpSuO1L9YnCN2NVKQzDAfcivC2kjV mMfg== X-Gm-Message-State: AC+VfDyKaDIGqXIryykdVwy954DAAO5TLb2Td5wnVEpVUB/sq2xFgoLB kVM8+Wiui93JdLVUuEVs5WezR9XuW1Jdp+y7MqQ= X-Received: by 2002:a05:6a00:1a12:b0:64d:742f:f590 with SMTP id g18-20020a056a001a1200b0064d742ff590mr1119289pfv.8.1684890894268; Tue, 23 May 2023 18:14:54 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:c13a:d73:4f88:3654]) by smtp.gmail.com with ESMTPSA id d8-20020aa78688000000b005d72e54a7e1sm6271652pfo.215.2023.05.23.18.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 18:14:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL v2 26/28] qemu/atomic128: Add runtime test for FEAT_LSE2 Date: Tue, 23 May 2023 18:14:52 -0700 Message-Id: <20230524011452.807053-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230524011452.807053-1-richard.henderson@linaro.org> References: <20230524011452.807053-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.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=ham 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 With FEAT_LSE2, load and store of int128 is directly supported. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- host/include/aarch64/host/atomic128-ldst.h | 53 ++++++++++++++++------ 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/host/include/aarch64/host/atomic128-ldst.h b/host/include/aarch64/host/atomic128-ldst.h index 4b1360de39..a08f62c40a 100644 --- a/host/include/aarch64/host/atomic128-ldst.h +++ b/host/include/aarch64/host/atomic128-ldst.h @@ -11,27 +11,48 @@ #ifndef AARCH64_ATOMIC128_LDST_H #define AARCH64_ATOMIC128_LDST_H +#include "host/cpuinfo.h" +#include "tcg/debug-assert.h" + /* * Through gcc 10, aarch64 has no support for 128-bit atomics. * Through clang 16, without -march=armv8.4-a, __atomic_load_16 * is incorrectly expanded to a read-write operation. + * + * Anyway, this method allows runtime detection of FEAT_LSE2. */ -#define HAVE_ATOMIC128_RO 0 +#define HAVE_ATOMIC128_RO (cpuinfo & CPUINFO_LSE2) #define HAVE_ATOMIC128_RW 1 -Int128 QEMU_ERROR("unsupported atomic") atomic16_read_ro(const Int128 *ptr); +static inline Int128 atomic16_read_ro(const Int128 *ptr) +{ + uint64_t l, h; + + tcg_debug_assert(HAVE_ATOMIC128_RO); + /* With FEAT_LSE2, 16-byte aligned LDP is atomic. */ + asm("ldp %[l], %[h], %[mem]" + : [l] "=r"(l), [h] "=r"(h) : [mem] "m"(*ptr)); + + return int128_make128(l, h); +} static inline Int128 atomic16_read_rw(Int128 *ptr) { uint64_t l, h; uint32_t tmp; - /* The load must be paired with the store to guarantee not tearing. */ - asm("0: ldxp %[l], %[h], %[mem]\n\t" - "stxp %w[tmp], %[l], %[h], %[mem]\n\t" - "cbnz %w[tmp], 0b" - : [mem] "+m"(*ptr), [tmp] "=r"(tmp), [l] "=r"(l), [h] "=r"(h)); + if (cpuinfo & CPUINFO_LSE2) { + /* With FEAT_LSE2, 16-byte aligned LDP is atomic. */ + asm("ldp %[l], %[h], %[mem]" + : [l] "=r"(l), [h] "=r"(h) : [mem] "m"(*ptr)); + } else { + /* The load must be paired with the store to guarantee not tearing. */ + asm("0: ldxp %[l], %[h], %[mem]\n\t" + "stxp %w[tmp], %[l], %[h], %[mem]\n\t" + "cbnz %w[tmp], 0b" + : [mem] "+m"(*ptr), [tmp] "=&r"(tmp), [l] "=&r"(l), [h] "=&r"(h)); + } return int128_make128(l, h); } @@ -41,12 +62,18 @@ static inline void atomic16_set(Int128 *ptr, Int128 val) uint64_t l = int128_getlo(val), h = int128_gethi(val); uint64_t t1, t2; - /* Load into temporaries to acquire the exclusive access lock. */ - asm("0: ldxp %[t1], %[t2], %[mem]\n\t" - "stxp %w[t1], %[l], %[h], %[mem]\n\t" - "cbnz %w[t1], 0b" - : [mem] "+m"(*ptr), [t1] "=&r"(t1), [t2] "=&r"(t2) - : [l] "r"(l), [h] "r"(h)); + if (cpuinfo & CPUINFO_LSE2) { + /* With FEAT_LSE2, 16-byte aligned STP is atomic. */ + asm("stp %[l], %[h], %[mem]" + : [mem] "=m"(*ptr) : [l] "r"(l), [h] "r"(h)); + } else { + /* Load into temporaries to acquire the exclusive access lock. */ + asm("0: ldxp %[t1], %[t2], %[mem]\n\t" + "stxp %w[t1], %[l], %[h], %[mem]\n\t" + "cbnz %w[t1], 0b" + : [mem] "+m"(*ptr), [t1] "=&r"(t1), [t2] "=&r"(t2) + : [l] "r"(l), [h] "r"(h)); + } } #endif /* AARCH64_ATOMIC128_LDST_H */