Skip to content

Commit 466c7b2

Browse files
miguelinuxNagarathnam Muthusamy
authored andcommitted
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]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]> (cherry picked from commit 30c23f2) Orabug: 28900385 Signed-off-by: Nagarathnam Muthusamy <[email protected]> Reviewed-by: Darren Kenny <[email protected]>
1 parent cd27e3c commit 466c7b2

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

arch/x86/include/asm/rwsem.h

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@
6464
static inline void __down_read(struct rw_semaphore *sem)
6565
{
6666
asm volatile("# beginning down_read\n\t"
67-
LOCK_PREFIX _ASM_INC "(%1)\n\t"
67+
LOCK_PREFIX _ASM_INC "(%[sem])\n\t"
6868
/* adds 0x00000001 */
6969
" jns 1f\n"
7070
" call call_rwsem_down_read_failed\n"
7171
"1:\n\t"
7272
"# ending down_read\n\t"
7373
: "+m" (sem->count)
74-
: "a" (sem)
74+
: [sem] "a" (sem)
7575
: "memory", "cc");
7676
}
7777

@@ -82,17 +82,18 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem)
8282
{
8383
long result, tmp;
8484
asm volatile("# beginning __down_read_trylock\n\t"
85-
" mov %0,%1\n\t"
85+
" mov %[count],%[result]\n\t"
8686
"1:\n\t"
87-
" mov %1,%2\n\t"
88-
" add %3,%2\n\t"
87+
" mov %[result],%[tmp]\n\t"
88+
" add %[inc],%[tmp]\n\t"
8989
" jle 2f\n\t"
90-
LOCK_PREFIX " cmpxchg %2,%0\n\t"
90+
LOCK_PREFIX " cmpxchg %[tmp],%[count]\n\t"
9191
" jnz 1b\n\t"
9292
"2:\n\t"
9393
"# ending __down_read_trylock\n\t"
94-
: "+m" (sem->count), "=&a" (result), "=&r" (tmp)
95-
: "i" (RWSEM_ACTIVE_READ_BIAS)
94+
: [count] "+m" (sem->count), [result] "=&a" (result),
95+
[tmp] "=&r" (tmp)
96+
: [inc] "i" (RWSEM_ACTIVE_READ_BIAS)
9697
: "memory", "cc");
9798
return result >= 0;
9899
}
@@ -106,17 +107,17 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem)
106107
struct rw_semaphore* ret; \
107108
\
108109
asm volatile("# beginning down_write\n\t" \
109-
LOCK_PREFIX " xadd %1,(%4)\n\t" \
110+
LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t" \
110111
/* adds 0xffff0001, returns the old value */ \
111112
" test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t" \
112113
/* was the active mask 0 before? */\
113114
" jz 1f\n" \
114115
" call " slow_path "\n" \
115116
"1:\n" \
116117
"# ending down_write" \
117-
: "+m" (sem->count), "=d" (tmp), \
118+
: "+m" (sem->count), [tmp] "=d" (tmp), \
118119
"=a" (ret), ASM_CALL_CONSTRAINT \
119-
: "a" (sem), "1" (RWSEM_ACTIVE_WRITE_BIAS) \
120+
: [sem] "a" (sem), "[tmp]" (RWSEM_ACTIVE_WRITE_BIAS) \
120121
: "memory", "cc"); \
121122
ret; \
122123
})
@@ -142,21 +143,21 @@ static inline bool __down_write_trylock(struct rw_semaphore *sem)
142143
bool result;
143144
long tmp0, tmp1;
144145
asm volatile("# beginning __down_write_trylock\n\t"
145-
" mov %0,%1\n\t"
146+
" mov %[count],%[tmp0]\n\t"
146147
"1:\n\t"
147148
" test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
148149
/* was the active mask 0 before? */
149150
" jnz 2f\n\t"
150-
" mov %1,%2\n\t"
151-
" add %4,%2\n\t"
152-
LOCK_PREFIX " cmpxchg %2,%0\n\t"
151+
" mov %[tmp0],%[tmp1]\n\t"
152+
" add %[inc],%[tmp1]\n\t"
153+
LOCK_PREFIX " cmpxchg %[tmp1],%[count]\n\t"
153154
" jnz 1b\n\t"
154155
"2:\n\t"
155156
CC_SET(e)
156157
"# ending __down_write_trylock\n\t"
157-
: "+m" (sem->count), "=&a" (tmp0), "=&r" (tmp1),
158-
CC_OUT(e) (result)
159-
: "er" (RWSEM_ACTIVE_WRITE_BIAS)
158+
: [count] "+m" (sem->count), [tmp0] "=&a" (tmp0),
159+
[tmp1] "=&r" (tmp1), CC_OUT(e) (result)
160+
: [inc] "er" (RWSEM_ACTIVE_WRITE_BIAS)
160161
: "memory");
161162
return result;
162163
}
@@ -168,14 +169,14 @@ static inline void __up_read(struct rw_semaphore *sem)
168169
{
169170
long tmp;
170171
asm volatile("# beginning __up_read\n\t"
171-
LOCK_PREFIX " xadd %1,(%2)\n\t"
172+
LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t"
172173
/* subtracts 1, returns the old value */
173174
" jns 1f\n\t"
174175
" call call_rwsem_wake\n" /* expects old value in %edx */
175176
"1:\n"
176177
"# ending __up_read\n"
177-
: "+m" (sem->count), "=d" (tmp)
178-
: "a" (sem), "1" (-RWSEM_ACTIVE_READ_BIAS)
178+
: "+m" (sem->count), [tmp] "=d" (tmp)
179+
: [sem] "a" (sem), "[tmp]" (-RWSEM_ACTIVE_READ_BIAS)
179180
: "memory", "cc");
180181
}
181182

@@ -186,14 +187,14 @@ static inline void __up_write(struct rw_semaphore *sem)
186187
{
187188
long tmp;
188189
asm volatile("# beginning __up_write\n\t"
189-
LOCK_PREFIX " xadd %1,(%2)\n\t"
190+
LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t"
190191
/* subtracts 0xffff0001, returns the old value */
191192
" jns 1f\n\t"
192193
" call call_rwsem_wake\n" /* expects old value in %edx */
193194
"1:\n\t"
194195
"# ending __up_write\n"
195-
: "+m" (sem->count), "=d" (tmp)
196-
: "a" (sem), "1" (-RWSEM_ACTIVE_WRITE_BIAS)
196+
: "+m" (sem->count), [tmp] "=d" (tmp)
197+
: [sem] "a" (sem), "[tmp]" (-RWSEM_ACTIVE_WRITE_BIAS)
197198
: "memory", "cc");
198199
}
199200

@@ -203,7 +204,7 @@ static inline void __up_write(struct rw_semaphore *sem)
203204
static inline void __downgrade_write(struct rw_semaphore *sem)
204205
{
205206
asm volatile("# beginning __downgrade_write\n\t"
206-
LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
207+
LOCK_PREFIX _ASM_ADD "%[inc],(%[sem])\n\t"
207208
/*
208209
* transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
209210
* 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
@@ -213,7 +214,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
213214
"1:\n\t"
214215
"# ending __downgrade_write\n"
215216
: "+m" (sem->count)
216-
: "a" (sem), "er" (-RWSEM_WAITING_BIAS)
217+
: [sem] "a" (sem), [inc] "er" (-RWSEM_WAITING_BIAS)
217218
: "memory", "cc");
218219
}
219220

0 commit comments

Comments
 (0)