- Mark temp variable as "earlyclobber" in assembler inline in
atomic_fetchadd_32. Without it gcc would use it as input register for v and sometimes generate following code for function call like atomic_fetchadd_32(&(fp)->f_count, -1): 801238b4: 2402ffff li v0,-1 801238b8: c2230018 ll v1,24(s1) 801238bc: 00431021 addu v0,v0,v1 801238c0: e2220018 sc v0,24(s1) 801238c4: 1040fffc beqz v0,801238b8 <dupfdopen+0x2e8> 801238c8: 00000000 nop Which is definitly wrong because if sc fails v0 is set to 0 and previous value of -1 is overriden hence whole operation turns to bogus
This commit is contained in:
parent
1a28ce2dcb
commit
6846a68073
@ -294,7 +294,7 @@ atomic_fetchadd_32(__volatile uint32_t *p, uint32_t v)
|
||||
"addu %2, %3, %0\n\t" /* calculate new value */
|
||||
"sc %2, %1\n\t" /* attempt to store */
|
||||
"beqz %2, 1b\n\t" /* spin if failed */
|
||||
: "=&r" (value), "=m" (*p), "=r" (temp)
|
||||
: "=&r" (value), "=m" (*p), "=&r" (temp)
|
||||
: "r" (v), "m" (*p));
|
||||
return (value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user