xref: /openbmc/linux/arch/x86/include/asm/rmwcc.h (revision 812f77b749a8ae11f58dacf0d3ed65e7ede47458)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_RMWcc
3 #define _ASM_X86_RMWcc
4 
5 #define __CLOBBERS_MEM		"memory"
6 #define __CLOBBERS_MEM_CC_CX	"memory", "cc", "cx"
7 
8 #if !defined(__GCC_ASM_FLAG_OUTPUTS__) && defined(CC_HAVE_ASM_GOTO)
9 
10 /* Use asm goto */
11 
12 #define __GEN_RMWcc(fullop, var, cc, clobbers, ...)			\
13 do {									\
14 	asm_volatile_goto (fullop "; j" #cc " %l[cc_label]"		\
15 			: : [counter] "m" (var), ## __VA_ARGS__		\
16 			: clobbers : cc_label);				\
17 	return 0;							\
18 cc_label:								\
19 	return 1;							\
20 } while (0)
21 
22 #define __BINARY_RMWcc_ARG	" %1, "
23 
24 
25 #else /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
26 
27 /* Use flags output or a set instruction */
28 
29 #define __GEN_RMWcc(fullop, var, cc, clobbers, ...)			\
30 do {									\
31 	bool c;								\
32 	asm volatile (fullop CC_SET(cc)					\
33 			: [counter] "+m" (var), CC_OUT(cc) (c)		\
34 			: __VA_ARGS__ : clobbers);			\
35 	return c;							\
36 } while (0)
37 
38 #define __BINARY_RMWcc_ARG	" %2, "
39 
40 #endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
41 
42 #define GEN_UNARY_RMWcc(op, var, arg0, cc)				\
43 	__GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM)
44 
45 #define GEN_UNARY_SUFFIXED_RMWcc(op, suffix, var, arg0, cc)		\
46 	__GEN_RMWcc(op " " arg0 "\n\t" suffix, var, cc,			\
47 		    __CLOBBERS_MEM_CC_CX)
48 
49 #define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc)			\
50 	__GEN_RMWcc(op __BINARY_RMWcc_ARG arg0, var, cc,		\
51 		    __CLOBBERS_MEM, vcon (val))
52 
53 #define GEN_BINARY_SUFFIXED_RMWcc(op, suffix, var, vcon, val, arg0, cc)	\
54 	__GEN_RMWcc(op __BINARY_RMWcc_ARG arg0 "\n\t" suffix, var, cc,	\
55 		    __CLOBBERS_MEM_CC_CX, vcon (val))
56 
57 #endif /* _ASM_X86_RMWcc */
58