From patchwork Tue Nov 7 02:48:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 741738 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1414485wrr; Mon, 6 Nov 2023 18:49:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZ5Yc1z1QUDiz6DyxjZk1pS/8yPUjdIyWKNsDHOVxpweBhKG2O07JUvPALS8c4Rlo5Uv3e X-Received: by 2002:ac8:5fc3:0:b0:41e:31bb:1e55 with SMTP id k3-20020ac85fc3000000b0041e31bb1e55mr37424455qta.61.1699325375357; Mon, 06 Nov 2023 18:49:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699325375; cv=none; d=google.com; s=arc-20160816; b=km6MXyZ85Cvkxzlsf8xvtCd4Lp/WPbOtryD17BQAfkDJIhWkQRP9hLngrKVsBmzPRx qlmKpsI3Vt6oK+kfLgNVHjNUZFAyb93nZFpoGartxbgck+T1u3RnFBN04EJkwv1fIfTy UE9QF0+5QYf6JvtEaMKfN4KbEdyT6vOSBZg4TO0lxzVHccy3ubPmEkb+tAsMW9cKHXIU K+1y3JYwvfmTOgu+VWD+V5ET5Xtdgr7Yj/7BvwgCVh8BEyrc7oHBG5+pUHoUQsoDyoJf DJV7EsQVpsrQABjZtjgokz1jtgVq63KQliFyXG2CfuMmiExbPZZprPsoD49Kcvcilrz7 gCcg== 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:to:from :dkim-signature; bh=vHLAwIo9k4CChF5auIiY+68A+lSlhRobpJGeh7zUX4I=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=SCOD7Xf7tvvy8gimZpeJ3zJbRctWCBxOy1sREYFIUUvKg77byG1fEF/j9Z0iaVFqR3 3l29c+hUkuEmLkmYAGxB443diXfQQdVuzMfhrA4LyLebxyaGbObIDSeJBYn1n+Ff/3is FMLDOb2f1wk3m4eOkLaRSgy1ow0ByJC/4mBVEFKuUfV1h6LwWLmH/WDHDh6pJsXsPr52 5fhexPsujKemyDA5Ybn+vc72+XOTHDSIZQm28rTX94O7JtUwzysULZv4HXpyeBzVvRGI fkeyVmjGUIPkaIZfB2+w0R1ViNj0gHRUXO+xF2/YJW7uRd7uVzwsH1pkfEyHhRjYNajs wfZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u36fQvJk; 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 h7-20020ac85e07000000b00419930eb09dsi6622876qtx.740.2023.11.06.18.49.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2023 18:49:35 -0800 (PST) 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=u36fQvJk; 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 1r0C9J-0008N6-U9; Mon, 06 Nov 2023 21:49:05 -0500 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 1r0C9H-0008KM-Tw for qemu-devel@nongnu.org; Mon, 06 Nov 2023 21:49:03 -0500 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r0C94-0005qC-AP for qemu-devel@nongnu.org; Mon, 06 Nov 2023 21:49:03 -0500 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6b5af4662b7so4252607b3a.3 for ; Mon, 06 Nov 2023 18:48:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699325329; x=1699930129; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=vHLAwIo9k4CChF5auIiY+68A+lSlhRobpJGeh7zUX4I=; b=u36fQvJkQezZC7ZrPhxhIBHAUJDGOwsXHt8C/fOJcqTHAOf6+GR9zCrzkhvqyJuJVC tmECJ1SbHQMCBE4Qr+dKEl2SRZDy/OcaaWscyKOOykqxdrX9rCQmfIlMTq4QxKx2zwFL IQ6wxYR5UaUQ27gmh9BVqBjmHqVR7ZwDXREwG7Y044eEjX1TFEAhpYoy5IZGQUUalovN 2NNc8Tu6dgoHYs33nz/R+DvKClareMpnEmOQ7g64SZZWWSusHLn9LeBbWvy7CkYpU6gS zoj7lYKqwBZrXsylxrBWC++mI18P5/q5pYXENMU8zcEgP4it2BdMJHyf7Bql7DUnldtA arVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699325329; x=1699930129; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vHLAwIo9k4CChF5auIiY+68A+lSlhRobpJGeh7zUX4I=; b=wdigAKmSf+RjXss40ojg9z63YFuFMem2EbueafaaQ6DybADoV1YTEEo5D5tuBNCyhh PplHOtV57Yrj5sg/9aUSnpQRNy/+Mdgl6EGOCfSWN23Uaprvcljezvi8kdoP8+TPgra7 YEQrqZQFhDKLhz7BpuiI6A+EjVxg5/CuR1yviNh27+XgLgg9mFqbDOHWI3bUuB2g5AVq G9x2qAaAAmCFCd44zlL/P8GmpWxrojIhvjOZ5Z8DyQ6JVZATz2ImsjNnKbKOtH66Vov1 /8o9JoENu2Qry5utcePd2dI0dbhuN2JL/WcpxBgKxrcvfzgrsmK/lZ7LI7Ic/faiVk9k narQ== X-Gm-Message-State: AOJu0YwWvJ9ng0ACJxIon76vtrdWw2TBsmjzCI31zCDKo4+Luy/ABJtC EN6s+V7tRIWz+7VnuUF5x9nlzO/ATCFLYXnQX/Y= X-Received: by 2002:a05:6a00:21c9:b0:68a:4103:9938 with SMTP id t9-20020a056a0021c900b0068a41039938mr28060198pfj.0.1699325328651; Mon, 06 Nov 2023 18:48:48 -0800 (PST) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fn11-20020a056a002fcb00b006bff7c36fb3sm6367478pfb.95.2023.11.06.18.48.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 18:48:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 06/35] host/include/loongarch64: Add atomic16 load and store Date: Mon, 6 Nov 2023 18:48:13 -0800 Message-Id: <20231107024842.7650-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231107024842.7650-1-richard.henderson@linaro.org> References: <20231107024842.7650-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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 While loongarch64 does not have a 128-bit cmpxchg, it does have 128-bit atomic load and store via the vector unit. Signed-off-by: Richard Henderson Message-Id: <20230916220151.526140-6-richard.henderson@linaro.org> --- .../include/loongarch64/host/atomic128-ldst.h | 52 +++++++++++++++++++ .../loongarch64/host/load-extract-al16-al8.h | 39 ++++++++++++++ .../loongarch64/host/store-insert-al16.h | 12 +++++ 3 files changed, 103 insertions(+) create mode 100644 host/include/loongarch64/host/atomic128-ldst.h create mode 100644 host/include/loongarch64/host/load-extract-al16-al8.h create mode 100644 host/include/loongarch64/host/store-insert-al16.h diff --git a/host/include/loongarch64/host/atomic128-ldst.h b/host/include/loongarch64/host/atomic128-ldst.h new file mode 100644 index 0000000000..9a4a8f8b9e --- /dev/null +++ b/host/include/loongarch64/host/atomic128-ldst.h @@ -0,0 +1,52 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Load/store for 128-bit atomic operations, LoongArch version. + * + * See docs/devel/atomics.rst for discussion about the guarantees each + * atomic primitive is meant to provide. + */ + +#ifndef LOONGARCH_ATOMIC128_LDST_H +#define LOONGARCH_ATOMIC128_LDST_H + +#include "host/cpuinfo.h" +#include "tcg/debug-assert.h" + +#define HAVE_ATOMIC128_RO likely(cpuinfo & CPUINFO_LSX) +#define HAVE_ATOMIC128_RW HAVE_ATOMIC128_RO + +/* + * As of gcc 13 and clang 16, there is no compiler support for LSX at all. + * Use inline assembly throughout. + */ + +static inline Int128 atomic16_read_ro(const Int128 *ptr) +{ + uint64_t l, h; + + tcg_debug_assert(HAVE_ATOMIC128_RO); + asm("vld $vr0, %2, 0\n\t" + "vpickve2gr.d %0, $vr0, 0\n\t" + "vpickve2gr.d %1, $vr0, 1" + : "=r"(l), "=r"(h) : "r"(ptr), "m"(*ptr) : "f0"); + + return int128_make128(l, h); +} + +static inline Int128 atomic16_read_rw(Int128 *ptr) +{ + return atomic16_read_ro(ptr); +} + +static inline void atomic16_set(Int128 *ptr, Int128 val) +{ + uint64_t l = int128_getlo(val), h = int128_gethi(val); + + tcg_debug_assert(HAVE_ATOMIC128_RW); + asm("vinsgr2vr.d $vr0, %1, 0\n\t" + "vinsgr2vr.d $vr0, %2, 1\n\t" + "vst $vr0, %3, 0" + : "=m"(*ptr) : "r"(l), "r"(h), "r"(ptr) : "f0"); +} + +#endif /* LOONGARCH_ATOMIC128_LDST_H */ diff --git a/host/include/loongarch64/host/load-extract-al16-al8.h b/host/include/loongarch64/host/load-extract-al16-al8.h new file mode 100644 index 0000000000..d1fb59d8af --- /dev/null +++ b/host/include/loongarch64/host/load-extract-al16-al8.h @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Atomic extract 64 from 128-bit, LoongArch version. + * + * Copyright (C) 2023 Linaro, Ltd. + */ + +#ifndef LOONGARCH_LOAD_EXTRACT_AL16_AL8_H +#define LOONGARCH_LOAD_EXTRACT_AL16_AL8_H + +#include "host/cpuinfo.h" +#include "tcg/debug-assert.h" + +/** + * load_atom_extract_al16_or_al8: + * @pv: host address + * @s: object size in bytes, @s <= 8. + * + * Load @s bytes from @pv, when pv % s != 0. If [p, p+s-1] does not + * cross an 16-byte boundary then the access must be 16-byte atomic, + * otherwise the access must be 8-byte atomic. + */ +static inline uint64_t load_atom_extract_al16_or_al8(void *pv, int s) +{ + uintptr_t pi = (uintptr_t)pv; + Int128 *ptr_align = (Int128 *)(pi & ~7); + int shr = (pi & 7) * 8; + uint64_t l, h; + + tcg_debug_assert(HAVE_ATOMIC128_RO); + asm("vld $vr0, %2, 0\n\t" + "vpickve2gr.d %0, $vr0, 0\n\t" + "vpickve2gr.d %1, $vr0, 1" + : "=r"(l), "=r"(h) : "r"(ptr_align), "m"(*ptr_align) : "f0"); + + return (l >> shr) | (h << (-shr & 63)); +} + +#endif /* LOONGARCH_LOAD_EXTRACT_AL16_AL8_H */ diff --git a/host/include/loongarch64/host/store-insert-al16.h b/host/include/loongarch64/host/store-insert-al16.h new file mode 100644 index 0000000000..919fd8d744 --- /dev/null +++ b/host/include/loongarch64/host/store-insert-al16.h @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Atomic store insert into 128-bit, LoongArch version. + */ + +#ifndef LOONGARCH_STORE_INSERT_AL16_H +#define LOONGARCH_STORE_INSERT_AL16_H + +void store_atom_insert_al16(Int128 *ps, Int128 val, Int128 msk) + QEMU_ERROR("unsupported atomic"); + +#endif /* LOONGARCH_STORE_INSERT_AL16_H */