Skip to content

Commit c295bc3

Browse files
mmindpalmer-dabbelt
authored andcommitted
riscv: introduce nops and __nops macros for NOP sequences
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 f99a250 ("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>
1 parent f2906aa commit c295bc3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

arch/riscv/include/asm/asm.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,19 @@
6767
#error "Unexpected __SIZEOF_SHORT__"
6868
#endif
6969

70+
#ifdef __ASSEMBLY__
71+
72+
/* Common assembly source macros */
73+
74+
/*
75+
* NOP sequence
76+
*/
77+
.macro nops, num
78+
.rept \num
79+
nop
80+
.endr
81+
.endm
82+
83+
#endif /* __ASSEMBLY__ */
84+
7085
#endif /* _ASM_RISCV_ASM_H */

arch/riscv/include/asm/barrier.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef __ASSEMBLY__
1414

1515
#define nop() __asm__ __volatile__ ("nop")
16+
#define __nops(n) ".rept " #n "\nnop\n.endr\n"
17+
#define nops(n) __asm__ __volatile__ (__nops(n))
1618

1719
#define RISCV_FENCE(p, s) \
1820
__asm__ __volatile__ ("fence " #p "," #s : : : "memory")

0 commit comments

Comments
 (0)