Skip to content

Commit

Permalink
riscv: introduce nops and __nops macros for NOP sequences
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Palmer Dabbelt <[email protected]>
  • Loading branch information
mmind authored and palmer-dabbelt committed Jul 22, 2022
1 parent f2906aa commit c295bc3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions arch/riscv/include/asm/asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions arch/riscv/include/asm/barrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c295bc3

Please sign in to comment.