[PATCH] powerpc/64: Rewrite loading of AMR_KUAP_BLOCKED in assembly

Christophe Leroy christophe.leroy at csgroup.eu
Sat Feb 12 01:29:20 AEDT 2022


Constant loading of AMR_KUAP_BLOCKED takes 5 instructions:

	c000000000016a40:       4c 00 01 2c     isync
	c000000000016a44:       3d 20 fc ff     lis     r9,-769
	c000000000016a48:       61 29 ff ff     ori     r9,r9,65535
	c000000000016a4c:       79 29 07 c6     rldicr  r9,r9,32,31
	c000000000016a50:       65 29 ff ff     oris    r9,r9,65535
	c000000000016a54:       61 29 ff ff     ori     r9,r9,65535
	c000000000016a58:       7d 3d 03 a6     mtamr   r9
	c000000000016a5c:       4c 00 01 2c     isync

Until GCC is fixed, implement it in assembly using 2 instructions:

	c000000000016a50:       4c 00 01 2c     isync
	c000000000016a54:       39 20 fc ff     li      r9,-769
	c000000000016a58:       79 29 80 02     rotldi  r9,r9,48
	c000000000016a5c:       7d 3d 03 a6     mtamr   r9
	c000000000016a60:       4c 00 01 2c     isync

With this change a ppc64_defconfig build is reduced by 15 kbytes.

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94395
Signed-off-by: Christophe Leroy <christophe.leroy at csgroup.eu>
---
 arch/powerpc/include/asm/book3s/64/kup.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index 54cf46808157..35c017ba29e1 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -338,6 +338,10 @@ static __always_inline void set_kuap(unsigned long value)
 	 * before and after the move to AMR. See table 6 on page 1134.
 	 */
 	isync();
+
+	if (__builtin_constant_p(value) && value == 0xfcffffffffffffff)
+		asm("li %0, %1 ; rotldi %0, %0, 48" : "=r"(value) : "i"(0xfffffffffffffcff));
+
 	mtspr(SPRN_AMR, value);
 	isync();
 }
-- 
2.34.1



More information about the Linuxppc-dev mailing list