-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x86: Use asm goto to implement better modify_and_test() functions
Linus suggested using asm goto to get rid of the typical SETcc + TEST instruction pair -- which also clobbers an extra register -- for our typical modify_and_test() functions. Because asm goto doesn't allow output fields it has to include an unconditinal memory clobber when it changes a memory variable to force a reload. Luckily all atomic ops already imply a compiler barrier to go along with their memory barrier semantics. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/n/tip-0mtn9siwbeo1d33bap1422se@git.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
- Loading branch information
Peter Zijlstra
authored and
Ingo Molnar
committed
Sep 25, 2013
1 parent
4314895
commit 0c44c2d
Showing
5 changed files
with
58 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#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, val, arg0, cc) \ | ||
__GEN_RMWcc(op " %1, " arg0, var, cc, "er" (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, val, arg0, cc) \ | ||
__GEN_RMWcc(op " %2, " arg0, var, cc, "er" (val)) | ||
|
||
#endif /* CC_HAVE_ASM_GOTO */ | ||
|
||
#endif /* _ASM_X86_RMWcc */ |