x86, asm: Use named operands in rwsem.h
PATCH 1/1 x86, asm: Use named operands in rwsem.h
Since GCC version 3.1, it is possible to specify input and output operands using symbolic names which can be referenced within the assembler code.
Convert to named operands makes easy to understand and maintain for future changes. This commit update operands in asm/rwsem.h.
Signed-off-by Miguel Bernal Marin <[email protected]>
--- arch/x86/include/asm/rwsem.h | 53 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 26 deletions(-)
arch/x86/include/asm/rwsem.h +27 -26
@@ -63,14 +63,14 @@static inline void __down_read (struct rw_semaphore *sem) { asmvolatile ("# beginning down_read\n\t" -LOCK_PREFIX _ASM_INC"(%1)\n\t" +LOCK_PREFIX _ASM_INC"(%[sem])\n\t" /* adds 0x00000001 */ " jns 1f\n" " call call_rwsem_down_read_failed\n" "1:\n\t" "# ending down_read\n\t" :"+m" (sem->count) - :"a" (sem) + : [sem]"a" (sem) :"memory" ,"cc" ); }
@@ -81,17 +81,18 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem) {long result, tmp; asmvolatile ("# beginning __down_read_trylock\n\t" -" mov %0,%1\n\t" +" mov %[count],%[result]\n\t" "1:\n\t" -" mov %1,%2\n\t" -" add %3,%2\n\t" +" mov %[result],%[tmp]\n\t" +" add %[inc],%[tmp]\n\t" " jle 2f\n\t" -LOCK_PREFIX " cmpxchg %2,%0\n\t" +LOCK_PREFIX " cmpxchg %[tmp],%[count]\n\t" " jnz 1b\n\t" "2:\n\t" "# ending __down_read_trylock\n\t" - :"+m" (sem->count),"=&a" (result),"=&r" (tmp) - :"i" (RWSEM_ACTIVE_READ_BIAS ) + : [count]"+m" (sem->count), [result]"=&a" (result), + [tmp]"=&r" (tmp) + : [inc]"i" (RWSEM_ACTIVE_READ_BIAS ) :"memory" ,"cc" );return result >=0 ; }
@@ -105,7 +106,7 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem)struct rw_semaphore * ret; \ \ asmvolatile ("# beginning down_write\n\t" \ -LOCK_PREFIX " xadd %1,(%4)\n\t" \ +LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t" \/* adds 0xffff0001, returns the old value */ \ " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t" \/* was the active mask 0 before? */\
@@ -113,9 +114,9 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem)" call " slow_path"\n" \"1:\n" \"# ending down_write" \ - : "+m" (sem->count), "=d" (tmp), \ + : "+m" (sem->count), [tmp] "=d" (tmp), \ "=a" (ret), ASM_CALL_CONSTRAINT \ - : "a" (sem), "1" (RWSEM_ACTIVE_WRITE_BIAS) \ + : [sem] "a" (sem), "[tmp]" (RWSEM_ACTIVE_WRITE_BIAS) \: " memory", " cc"); \ ret; \ })
@@ -141,21 +142,21 @@ static inline bool __down_write_trylock(struct rw_semaphore *sem)bool result;long tmp0, tmp1; asmvolatile ("# beginning __down_write_trylock\n\t" -" mov %0,%1\n\t" +" mov %[count],%[tmp0]\n\t" "1:\n\t" " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"/* was the active mask 0 before? */ " jnz 2f\n\t" -" mov %1,%2\n\t" -" add %4,%2\n\t" -LOCK_PREFIX " cmpxchg %2,%0\n\t" +" mov %[tmp0],%[tmp1]\n\t" +" add %[inc],%[tmp1]\n\t" +LOCK_PREFIX " cmpxchg %[tmp1],%[count]\n\t" " jnz 1b\n\t" "2:\n\t" CC_SET(e) "# ending __down_write_trylock\n\t" - : "+m" (sem->count), "=&a" (tmp0), "=&r" (tmp1), - CC_OUT(e) (result) - : "er" (RWSEM_ACTIVE_WRITE_BIAS) + : [count] "+m" (sem->count), [tmp0] "=&a" (tmp0), + [tmp1] "=&r" (tmp1), CC_OUT(e) (result) + : [inc] "er" (RWSEM_ACTIVE_WRITE_BIAS) : "memory"); return result; }
@@ -167,14 +168,14 @@ static inline void __up_read(struct rw_semaphore *sem) {long tmp; asmvolatile ("# beginning __up_read\n\t" -LOCK_PREFIX " xadd %1,(%2)\n\t" +LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t" /* subtracts 1, returns the old value */ " jns 1f\n\t" " call call_rwsem_wake\n" /* expects old value in %edx */ "1:\n" "# ending __up_read\n" - :"+m" (sem->count),"=d" (tmp) - :"a" (sem),"1" (-RWSEM_ACTIVE_READ_BIAS ) + :"+m" (sem->count), [tmp]"=d" (tmp) + : [sem]"a" (sem),"[tmp]" (-RWSEM_ACTIVE_READ_BIAS ) :"memory" ,"cc" ); }
@@ -185,14 +186,14 @@ static inline void __up_write(struct rw_semaphore *sem) {long tmp; asmvolatile ("# beginning __up_write\n\t" -LOCK_PREFIX " xadd %1,(%2)\n\t" +LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t" /* subtracts 0xffff0001, returns the old value */ " jns 1f\n\t" " call call_rwsem_wake\n" /* expects old value in %edx */ "1:\n\t" "# ending __up_write\n" - :"+m" (sem->count),"=d" (tmp) - :"a" (sem),"1" (-RWSEM_ACTIVE_WRITE_BIAS ) + :"+m" (sem->count), [tmp]"=d" (tmp) + : [sem]"a" (sem),"[tmp]" (-RWSEM_ACTIVE_WRITE_BIAS ) :"memory" ,"cc" ); }
@@ -202,7 +203,7 @@ static inline void __up_write(struct rw_semaphore *sem)static inline void __downgrade_write (struct rw_semaphore *sem) { asmvolatile ("# beginning __downgrade_write\n\t" -LOCK_PREFIX _ASM_ADD"%2,(%1)\n\t" +LOCK_PREFIX _ASM_ADD"%[inc],(%[sem])\n\t" /* * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386) * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
@@ -212,7 +213,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)"1:\n\t" "# ending __downgrade_write\n" : "+m" (sem->count) - : "a" (sem), "er" (-RWSEM_WAITING_BIAS) + : [sem] "a" (sem), [inc] "er" (-RWSEM_WAITING_BIAS) : "memory", "cc"); }
Signature · 1 line
2.14.1
tip-bot for Miguel Bernal Marin
merge bot[tip:locking/core] locking/x86: Use named operands in rwsem.h
locking/x86: Use named operands in rwsem.h
Commit-ID: 30c23f29d2d5e3ce8e24f7dec550b7e15142aaef Gitweb: https://git.kernel.org/tip/30c23f29d2d5e3ce8e24f7dec550b7e15142aaef Author: Miguel Bernal Marin <[email protected]> AuthorDate: Mon, 25 Sep 2017 18:03:49 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 28 Sep 2017 09:43:15 +0200
locking/x86: Use named operands in rwsem.h
Since GCC version 3.1 it is possible to specify input and output operands using symbolic names, which can be referenced within the assembler code.
Converting to named operands makes it easier to understand and maintain the code in the future.
Update operands in asm/rwsem.h accordingly.
Signed-off-by Miguel Bernal Marin <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Signed-off-by Ingo Molnar <[email protected]>
--- arch/x86/include/asm/rwsem.h | 53 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 26 deletions(-)
arch/x86/include/asm/rwsem.h +27 -26
@@ -63,14 +63,14 @@static inline void __down_read (struct rw_semaphore *sem) { asmvolatile ("# beginning down_read\n\t" -LOCK_PREFIX _ASM_INC"(%1)\n\t" +LOCK_PREFIX _ASM_INC"(%[sem])\n\t" /* adds 0x00000001 */ " jns 1f\n" " call call_rwsem_down_read_failed\n" "1:\n\t" "# ending down_read\n\t" :"+m" (sem->count) - :"a" (sem) + : [sem]"a" (sem) :"memory" ,"cc" ); }
@@ -81,17 +81,18 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem) {long result, tmp; asmvolatile ("# beginning __down_read_trylock\n\t" -" mov %0,%1\n\t" +" mov %[count],%[result]\n\t" "1:\n\t" -" mov %1,%2\n\t" -" add %3,%2\n\t" +" mov %[result],%[tmp]\n\t" +" add %[inc],%[tmp]\n\t" " jle 2f\n\t" -LOCK_PREFIX " cmpxchg %2,%0\n\t" +LOCK_PREFIX " cmpxchg %[tmp],%[count]\n\t" " jnz 1b\n\t" "2:\n\t" "# ending __down_read_trylock\n\t" - :"+m" (sem->count),"=&a" (result),"=&r" (tmp) - :"i" (RWSEM_ACTIVE_READ_BIAS ) + : [count]"+m" (sem->count), [result]"=&a" (result), + [tmp]"=&r" (tmp) + : [inc]"i" (RWSEM_ACTIVE_READ_BIAS ) :"memory" ,"cc" );return result >=0 ; }
@@ -105,7 +106,7 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem)struct rw_semaphore * ret; \ \ asmvolatile ("# beginning down_write\n\t" \ -LOCK_PREFIX " xadd %1,(%4)\n\t" \ +LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t" \/* adds 0xffff0001, returns the old value */ \ " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t" \/* was the active mask 0 before? */\
@@ -113,9 +114,9 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem)" call " slow_path"\n" \"1:\n" \"# ending down_write" \ - : "+m" (sem->count), "=d" (tmp), \ + : "+m" (sem->count), [tmp] "=d" (tmp), \ "=a" (ret), ASM_CALL_CONSTRAINT \ - : "a" (sem), "1" (RWSEM_ACTIVE_WRITE_BIAS) \ + : [sem] "a" (sem), "[tmp]" (RWSEM_ACTIVE_WRITE_BIAS) \: " memory", " cc"); \ ret; \ })
@@ -141,21 +142,21 @@ static inline bool __down_write_trylock(struct rw_semaphore *sem)bool result;long tmp0, tmp1; asmvolatile ("# beginning __down_write_trylock\n\t" -" mov %0,%1\n\t" +" mov %[count],%[tmp0]\n\t" "1:\n\t" " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"/* was the active mask 0 before? */ " jnz 2f\n\t" -" mov %1,%2\n\t" -" add %4,%2\n\t" -LOCK_PREFIX " cmpxchg %2,%0\n\t" +" mov %[tmp0],%[tmp1]\n\t" +" add %[inc],%[tmp1]\n\t" +LOCK_PREFIX " cmpxchg %[tmp1],%[count]\n\t" " jnz 1b\n\t" "2:\n\t" CC_SET(e) "# ending __down_write_trylock\n\t" - : "+m" (sem->count), "=&a" (tmp0), "=&r" (tmp1), - CC_OUT(e) (result) - : "er" (RWSEM_ACTIVE_WRITE_BIAS) + : [count] "+m" (sem->count), [tmp0] "=&a" (tmp0), + [tmp1] "=&r" (tmp1), CC_OUT(e) (result) + : [inc] "er" (RWSEM_ACTIVE_WRITE_BIAS) : "memory"); return result; }
@@ -167,14 +168,14 @@ static inline void __up_read(struct rw_semaphore *sem) {long tmp; asmvolatile ("# beginning __up_read\n\t" -LOCK_PREFIX " xadd %1,(%2)\n\t" +LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t" /* subtracts 1, returns the old value */ " jns 1f\n\t" " call call_rwsem_wake\n" /* expects old value in %edx */ "1:\n" "# ending __up_read\n" - :"+m" (sem->count),"=d" (tmp) - :"a" (sem),"1" (-RWSEM_ACTIVE_READ_BIAS ) + :"+m" (sem->count), [tmp]"=d" (tmp) + : [sem]"a" (sem),"[tmp]" (-RWSEM_ACTIVE_READ_BIAS ) :"memory" ,"cc" ); }
@@ -185,14 +186,14 @@ static inline void __up_write(struct rw_semaphore *sem) {long tmp; asmvolatile ("# beginning __up_write\n\t" -LOCK_PREFIX " xadd %1,(%2)\n\t" +LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t" /* subtracts 0xffff0001, returns the old value */ " jns 1f\n\t" " call call_rwsem_wake\n" /* expects old value in %edx */ "1:\n\t" "# ending __up_write\n" - :"+m" (sem->count),"=d" (tmp) - :"a" (sem),"1" (-RWSEM_ACTIVE_WRITE_BIAS ) + :"+m" (sem->count), [tmp]"=d" (tmp) + : [sem]"a" (sem),"[tmp]" (-RWSEM_ACTIVE_WRITE_BIAS ) :"memory" ,"cc" ); }
@@ -202,7 +203,7 @@ static inline void __up_write(struct rw_semaphore *sem)static inline void __downgrade_write (struct rw_semaphore *sem) { asmvolatile ("# beginning __downgrade_write\n\t" -LOCK_PREFIX _ASM_ADD"%2,(%1)\n\t" +LOCK_PREFIX _ASM_ADD"%[inc],(%[sem])\n\t" /* * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386) * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
@@ -212,7 +213,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)"1:\n\t" "# ending __downgrade_write\n" : "+m" (sem->count) - : "a" (sem), "er" (-RWSEM_WAITING_BIAS) + : [sem] "a" (sem), [inc] "er" (-RWSEM_WAITING_BIAS) : "memory", "cc"); }