public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jisheng Zhang <jszhang@kernel.org>
To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] arm64: runtime-const: save one instruction when ARM64_VA_BITS <= 48
Date: Wed, 25 Feb 2026 22:46:13 +0800	[thread overview]
Message-ID: <20260225144613.30846-1-jszhang@kernel.org> (raw)

Currently, the runtime_const_ptr() uses 4 instructions to move a long
imm to GP, but when ARM64_VA_BITS <= 48(which is true for android and
armbian), the top 8bits of runtime cont ptr is all '1', so we can make
use of the movn instruction to construct the imm's top 8bits and lower
16bits at the same time, thus save one instruction.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 arch/arm64/include/asm/runtime-const.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/arch/arm64/include/asm/runtime-const.h b/arch/arm64/include/asm/runtime-const.h
index be5915669d23..6797dd37d690 100644
--- a/arch/arm64/include/asm/runtime-const.h
+++ b/arch/arm64/include/asm/runtime-const.h
@@ -7,6 +7,8 @@
 /* Sigh. You can still run arm64 in BE mode */
 #include <asm/byteorder.h>
 
+#if CONFIG_ARM64_VA_BITS > 48
+
 #define runtime_const_ptr(sym) ({				\
 	typeof(sym) __ret;					\
 	asm_inline("1:\t"					\
@@ -20,6 +22,22 @@
 		:"=r" (__ret));					\
 	__ret; })
 
+#else
+
+#define runtime_const_ptr(sym) ({				\
+	typeof(sym) __ret;					\
+	asm_inline("1:\t"					\
+		"movn %0, #0x3210\n\t"				\
+		"movk %0, #0x89ab, lsl #16\n\t"			\
+		"movk %0, #0x4567, lsl #32\n\t"			\
+		".pushsection runtime_ptr_" #sym ",\"a\"\n\t"	\
+		".long 1b - .\n\t"				\
+		".popsection"					\
+		: "=r" (__ret));				\
+	__ret; })
+
+#endif
+
 #define runtime_const_shift_right_32(val, sym) ({		\
 	unsigned long __ret;					\
 	asm_inline("1:\t"					\
@@ -58,11 +76,19 @@ static inline void __runtime_fixup_caches(void *where, unsigned int insns)
 static inline void __runtime_fixup_ptr(void *where, unsigned long val)
 {
 	__le32 *p = lm_alias(where);
+#if CONFIG_ARM64_VA_BITS > 48
 	__runtime_fixup_16(p, val);
+#else
+	__runtime_fixup_16(p, ~val);
+#endif
 	__runtime_fixup_16(p+1, val >> 16);
 	__runtime_fixup_16(p+2, val >> 32);
+#if CONFIG_ARM64_VA_BITS > 48
 	__runtime_fixup_16(p+3, val >> 48);
 	__runtime_fixup_caches(where, 4);
+#else
+	__runtime_fixup_caches(where, 3);
+#endif
 }
 
 /* Immediate value is 6 bits starting at bit #16 */
-- 
2.51.0


             reply	other threads:[~2026-02-25 15:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 14:46 Jisheng Zhang [this message]
2026-02-27 16:34 ` [PATCH] arm64: runtime-const: save one instruction when ARM64_VA_BITS <= 48 Catalin Marinas
2026-03-02 16:08   ` Jisheng Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260225144613.30846-1-jszhang@kernel.org \
    --to=jszhang@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox