From patchwork Fri Mar 14 17:31: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: 14017222 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 86C6CC35FF1 for ; Fri, 14 Mar 2025 17:33:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tt8tb-0005qs-U2; Fri, 14 Mar 2025 13:32:32 -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 1tt8t0-0005TY-7P for qemu-devel@nongnu.org; Fri, 14 Mar 2025 13:31:55 -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 1tt8sw-0008D4-Ax for qemu-devel@nongnu.org; Fri, 14 Mar 2025 13:31:53 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-224341bbc1dso48125445ad.3 for ; Fri, 14 Mar 2025 10:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741973507; x=1742578307; 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=fjQjYNlvDIsMbe7+veFF5h4s6vvln32m8yANkT1fS5Y=; b=ZSei9wealOuhmjgEUMuaMnUnO2RiWDeRYTFal1jYsOf1AYycbqwFp1xgd0YxjIxyo1 3ZYsQ67116JgfloWttBxft8TO0YTISA9SnVfHWXitwsNPs7pkr8hmfJxXNaJTu+37YWb F7Q7XqKcJaru7yj2bCkupIjmm9H5AGLKDgmWVfZ14IpTBd6Uv4dA1PCUReoqTjBupHYc beRa9N0B26s3hJxiBLmUJuJZKchIcXT6qPbJisNBxOmYUF+FnH3SQUiv2Lc6OsMD/Bby fufKcLWtYSPEh1k0zAGdgDUQw9caJ6onfse2moeizHw75wQslYZHRx1RVzL8LgO4touq juLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973507; x=1742578307; 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=fjQjYNlvDIsMbe7+veFF5h4s6vvln32m8yANkT1fS5Y=; b=RP0hAZicwy0Vn1po0Eo2THNG9mRa+oYwxDl4VRW1HWjftqeFqSMeAHPBnqvcE5jclp 8kqFzoT1ImNqDkTkIeI6yLejOXVbtCu4G1vpFzOubPEJnY3U1lCnVOHDX2XAoxvqPMtm w0B4Pm/odVBWN/37SkTht/SDPK70WNSzl9BXFOohAGn9ouwGWANRLupOPN6SVjsNj+5I EMGgHVxkMFRIEj8g5SNSefStMYUfftsc+2Lzq5QxUr9Aq3Bv9/ZV2fHSCTkOt6tzqgCG gg99QRIGyWEMJ5361vk6tZPYrnbtidutAeHZjRBGJdw+qOahsF+/4BbvhCCOAtfLcW1W UtRA== X-Gm-Message-State: AOJu0Yz7491XDCB3cHqpT6ECI9X5LNOlNQcHtbfo7tG93E1D97jqRCJ9 AFOwJOQDywrR0TfA37qMOS3yn+t/6Cf6Qol3jjtLI24b41899aRemtolD5QHsLrm/Lh9upXQEvt ylkk= X-Gm-Gg: ASbGncuAjSWswTQ+1TNqDugQCf5slRbaycItLNDN+VuMcxU0bngp9tQUrnmqesn/ms3 zGb4VU25AFmA/7Y/KFuyn964IkUcXUfEQCTUcR047VAFD0fA+1OSVbepHRpHue80rqlfMLJXm1/ I//VAQ+UhPASBobcFhA3Tp4S3uuOBYoTeplkue2IvBoSThOPovYaQ+umi5hToGRPYfX7jM+xWk+ hnQxiVJdhPDdcjpGc7IzVEhAUUuWaKV35Bm149i0O/y/QgZegjY0D4xTRGn5JXHAeySA7DQJ02W 9hERJKH6gKGDLH757xuNsecpEUYq7ZlYpEpjilcjcUHG X-Google-Smtp-Source: AGHT+IG98FFUYfg0sUj6szpvN+iBBsyjmwTHoAxx0itmB7R9pQNc8XnfcIaBUehzGw+xAOY05im+Eg== X-Received: by 2002:a05:6a20:c106:b0:1f3:47e2:80b3 with SMTP id adf61e73a8af0-1f5c11c3cd2mr3981620637.20.1741973507092; Fri, 14 Mar 2025 10:31:47 -0700 (PDT) Received: from pc.. ([38.39.164.180]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-af56e9cd03bsm2990529a12.8.2025.03.14.10.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:31:46 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, Yoshinori Sato , Paul Durrant , Peter Xu , alex.bennee@linaro.org, Harsh Prateek Bora , David Hildenbrand , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Richard Henderson , "Edgar E. Iglesias" , Liu Zhiwei , Nicholas Piggin , Daniel Henrique Barboza , qemu-riscv@nongnu.org, manos.pitsidianakis@linaro.org, Palmer Dabbelt , Anthony PERARD , kvm@vger.kernel.org, xen-devel@lists.xenproject.org, Stefano Stabellini , Paolo Bonzini , Weiwei Li , Pierrick Bouvier Subject: [PATCH v5 02/17] exec/tswap: implement {ld, st}.*_p as functions instead of macros Date: Fri, 14 Mar 2025 10:31:24 -0700 Message-Id: <20250314173139.2122904-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250314173139.2122904-1-pierrick.bouvier@linaro.org> References: <20250314173139.2122904-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=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+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. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- 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 */