mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-25 17:05:24 +07:00
288e4521f0
Currently the GEN_*_RMWcc() macros include a return statement, which pretty much mandates we directly wrap them in a (inline) function. Macros with return statements are tricky and, as per the above, limit use, so remove the return statement and make them statement-expressions. This allows them to be used more widely. Also, shuffle the arguments a bit. Place the @cc argument as 3rd, this makes it consistent between UNARY and BINARY, but more importantly, it makes the @arg0 argument last. Since the @arg0 argument is now last, we can do CPP trickery and make it an optional argument, simplifying the users; 17 out of 18 occurences do not need this argument. Finally, change to asm symbolic names, instead of the numeric ordering of operands, which allows us to get rid of __BINARY_RMWcc_ARG and get cleaner code overall. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: JBeulich@suse.com Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: bp@alien8.de Cc: hpa@linux.intel.com Link: https://lkml.kernel.org/r/20181003130957.108960094@infradead.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
71 lines
2.2 KiB
C
71 lines
2.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _ASM_X86_RMWcc
|
|
#define _ASM_X86_RMWcc
|
|
|
|
/* This counts to 12. Any more, it will return 13th argument. */
|
|
#define __RMWcc_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _n, X...) _n
|
|
#define RMWcc_ARGS(X...) __RMWcc_ARGS(, ##X, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
|
|
|
|
#define __RMWcc_CONCAT(a, b) a ## b
|
|
#define RMWcc_CONCAT(a, b) __RMWcc_CONCAT(a, b)
|
|
|
|
#define __CLOBBERS_MEM(clb...) "memory", ## clb
|
|
|
|
#if !defined(__GCC_ASM_FLAG_OUTPUTS__) && defined(CC_HAVE_ASM_GOTO)
|
|
|
|
/* Use asm goto */
|
|
|
|
#define __GEN_RMWcc(fullop, _var, cc, clobbers, ...) \
|
|
({ \
|
|
bool c = false; \
|
|
asm_volatile_goto (fullop "; j" #cc " %l[cc_label]" \
|
|
: : [var] "m" (_var), ## __VA_ARGS__ \
|
|
: clobbers : cc_label); \
|
|
if (0) { \
|
|
cc_label: c = true; \
|
|
} \
|
|
c; \
|
|
})
|
|
|
|
#else /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
|
|
|
|
/* Use flags output or a set instruction */
|
|
|
|
#define __GEN_RMWcc(fullop, _var, cc, clobbers, ...) \
|
|
({ \
|
|
bool c; \
|
|
asm volatile (fullop CC_SET(cc) \
|
|
: [var] "+m" (_var), CC_OUT(cc) (c) \
|
|
: __VA_ARGS__ : clobbers); \
|
|
c; \
|
|
})
|
|
|
|
#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
|
|
|
|
#define GEN_UNARY_RMWcc_4(op, var, cc, arg0) \
|
|
__GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM())
|
|
|
|
#define GEN_UNARY_RMWcc_3(op, var, cc) \
|
|
GEN_UNARY_RMWcc_4(op, var, cc, "%[var]")
|
|
|
|
#define GEN_UNARY_RMWcc(X...) RMWcc_CONCAT(GEN_UNARY_RMWcc_, RMWcc_ARGS(X))(X)
|
|
|
|
#define GEN_BINARY_RMWcc_6(op, var, cc, vcon, _val, arg0) \
|
|
__GEN_RMWcc(op " %[val], " arg0, var, cc, \
|
|
__CLOBBERS_MEM(), [val] vcon (_val))
|
|
|
|
#define GEN_BINARY_RMWcc_5(op, var, cc, vcon, val) \
|
|
GEN_BINARY_RMWcc_6(op, var, cc, vcon, val, "%[var]")
|
|
|
|
#define GEN_BINARY_RMWcc(X...) RMWcc_CONCAT(GEN_BINARY_RMWcc_, RMWcc_ARGS(X))(X)
|
|
|
|
#define GEN_UNARY_SUFFIXED_RMWcc(op, suffix, var, cc, clobbers...) \
|
|
__GEN_RMWcc(op " %[var]\n\t" suffix, var, cc, \
|
|
__CLOBBERS_MEM(clobbers))
|
|
|
|
#define GEN_BINARY_SUFFIXED_RMWcc(op, suffix, var, cc, vcon, _val, clobbers...)\
|
|
__GEN_RMWcc(op " %[val], %[var]\n\t" suffix, var, cc, \
|
|
__CLOBBERS_MEM(clobbers), [val] vcon (_val))
|
|
|
|
#endif /* _ASM_X86_RMWcc */
|