Skip to contentSkip to conversation

riscv: lib: relax assembly constraints in hweight

PATCH Applied Qingfang Deng 3 participants 3 messages May 27, 2024 – Jul 16, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 riscv: lib: relax assembly constraints in hweight

From: Qingfang Deng <[email protected]>

rd and rs don't have to be the same. In some cases where rs needs to be saved for later usage, this will save us some mv instructions.

---
v2: updated title as suggested by Xiao.

 arch/riscv/include/asm/arch_hweight.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/riscv/include/asm/arch_hweight.h +4 -4
index 85b2c443823e..613769b9cdc9 100644
@@ -26,9 +26,9 @@ static __always_inline unsigned int __arch_hweight32(unsigned int w)
 
 	asm (".option push\n"
 	     ".option arch,+zbb\n"
-	     CPOPW "%0, %0\n"
+	     CPOPW "%0, %1\n"
 	     ".option pop\n"
-	     : "+r" (w) : :);
+	     : "=r" (w) : "r" (w) :);
 
 	return w;
 
@@ -57,9 +57,9 @@ static __always_inline unsigned long __arch_hweight64(__u64 w)
 
 	asm (".option push\n"
 	     ".option arch,+zbb\n"
-	     "cpop %0, %0\n"
+	     "cpop %0, %1\n"
 	     ".option pop\n"
-	     : "+r" (w) : :);
+	     : "=r" (w) : "r" (w) :);
 
 	return w;
 
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 56 lines

-----Original Message-----
From: Qingfang Deng <[email protected]>
Sent: Monday, May 27, 2024 5:24 PM
To: Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Albert Ou <[email protected]>; linux- [email protected]; [email protected]
Cc: Wang, Xiao W <[email protected]>; Qingfang Deng <[email protected]>
Subject: [PATCH v2] riscv: lib: relax assembly constraints in hweight

From: Qingfang Deng <[email protected]>

rd and rs don't have to be the same. In some cases where rs needs to be saved for later usage, this will save us some mv instructions.

---
v2: updated title as suggested by Xiao.

 arch/riscv/include/asm/arch_hweight.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/riscv/include/asm/arch_hweight.h +4 -5
index 85b2c443823e..613769b9cdc9 100644
@@ -26,9 +26,9 @@ static __always_inline unsigned int
 __arch_hweight32(unsigned int w)
 
 	asm (".option push\n"
 	     ".option arch,+zbb\n"
-	     CPOPW "%0, %0\n"
+	     CPOPW "%0, %1\n"
 	     ".option pop\n"
-	     : "+r" (w) : :);
+	     : "=r" (w) : "r" (w) :);
 
 	return w;
@@ -57,9 +57,9 @@ static __always_inline unsigned long
 __arch_hweight64(__u64 w)
 
 	asm (".option push\n"
 	     ".option arch,+zbb\n"
-	     "cpop %0, %0\n"
+	     "cpop %0, %1\n"
 	     ".option pop\n"
-	     : "+r" (w) : :);
+	     : "=r" (w) : "r" (w) :);
 
 	return w;
 
--
Quoted 1 line

2.34.1

#2 lore raw
In reply to Qingfang Deng
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 8 lines · On Mon, 27 May 2024 17:24:04 +0800 you wrote:

From: Qingfang Deng <[email protected]>

rd and rs don't have to be the same. In some cases where rs needs to be saved for later usage, this will save us some mv instructions.

[...]

Here is the summary with links:
- [v2] riscv: lib: relax assembly constraints in hweight

    https://git.kernel.org/riscv/c/93b63f68d00a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html