[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] x86/asm: Use ASM_FLAG_OUT() to simplify atomic and bitop stubs



commit adc017b80b18af63de7da077ed3382acef1222ec
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Thu Feb 9 17:08:44 2017 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Wed Feb 15 17:18:15 2017 +0000

    x86/asm: Use ASM_FLAG_OUT() to simplify atomic and bitop stubs
    
    bitops.h cannot include asm_defns.h, because the static inlines in 
cpumasks.h
    result in forward declarations of the bitops.h contents.  Move 
ASM_FLAG_OUT()
    to a new asm/compiler.h to compensate.
    
    While making changes, switch bool_t to bool and use named asm parameters.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/include/asm-x86/asm_defns.h |  6 ---
 xen/include/asm-x86/atomic.h    | 64 ++++++++++++-------------------
 xen/include/asm-x86/bitops.h    | 85 ++++++++++++++---------------------------
 xen/include/xen/compiler.h      |  6 +++
 4 files changed, 58 insertions(+), 103 deletions(-)

diff --git a/xen/include/asm-x86/asm_defns.h b/xen/include/asm-x86/asm_defns.h
index 220ae2e..f1c6fa1 100644
--- a/xen/include/asm-x86/asm_defns.h
+++ b/xen/include/asm-x86/asm_defns.h
@@ -413,10 +413,4 @@ static always_inline void stac(void)
 #define REX64_PREFIX "rex64/"
 #endif
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-# define ASM_FLAG_OUT(yes, no) yes
-#else
-# define ASM_FLAG_OUT(yes, no) no
-#endif
-
 #endif /* __X86_ASM_DEFNS_H__ */
diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h
index ef7e70b..d2a311c 100644
--- a/xen/include/asm-x86/atomic.h
+++ b/xen/include/asm-x86/atomic.h
@@ -133,17 +133,13 @@ static inline int atomic_sub_return(int i, atomic_t *v)
 
 static inline int atomic_sub_and_test(int i, atomic_t *v)
 {
-    bool_t c;
-
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "lock; subl %2,%0"
-                   : "+m" (*(volatile int *)&v->counter), "=@ccz" (c)
-                   : "ir" (i) : "memory" );
-#else
-    asm volatile ( "lock; subl %2,%0; setz %1"
-                   : "+m" (*(volatile int *)&v->counter), "=qm" (c)
-                   : "ir" (i) : "memory" );
-#endif
+    bool c;
+
+    asm volatile ( "lock; subl %[i], %[counter]\n\t"
+                   ASM_FLAG_OUT(, "setz %[zf]\n\t")
+                   : [counter] "+m" (*(volatile int *)&v->counter),
+                     [zf] ASM_FLAG_OUT("=@ccz", "=qm") (c)
+                   : [i] "ir" (i) : "memory" );
 
     return c;
 }
@@ -163,17 +159,13 @@ static inline int atomic_inc_return(atomic_t *v)
 
 static inline int atomic_inc_and_test(atomic_t *v)
 {
-    bool_t c;
+    bool c;
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "lock; incl %0"
-                   : "+m" (*(volatile int *)&v->counter), "=@ccz" (c)
-                   :: "memory" );
-#else
-    asm volatile ( "lock; incl %0; setz %1"
-                   : "+m" (*(volatile int *)&v->counter), "=qm" (c)
+    asm volatile ( "lock; incl %[counter]\n\t"
+                   ASM_FLAG_OUT(, "setz %[zf]\n\t")
+                   : [counter] "+m" (*(volatile int *)&v->counter),
+                     [zf] ASM_FLAG_OUT("=@ccz", "=qm") (c)
                    :: "memory" );
-#endif
 
     return c;
 }
