![H. Peter Anvin](/assets/img/avatar_default.png)
In checkin:
0c44c2d0f4
x86: Use asm goto to implement better modify_and_test() functions
the various functions which do modify and test were unified and
optimized using "asm goto". However, this change missed the detail
that the bitops require an "Ir" constraint rather than an "er"
constraint ("I" = integer constant from 0-31, "e" = signed 32-bit
integer constant). This would cause code to miscompile if these
functions were used on constant bit positions 32-255 and the build to
fail if used on constant bit positions above 255.
Add the constraints as a parameter to the GEN_BINARY_RMWcc() macro to
avoid this problem.
Reported-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/529E8719.4070202@zytor.com
42 lines
1 KiB
C
42 lines
1 KiB
C
#ifndef _ASM_X86_RMWcc
|
|
#define _ASM_X86_RMWcc
|
|
|
|
#ifdef CC_HAVE_ASM_GOTO
|
|
|
|
#define __GEN_RMWcc(fullop, var, cc, ...) \
|
|
do { \
|
|
asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
|
|
: : "m" (var), ## __VA_ARGS__ \
|
|
: "memory" : cc_label); \
|
|
return 0; \
|
|
cc_label: \
|
|
return 1; \
|
|
} while (0)
|
|
|
|
#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
|
|
__GEN_RMWcc(op " " arg0, var, cc)
|
|
|
|
#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
|
|
__GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
|
|
|
|
#else /* !CC_HAVE_ASM_GOTO */
|
|
|
|
#define __GEN_RMWcc(fullop, var, cc, ...) \
|
|
do { \
|
|
char c; \
|
|
asm volatile (fullop "; set" cc " %1" \
|
|
: "+m" (var), "=qm" (c) \
|
|
: __VA_ARGS__ : "memory"); \
|
|
return c != 0; \
|
|
} while (0)
|
|
|
|
#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
|
|
__GEN_RMWcc(op " " arg0, var, cc)
|
|
|
|
#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
|
|
__GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
|
|
|
|
#endif /* CC_HAVE_ASM_GOTO */
|
|
|
|
#endif /* _ASM_X86_RMWcc */
|