2019-05-24 14:46:08 +00:00
|
|
|
#define a_barrier a_barrier
|
|
|
|
static inline void a_barrier()
|
|
|
|
{
|
|
|
|
__asm__ __volatile__ ("fence rw,rw" : : : "memory");
|
|
|
|
}
|
|
|
|
|
|
|
|
#define a_cas a_cas
|
|
|
|
static inline int a_cas(volatile int *p, int t, int s)
|
|
|
|
{
|
|
|
|
int old, tmp;
|
2019-07-17 22:53:26 +00:00
|
|
|
__asm__ __volatile__ (
|
2019-07-17 23:07:57 +00:00
|
|
|
"\n1: lr.w.aqrl %0, (%2)\n"
|
2019-05-24 14:46:08 +00:00
|
|
|
" bne %0, %3, 1f\n"
|
2019-07-17 23:07:57 +00:00
|
|
|
" sc.w.aqrl %1, %4, (%2)\n"
|
2019-05-24 14:46:08 +00:00
|
|
|
" bnez %1, 1b\n"
|
|
|
|
"1:"
|
2019-09-25 03:30:15 +00:00
|
|
|
: "=&r"(old), "=&r"(tmp)
|
2020-01-15 13:24:41 +00:00
|
|
|
: "r"(p), "r"((long)t), "r"((long)s)
|
2019-07-17 22:53:26 +00:00
|
|
|
: "memory");
|
2019-05-24 14:46:08 +00:00
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define a_cas_p a_cas_p
|
|
|
|
static inline void *a_cas_p(volatile void *p, void *t, void *s)
|
|
|
|
{
|
|
|
|
void *old;
|
|
|
|
int tmp;
|
2019-07-17 22:53:26 +00:00
|
|
|
__asm__ __volatile__ (
|
2019-07-17 23:07:57 +00:00
|
|
|
"\n1: lr.d.aqrl %0, (%2)\n"
|
2019-05-24 14:46:08 +00:00
|
|
|
" bne %0, %3, 1f\n"
|
2019-07-17 23:07:57 +00:00
|
|
|
" sc.d.aqrl %1, %4, (%2)\n"
|
2019-05-24 14:46:08 +00:00
|
|
|
" bnez %1, 1b\n"
|
|
|
|
"1:"
|
2019-09-25 03:30:15 +00:00
|
|
|
: "=&r"(old), "=&r"(tmp)
|
2019-07-17 23:07:57 +00:00
|
|
|
: "r"(p), "r"(t), "r"(s)
|
2019-07-17 22:53:26 +00:00
|
|
|
: "memory");
|
2019-05-24 14:46:08 +00:00
|
|
|
return old;
|
|
|
|
}
|