@@ -193,34 +185,26 @@ static inline int atomic_dec_return(atomic_t *v)
 
 static inline int atomic_dec_and_test(atomic_t *v)
 {
-    bool_t c;
+    bool c;
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "lock; decl %0"
-                   : "+m" (*(volatile int *)&v->counter), "=@ccz" (c)
+    asm volatile ( "lock; decl %[counter]\n\t"
+                   ASM_FLAG_OUT(, "setz %[zf]\n\t")
+                   : [counter] "+m" (*(volatile int *)&v->counter),
+                     [zf] ASM_FLAG_OUT("=@ccz", "=qm") (c)
                    :: "memory" );
-#else
-    asm volatile ( "lock; decl %0; setz %1"
-                   : "+m" (*(volatile int *)&v->counter), "=qm" (c)
-                   :: "memory" );
-#endif
 
     return c;
 }
 
 static inline int atomic_add_negative(int i, atomic_t *v)
 {
-    bool_t c;
-
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "lock; addl %2,%0"
-                   : "+m" (*(volatile int *)&v->counter), "=@ccs" (c)
-                   : "ir" (i) : "memory" );
-#else
-    asm volatile ( "lock; addl %2,%0; sets %1"
-                   : "+m" (*(volatile int *)&v->counter), "=qm" (c)
-                   : "ir" (i) : "memory" );
-#endif
+    bool c;
+
+    asm volatile ( "lock; addl %[i], %[counter]\n\t"
+                   ASM_FLAG_OUT(, "sets %[sf]\n\t")
+                   : [counter] "+m" (*(volatile int *)&v->counter),
+                     [sf] ASM_FLAG_OUT("=@ccs", "=qm") (c)
+                   : [i] "ir" (i) : "memory" );
 
     return c;
 }
diff --git a/xen/include/asm-x86/bitops.h b/xen/include/asm-x86/bitops.h
index 0f18645..440abb7 100644
--- a/xen/include/asm-x86/bitops.h
+++ b/xen/include/asm-x86/bitops.h
@@ -144,13 +144,10 @@ static inline int test_and_set_bit(int nr, volatile void 
*addr)
 {
     int oldbit;
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "lock; btsl %2,%1"
-                   : "=@ccc" (oldbit), "+m" (ADDR) : "Ir" (nr) : "memory" );
-#else
-    asm volatile ( "lock; btsl %2,%1\n\tsbbl %0,%0"
-                   : "=r" (oldbit), "+m" (ADDR) : "Ir" (nr) : "memory" );
-#endif
+    asm volatile ( "lock; btsl %[nr], %[addr]\n\t"
+                   ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t")
+                   : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit),
+                     [addr] "+m" (ADDR) : [nr] "Ir" (nr) : "memory" );
 
     return oldbit;
 }
@@ -172,15 +169,10 @@ static inline int __test_and_set_bit(int nr, void *addr)
 {
     int oldbit;
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "btsl %2,%1"
-                   : "=@ccc" (oldbit), "+m" (*(int *)addr)
-                   : "Ir" (nr) : "memory" );
-#else
-    asm volatile ( "btsl %2,%1\n\tsbbl %0,%0"
-                   : "=r" (oldbit), "+m" (*(int *)addr)
-                   : "Ir" (nr) : "memory" );
-#endif
+    asm volatile ( "btsl %[nr], %[addr]\n\t"
+                   ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t")
+                   : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit),
+                     [addr] "+m" (*(int *)addr) : [nr] "Ir" (nr) : "memory" );
 
     return oldbit;
 }
@@ -201,13 +193,10 @@ static inline int test_and_clear_bit(int nr, volatile 
void *addr)
 {
     int oldbit;
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "lock; btrl %2,%1"
-                   : "=@ccc" (oldbit), "+m" (ADDR) : "Ir" (nr) : "memory" );
-#else
-    asm volatile ( "lock; btrl %2,%1\n\tsbbl %0,%0"
-                   : "=r" (oldbit), "+m" (ADDR) : "Ir" (nr) : "memory" );
-#endif
+    asm volatile ( "lock; btrl %[nr], %[addr]\n\t"
+                   ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t")
+                   : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit),
+                     [addr] "+m" (ADDR) : [nr] "Ir" (nr) : "memory" );
 
     return oldbit;
 }
