despite lacking the semantic content that the asm accesses the
pointed-to object rather than just using its address as a value, the
mips asm was not actually broken. the asm blocks were declared
volatile, meaning that the compiler must treat them as having unknown
side effects.
however changing the asm to use memory constraints is desirable not
just from a semantic correctness and consistency standpoint, but also
produces better code. the compiler is able to use base/offset
addressing expressions for the atomic object's address rather than
having to load the address into a single register. this improves
access to global locks in static libc, and access to non-zero-offset
atomic fields in synchronization primitives, etc.
".set push\n"
".set mips2\n"
".set noreorder\n"
".set push\n"
".set mips2\n"
".set noreorder\n"
" bne %0, %3, 1f\n"
" addu %1, %4, $0\n"
" bne %0, %3, 1f\n"
" addu %1, %4, $0\n"
" beq %1, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
" beq %1, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
- : "=&r"(t), "=&r"(dummy) : "r"(p), "r"(t), "r"(s) : "memory" );
+ : "=&r"(t), "=&r"(dummy), "+m"(*p) : "r"(t), "r"(s) : "memory" );
".set push\n"
".set mips2\n"
".set noreorder\n"
".set push\n"
".set mips2\n"
".set noreorder\n"
" beq %1, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
" beq %1, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
- : "=&r"(old), "=&r"(dummy) : "r"(x), "r"(v) : "memory" );
+ : "=&r"(old), "=&r"(dummy), "+m"(*x) : "r"(v) : "memory" );
".set push\n"
".set mips2\n"
".set noreorder\n"
".set push\n"
".set mips2\n"
".set noreorder\n"
" beq %1, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
" beq %1, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
- : "=&r"(old), "=&r"(dummy) : "r"(x), "r"(v) : "memory" );
+ : "=&r"(old), "=&r"(dummy), "+m"(*x) : "r"(v) : "memory" );
".set push\n"
".set mips2\n"
".set noreorder\n"
".set push\n"
".set mips2\n"
".set noreorder\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
- : "=&r"(dummy) : "r"(x) : "memory" );
+ : "=&r"(dummy), "+m"(*x) : : "memory" );
}
static inline void a_dec(volatile int *x)
}
static inline void a_dec(volatile int *x)
".set push\n"
".set mips2\n"
".set noreorder\n"
".set push\n"
".set mips2\n"
".set noreorder\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
- : "=&r"(dummy) : "r"(x) : "memory" );
+ : "=&r"(dummy), "+m"(*x) : : "memory" );
}
static inline void a_store(volatile int *p, int x)
}
static inline void a_store(volatile int *p, int x)
".set push\n"
".set mips2\n"
".set noreorder\n"
".set push\n"
".set mips2\n"
".set noreorder\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
- : "=&r"(dummy) : "r"(p), "r"(x) : "memory" );
+ : "=&r"(dummy), "+m"(*p) : "r"(x) : "memory" );
}
static inline void a_spin()
}
static inline void a_spin()
".set push\n"
".set mips2\n"
".set noreorder\n"
".set push\n"
".set mips2\n"
".set noreorder\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
- : "=&r"(dummy) : "r"(p), "r"(v) : "memory" );
+ : "=&r"(dummy), "+m"(*p) : "r"(v) : "memory" );
}
static inline void a_or(volatile int *p, int v)
}
static inline void a_or(volatile int *p, int v)
".set push\n"
".set mips2\n"
".set noreorder\n"
".set push\n"
".set mips2\n"
".set noreorder\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
" beq %0, $0, 1b\n"
" nop\n"
"1: \n"
".set pop\n"
- : "=&r"(dummy) : "r"(p), "r"(v) : "memory" );
+ : "=&r"(dummy), "+m"(*p) : "r"(v) : "memory" );
}
static inline void a_or_l(volatile void *p, long v)
}
static inline void a_or_l(volatile void *p, long v)