From patchwork Tue Mar 11 04:08:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 14011111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6807C28B2E for ; Tue, 11 Mar 2025 04:12:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1trqxl-0005Rd-Al; Tue, 11 Mar 2025 00:11:29 -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 1trqvT-0003J9-2K for qemu-devel@nongnu.org; Tue, 11 Mar 2025 00:09:08 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1trqvO-0006PP-CH for qemu-devel@nongnu.org; Tue, 11 Mar 2025 00:09:05 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-225477548e1so45549665ad.0 for ; Mon, 10 Mar 2025 21:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741666139; x=1742270939; darn=nongnu.org; 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=p9XKPWEC1FDWwfXw4amuYrHiaWnSduBZ0xkgSDXw7jg=; b=Pp1t1nw0qvDhSrMhb9aSFJeSYS0LU4LsTCz1ZQZPgNUvo/aaJj8InVdA/OkXOCBLm2 QZthCfV8oHsqGocvb6En0Dj/FMsuxhytXbSSXGkhx8toEPqhfhyS6wpRGDQyDW/SG/Gq +AbvGDu3Y1xB2r3g5eB7VQYsKyoryNycQRTVDAr3kKTNqkIt2tUI5iygL8Sbem/5HoEG UM3ApLHFc0NbZ0ZgBtYPbxeJG5ZWbxPFdpSDpL6nQkFea6Y81AcGJuxN8fk+oOjI+3MG oP/imM5IGNevwk4lRmgi5uZ14zqgSzVeezoeC57cR69torE05tlDwmep+ZaImvZ2fVGW PRhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741666139; x=1742270939; 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=p9XKPWEC1FDWwfXw4amuYrHiaWnSduBZ0xkgSDXw7jg=; b=T2yXJtJhmQ5dpTrYxYXozyjmetiyiJQYLXEFIZkgY7UjdTvEXsOywVv/zQu18sg5IY bCrV4FvubNbhE1P9vpODSkJTztMAD85f4yLs4cip+hacEHMF9tmUkAnzZlr7uNPB109f F0o6Eu5Z/G0KoNJsacYGFaadkUjvUmb4QQhBQj/chVXCHjQ4CHG+lZiIwSpZK3veWHAQ YmMX2EWXYgWmhcInNNIYyODfc9altiDKOvXKdO6PZEch5roosriBdI6ubyhEqL/1jnhq joY3sPfxB6+FxIrCCKQ3FHYaiuq4w0G4ca5fC6W0i95C0dbDof/SyTirNJyC29tWkn5x WosQ== X-Gm-Message-State: AOJu0YwaGN0/c5MvWeF6Ff72pMlSDOqjMzaj4+FCvo6xGnvvzXh/Yh4N ILu9lPoEKHDHScHZNMpuO//jrfZWUkj4sItiWToM2L8lAZ0r3eV3Ei4XO71Q5MWybDjBKTsShJn 7tpM= X-Gm-Gg: ASbGncvdKeloC83Y45IQtIomqALFQ1KIEwXW5eSZOi/5+qgJpjpfbTHdIQEEDQlcFvx 4Y2MDH+JrgE5LNTByZSy4fRqD+0POCSxddMlEo6EcxF1p7Pmi7rpiN6geV0da1PUUHb2qAFWfKR 3GHsB4Nf3woDX9NEO8JUa6vK698Iga6EEYw4HNqYIdiiRPM6QJrFjLaQ3ucJqt2t4BEPUvEDc3f 7Gu468iYAdDAl7WxFypw3Q1d8F9ZJXqUzwBmhVVqnJ7dimx1u5HpqHy/R1AL0QzDiaOcnxEnMTK ds9F/vqjvJy4P992zH+w05h6EY4l1yhwGWGb1j/naVa4 X-Google-Smtp-Source: AGHT+IFULxKXKLSRt6Qs0nLWBVqgQyDOkjRhSbU6XrRQVwLJue3Ph3bi7X9tYlurUTD8KJTtNJkwJQ== X-Received: by 2002:a05:6a20:2d24:b0:1f5:7007:9eb7 with SMTP id adf61e73a8af0-1f57008366dmr14192716637.37.1741666139634; Mon, 10 Mar 2025 21:08:59 -0700 (PDT) Received: from pc.. ([38.39.164.180]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af28c0339cesm7324454a12.46.2025.03.10.21.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 21:08:59 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paul Durrant , Liu Zhiwei , David Hildenbrand , Weiwei Li , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org, Paolo Bonzini , Richard Henderson , Peter Xu , Nicholas Piggin , kvm@vger.kernel.org, qemu-ppc@nongnu.org, Alistair Francis , "Edgar E. Iglesias" , Stefano Stabellini , Harsh Prateek Bora , alex.bennee@linaro.org, qemu-riscv@nongnu.org, manos.pitsidianakis@linaro.org, Yoshinori Sato , Palmer Dabbelt , Daniel Henrique Barboza , Anthony PERARD , Pierrick Bouvier Subject: [PATCH v2 02/16] exec/tswap: implement {ld, st}.*_p as functions instead of macros Date: Mon, 10 Mar 2025 21:08:24 -0700 Message-Id: <20250311040838.3937136-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250311040838.3937136-1-pierrick.bouvier@linaro.org> References: <20250311040838.3937136-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x630.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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Defining functions allows to use them from common code, by not depending on TARGET_BIG_ENDIAN. Remove previous macros from exec/cpu-all.h. By moving them out of cpu-all.h, we'll be able to break dependency on cpu.h for memory related functions coming in next commits. Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- include/exec/cpu-all.h | 25 --------------- include/exec/tswap.h | 70 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 25 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 8cd6c00cf89..e56c064d46f 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -38,31 +38,6 @@ #define BSWAP_NEEDED #endif -/* Target-endianness CPU memory access functions. These fit into the - * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h. - */ -#if TARGET_BIG_ENDIAN -#define lduw_p(p) lduw_be_p(p) -#define ldsw_p(p) ldsw_be_p(p) -#define ldl_p(p) ldl_be_p(p) -#define ldq_p(p) ldq_be_p(p) -#define stw_p(p, v) stw_be_p(p, v) -#define stl_p(p, v) stl_be_p(p, v) -#define stq_p(p, v) stq_be_p(p, v) -#define ldn_p(p, sz) ldn_be_p(p, sz) -#define stn_p(p, sz, v) stn_be_p(p, sz, v) -#else -#define lduw_p(p) lduw_le_p(p) -#define ldsw_p(p) ldsw_le_p(p) -#define ldl_p(p) ldl_le_p(p) -#define ldq_p(p) ldq_le_p(p) -#define stw_p(p, v) stw_le_p(p, v) -#define stl_p(p, v) stl_le_p(p, v) -#define stq_p(p, v) stq_le_p(p, v) -#define ldn_p(p, sz) ldn_le_p(p, sz) -#define stn_p(p, sz, v) stn_le_p(p, sz, v) -#endif - /* MMU memory access macros */ #if !defined(CONFIG_USER_ONLY) diff --git a/include/exec/tswap.h b/include/exec/tswap.h index 2683da0adb7..84060a49994 100644 --- a/include/exec/tswap.h +++ b/include/exec/tswap.h @@ -80,4 +80,74 @@ static inline void tswap64s(uint64_t *s) } } +/* Return ld{word}_{le,be}_p following target endianness. */ +#define LOAD_IMPL(word, args...) \ +do { \ + if (target_words_bigendian()) { \ + return glue(glue(ld, word), _be_p)(args); \ + } else { \ + return glue(glue(ld, word), _le_p)(args); \ + } \ +} while (0) + +static inline int lduw_p(const void *ptr) +{ + LOAD_IMPL(uw, ptr); +} + +static inline int ldsw_p(const void *ptr) +{ + LOAD_IMPL(sw, ptr); +} + +static inline int ldl_p(const void *ptr) +{ + LOAD_IMPL(l, ptr); +} + +static inline uint64_t ldq_p(const void *ptr) +{ + LOAD_IMPL(q, ptr); +} + +static inline uint64_t ldn_p(const void *ptr, int sz) +{ + LOAD_IMPL(n, ptr, sz); +} + +#undef LOAD_IMPL + +/* Call st{word}_{le,be}_p following target endianness. */ +#define STORE_IMPL(word, args...) \ +do { \ + if (target_words_bigendian()) { \ + glue(glue(st, word), _be_p)(args); \ + } else { \ + glue(glue(st, word), _le_p)(args); \ + } \ +} while (0) + + +static inline void stw_p(void *ptr, uint16_t v) +{ + STORE_IMPL(w, ptr, v); +} + +static inline void stl_p(void *ptr, uint32_t v) +{ + STORE_IMPL(l, ptr, v); +} + +static inline void stq_p(void *ptr, uint64_t v) +{ + STORE_IMPL(q, ptr, v); +} + +static inline void stn_p(void *ptr, int sz, uint64_t v) +{ + STORE_IMPL(n, ptr, sz, v); +} + +#undef STORE_IMPL + #endif /* TSWAP_H */