riscv: introduce nops and __nops macros for NOP sequences

A patch from »riscv: Add macro for multiple nop instructions« in state Mainline for linux-kernel

From: Heiko Stuebner <heiko@...> Date: Mon, 16 May 2022 23:48:56 +0200

Commit-Message

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@...>

Patch-Comment

arch/riscv/include/asm/asm.h | 15 +++++++++++++++ arch/riscv/include/asm/barrier.h | 2 ++ 2 files changed, 17 insertions(+)

Statistics

  • 17 lines added
  • 0 lines removed

Changes

------------------------- arch/riscv/include/asm/asm.h -------------------------
index 618d7c5af1a2..1b471ff73178 100644
@@ -67,4 +67,19 @@
#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 */
----------------------- arch/riscv/include/asm/barrier.h -----------------------
index d0e24aaa2aa0..110752594228 100644
@@ -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")
 
 

Recent Patches

About Us

Sed lacus. Donec lectus. Nullam pretium nibh ut turpis. Nam bibendum. In nulla tortor, elementum vel, tempor at, varius non, purus. Mauris vitae nisl nec metus placerat consectetuer.

Read More...