Skip to content

Commit 30c23f2

Browse files
miguelinuxIngo Molnar
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]>
1 parent 9cd6681 commit 30c23f2

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
@@ -63,14 +63,14 @@
6363
static inline void __down_read(struct rw_semaphore *sem)
6464
{
6565
asm volatile("# beginning down_read\n\t"
66-
LOCK_PREFIX _ASM_INC "(%1)\n\t"
66+
LOCK_PREFIX _ASM_INC "(%[sem])\n\t"
6767
/* adds 0x00000001 */
6868
" jns 1f\n"
6969
" call call_rwsem_down_read_failed\n"
7070
"1:\n\t"
7171
"# ending down_read\n\t"
7272
: "+m" (sem->count)
73-
: "a" (sem)
73+
: [sem] "a" (sem)
7474
: "memory", "cc");
7575
}
7676

@@ -81,17 +81,18 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem)
8181
{
8282
long result, tmp;
8383
asm volatile("# beginning __down_read_trylock\n\t"
84-
" mov %0,%1\n\t"
84+
" mov %[count],%[result]\n\t"
8585
"1:\n\t"
86-
" mov %1,%2\n\t"
87-
" add %3,%2\n\t"
86+
" mov %[result],%[tmp]\n\t"
87+
" add %[inc],%[tmp]\n\t"
8888
" jle 2f\n\t"
89-
LOCK_PREFIX " cmpxchg %2,%0\n\t"
89+
LOCK_PREFIX " cmpxchg %[tmp],%[count]\n\t"
9090
" jnz 1b\n\t"
9191
"2:\n\t"
9292
"# ending __down_read_trylock\n\t"
93-
: "+m" (sem->count), "=&a" (result), "=&r" (tmp)
94-
: "i" (RWSEM_ACTIVE_READ_BIAS)
93+
: [count] "+m" (sem->count), [result] "=&a" (result),
94+
[tmp] "=&r" (tmp)
95+
: [inc] "i" (RWSEM_ACTIVE_READ_BIAS)
9596
: "memory", "cc");
9697
return result >= 0;
9798
}
@@ -105,17 +106,17 @@ static inline bool __down_read_trylock(struct rw_semaphore *sem)
105106
struct rw_semaphore* ret; \
106107
\
107108
asm volatile("# beginning down_write\n\t" \
108-
LOCK_PREFIX " xadd %1,(%4)\n\t" \
109+
LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t" \
109110
/* adds 0xffff0001, returns the old value */ \
110111
" test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t" \
111112
/* was the active mask 0 before? */\
112113
" jz 1f\n" \
113114
" call " slow_path "\n" \
114115
"1:\n" \
115116
"# ending down_write" \
116-
: "+m" (sem->count), "=d" (tmp), \
117+
: "+m" (sem->count), [tmp] "=d" (tmp), \
117118
"=a" (ret), ASM_CALL_CONSTRAINT \
118-
: "a" (sem), "1" (RWSEM_ACTIVE_WRITE_BIAS) \
119+
: [sem] "a" (sem), "[tmp]" (RWSEM_ACTIVE_WRITE_BIAS) \
119120
: "memory", "cc"); \
120121
ret; \
121122
})
@@ -141,21 +142,21 @@ static inline bool __down_write_trylock(struct rw_semaphore *sem)
141142
bool result;
142143
long tmp0, tmp1;
143144
asm volatile("# beginning __down_write_trylock\n\t"
144-
" mov %0,%1\n\t"
145+
" mov %[count],%[tmp0]\n\t"
145146
"1:\n\t"
146147
" test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
147148
/* was the active mask 0 before? */
148149
" jnz 2f\n\t"
149-
" mov %1,%2\n\t"
150-
" add %4,%2\n\t"
151-
LOCK_PREFIX " cmpxchg %2,%0\n\t"
150+
" mov %[tmp0],%[tmp1]\n\t"
151+
" add %[inc],%[tmp1]\n\t"
152+
LOCK_PREFIX " cmpxchg %[tmp1],%[count]\n\t"
152153
" jnz 1b\n\t"
153154
"2:\n\t"
154155
CC_SET(e)
155156
"# ending __down_write_trylock\n\t"
156-
: "+m" (sem->count), "=&a" (tmp0), "=&r" (tmp1),
157-
CC_OUT(e) (result)
158-
: "er" (RWSEM_ACTIVE_WRITE_BIAS)
157+
: [count] "+m" (sem->count), [tmp0] "=&a" (tmp0),
158+
[tmp1] "=&r" (tmp1), CC_OUT(e) (result)
159+
: [inc] "er" (RWSEM_ACTIVE_WRITE_BIAS)
159160
: "memory");
160161
return result;
161162
}
@@ -167,14 +168,14 @@ static inline void __up_read(struct rw_semaphore *sem)
167168
{
168169
long tmp;
169170
asm volatile("# beginning __up_read\n\t"
170-
LOCK_PREFIX " xadd %1,(%2)\n\t"
171+
LOCK_PREFIX " xadd %[tmp],(%[sem])\n\t"
171172
/* subtracts 1, returns the old value */
172173
" jns 1f\n\t"
173174
" call call_rwsem_wake\n" /* expects old value in %edx */
174175
"1:\n"
175176
"# ending __up_read\n"
176-
: "+m" (sem->count), "=d" (tmp)
177-
: "a" (sem), "1" (-RWSEM_ACTIVE_READ_BIAS)
177+
: "+m" (sem->count), [tmp] "=d" (tmp)
178+
: [sem] "a" (sem), "[tmp]" (-RWSEM_ACTIVE_READ_BIAS)
178179
: "memory", "cc");
179180
}
180181

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

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

0 commit comments

Comments
 (0)