xref: /linux/tools/arch/x86/include/asm/rmwcc.h (revision b85d45947951d23cb22d90caecf4c1eb81342c96)
1 #ifndef _TOOLS_LINUX_ASM_X86_RMWcc
2 #define _TOOLS_LINUX_ASM_X86_RMWcc
3 
4 #ifdef CC_HAVE_ASM_GOTO
5 
6 #define __GEN_RMWcc(fullop, var, cc, ...)				\
7 do {									\
8 	asm_volatile_goto (fullop "; j" cc " %l[cc_label]"		\
9 			: : "m" (var), ## __VA_ARGS__ 			\
10 			: "memory" : cc_label);				\
11 	return 0;							\
12 cc_label:								\
13 	return 1;							\
14 } while (0)
15 
16 #define GEN_UNARY_RMWcc(op, var, arg0, cc) 				\
17 	__GEN_RMWcc(op " " arg0, var, cc)
18 
19 #define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc)			\
20 	__GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
21 
22 #else /* !CC_HAVE_ASM_GOTO */
23 
24 #define __GEN_RMWcc(fullop, var, cc, ...)				\
25 do {									\
26 	char c;								\
27 	asm volatile (fullop "; set" cc " %1"				\
28 			: "+m" (var), "=qm" (c)				\
29 			: __VA_ARGS__ : "memory");			\
30 	return c != 0;							\
31 } while (0)
32 
33 #define GEN_UNARY_RMWcc(op, var, arg0, cc)				\
34 	__GEN_RMWcc(op " " arg0, var, cc)
35 
36 #define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc)			\
37 	__GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
38 
39 #endif /* CC_HAVE_ASM_GOTO */
40 
41 #endif /* _TOOLS_LINUX_ASM_X86_RMWcc */
42