riscv: introduce nops and __nops macros for NOP sequences
authorHeiko Stuebner <heiko@sntech.de>
Tue, 7 Jun 2022 14:30:58 +0000 (16:30 +0200)
committerPalmer Dabbelt <palmer@rivosinc.com>
Fri, 22 Jul 2022 00:17:29 +0000 (17:17 -0700)
NOP sequences tend to get used for padding out alternative sections

This change adds macros for generating these sequences as both inline
asm blocks, but also as strings suitable for embedding in other asm
blocks directly.

It essentially mimics similar functionality from arm64 introduced by
Wil Deacon in commit f99a250cb6a3 ("arm64: barriers: introduce nops
and __nops macros for NOP sequences").

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Link: https://lore.kernel.org/r/20220607143059.1054074-2-heiko@sntech.de
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/asm.h
arch/riscv/include/asm/barrier.h

index 618d7c5af1a2df39e54ef3565dedfa86bd0dc5c4..1b471ff731788608a1715f6f25796483a5077da0 100644 (file)
 #error "Unexpected __SIZEOF_SHORT__"
 #endif
 
+#ifdef __ASSEMBLY__
+
+/* Common assembly source macros */
+
+/*
+ * NOP sequence
+ */
+.macro nops, num
+       .rept   \num
+       nop
+       .endr
+.endm
+
+#endif /* __ASSEMBLY__ */
+
 #endif /* _ASM_RISCV_ASM_H */
index d0e24aaa2aa060499d338cbeae06a7e99352c7e5..110752594228e23125bd7a16b4c0469cbfcda4f5 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef __ASSEMBLY__
 
 #define nop()          __asm__ __volatile__ ("nop")
+#define __nops(n)      ".rept  " #n "\nnop\n.endr\n"
+#define nops(n)                __asm__ __volatile__ (__nops(n))
 
 #define RISCV_FENCE(p, s) \
        __asm__ __volatile__ ("fence " #p "," #s : : : "memory")