2013-09-11 20:19:24 +07:00
|
|
|
#ifndef _ASM_X86_RMWcc
|
|
|
|
#define _ASM_X86_RMWcc
|
|
|
|
|
2017-07-25 01:35:47 +07:00
|
|
|
#define __CLOBBERS_MEM "memory"
|
|
|
|
#define __CLOBBERS_MEM_CC_CX "memory", "cc", "cx"
|
|
|
|
|
2016-06-09 02:38:41 +07:00
|
|
|
#if !defined(__GCC_ASM_FLAG_OUTPUTS__) && defined(CC_HAVE_ASM_GOTO)
|
|
|
|
|
|
|
|
/* Use asm goto */
|
2013-09-11 20:19:24 +07:00
|
|
|
|
2017-07-25 01:35:47 +07:00
|
|
|
#define __GEN_RMWcc(fullop, var, cc, clobbers, ...) \
|
2013-09-11 20:19:24 +07:00
|
|
|
do { \
|
2016-06-09 02:38:39 +07:00
|
|
|
asm_volatile_goto (fullop "; j" #cc " %l[cc_label]" \
|
2017-07-25 01:35:47 +07:00
|
|
|
: : [counter] "m" (var), ## __VA_ARGS__ \
|
|
|
|
: clobbers : cc_label); \
|
2013-09-11 20:19:24 +07:00
|
|
|
return 0; \
|
|
|
|
cc_label: \
|
|
|
|
return 1; \
|
|
|
|
} while (0)
|
|
|
|
|
2017-07-25 01:35:47 +07:00
|
|
|
#define __BINARY_RMWcc_ARG " %1, "
|
2013-09-11 20:19:24 +07:00
|
|
|
|
|
|
|
|
2016-06-09 02:38:41 +07:00
|
|
|
#else /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
|
|
|
|
|
|
|
|
/* Use flags output or a set instruction */
|
2013-09-11 20:19:24 +07:00
|
|
|
|
2017-07-25 01:35:47 +07:00
|
|
|
#define __GEN_RMWcc(fullop, var, cc, clobbers, ...) \
|
2013-09-11 20:19:24 +07:00
|
|
|
do { \
|
2016-06-09 02:38:38 +07:00
|
|
|
bool c; \
|
2016-06-09 02:38:41 +07:00
|
|
|
asm volatile (fullop ";" CC_SET(cc) \
|
2017-07-25 01:35:47 +07:00
|
|
|
: [counter] "+m" (var), CC_OUT(cc) (c) \
|
|
|
|
: __VA_ARGS__ : clobbers); \
|
2016-06-09 02:38:38 +07:00
|
|
|
return c; \
|
2013-09-11 20:19:24 +07:00
|
|
|
} while (0)
|
|
|
|
|
2017-07-25 01:35:47 +07:00
|
|
|
#define __BINARY_RMWcc_ARG " %2, "
|
|
|
|
|
|
|
|
#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
|
|
|
|
|
2013-09-11 20:19:24 +07:00
|
|
|
#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
|
2017-07-25 01:35:47 +07:00
|
|
|
__GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM)
|
|
|
|
|
|
|
|
#define GEN_UNARY_SUFFIXED_RMWcc(op, suffix, var, arg0, cc) \
|
|
|
|
__GEN_RMWcc(op " " arg0 "\n\t" suffix, var, cc, \
|
|
|
|
__CLOBBERS_MEM_CC_CX)
|
2013-09-11 20:19:24 +07:00
|
|
|
|
2013-12-05 05:31:28 +07:00
|
|
|
#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
|
2017-07-25 01:35:47 +07:00
|
|
|
__GEN_RMWcc(op __BINARY_RMWcc_ARG arg0, var, cc, \
|
|
|
|
__CLOBBERS_MEM, vcon (val))
|
2013-09-11 20:19:24 +07:00
|
|
|
|
2017-07-25 01:35:47 +07:00
|
|
|
#define GEN_BINARY_SUFFIXED_RMWcc(op, suffix, var, vcon, val, arg0, cc) \
|
|
|
|
__GEN_RMWcc(op __BINARY_RMWcc_ARG arg0 "\n\t" suffix, var, cc, \
|
|
|
|
__CLOBBERS_MEM_CC_CX, vcon (val))
|
2013-09-11 20:19:24 +07:00
|
|
|
|
|
|
|
#endif /* _ASM_X86_RMWcc */
|