@@ -229,15 +218,10 @@ static inline int __test_and_clear_bit(int nr, void *addr)
 {
     int oldbit;
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "btrl %2,%1"
-                   : "=@ccc" (oldbit), "+m" (*(int *)addr)
-                   : "Ir" (nr) : "memory" );
-#else
-    asm volatile ( "btrl %2,%1\n\tsbbl %0,%0"
-                   : "=r" (oldbit), "+m" (*(int *)addr)
-                   : "Ir" (nr) : "memory" );
-#endif
+    asm volatile ( "btrl %[nr], %[addr]\n\t"
+                   ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t")
+                   : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit),
+                     [addr] "+m" (*(int *)addr) : [nr] "Ir" (nr) : "memory" );
 
     return oldbit;
 }
@@ -251,15 +235,10 @@ static inline int __test_and_change_bit(int nr, void 
*addr)
 {
     int oldbit;
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "btcl %2,%1"
-                   : "=@ccc" (oldbit), "+m" (*(int *)addr)
-                   : "Ir" (nr) : "memory" );
-#else
-    asm volatile ( "btcl %2,%1\n\tsbbl %0,%0"
-                   : "=r" (oldbit), "+m" (*(int *)addr)
-                   : "Ir" (nr) : "memory" );
-#endif
+    asm volatile ( "btcl %[nr], %[addr]\n\t"
+                   ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t")
+                   : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit),
+                     [addr] "+m" (*(int *)addr) : [nr] "Ir" (nr) : "memory" );
 
     return oldbit;
 }
@@ -280,13 +259,10 @@ static inline int test_and_change_bit(int nr, volatile 
void *addr)
 {
     int oldbit;
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "lock; btcl %2,%1"
-                   : "=@ccc" (oldbit), "+m" (ADDR) : "Ir" (nr) : "memory" );
-#else
-    asm volatile ( "lock; btcl %2,%1\n\tsbbl %0,%0"
-                   : "=r" (oldbit), "+m" (ADDR) : "Ir" (nr) : "memory" );
-#endif
+    asm volatile ( "lock; btcl %[nr], %[addr]\n\t"
+                   ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t")
+                   : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit),
+                     [addr] "+m" (ADDR) : [nr] "Ir" (nr) : "memory" );
 
     return oldbit;
 }
@@ -305,15 +281,10 @@ static inline int variable_test_bit(int nr, const 
volatile void *addr)
 {
     int oldbit;
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-    asm volatile ( "btl %2,%1"
-                   : "=@ccc" (oldbit)
-                   : "m" (CONST_ADDR), "Ir" (nr) : "memory" );
-#else
-    asm volatile ( "btl %2,%1\n\tsbbl %0,%0"
-                   : "=r" (oldbit)
-                   : "m" (CONST_ADDR), "Ir" (nr) : "memory" );
-#endif
+    asm volatile ( "btl %[nr], %[addr]\n\t"
+                   ASM_FLAG_OUT(, "sbbl %[old], %[old]\n\t")
+                   : [old] ASM_FLAG_OUT("=@ccc", "=r") (oldbit)
+                   : [addr] "m" (CONST_ADDR), [nr] "Ir" (nr) : "memory" );
 
     return oldbit;
 }
diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
index e800709..16aeeea 100644
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -94,4 +94,10 @@
     __asm__ ("" : "=r"(__ptr) : "0"(ptr));      \
     (typeof(ptr)) (__ptr + (off)); })
 
+#ifdef __GCC_ASM_FLAG_OUTPUTS__
+# define ASM_FLAG_OUT(yes, no) yes
+#else
+# define ASM_FLAG_OUT(yes, no) no
+#endif
+
 #endif /* __LINUX_COMPILER_H */
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.