1570af302Sopenharmony_ci#define a_barrier a_barrier 2570af302Sopenharmony_cistatic inline void a_barrier() 3570af302Sopenharmony_ci{ 4570af302Sopenharmony_ci __asm__ __volatile__ ("fence rw,rw" : : : "memory"); 5570af302Sopenharmony_ci} 6570af302Sopenharmony_ci 7570af302Sopenharmony_ci#define a_cas a_cas 8570af302Sopenharmony_cistatic inline int a_cas(volatile int *p, int t, int s) 9570af302Sopenharmony_ci{ 10570af302Sopenharmony_ci int old, tmp; 11570af302Sopenharmony_ci __asm__ __volatile__ ( 12570af302Sopenharmony_ci "\n1: lr.w.aqrl %0, (%2)\n" 13570af302Sopenharmony_ci " bne %0, %3, 1f\n" 14570af302Sopenharmony_ci " sc.w.aqrl %1, %4, (%2)\n" 15570af302Sopenharmony_ci " bnez %1, 1b\n" 16570af302Sopenharmony_ci "1:" 17570af302Sopenharmony_ci : "=&r"(old), "=&r"(tmp) 18570af302Sopenharmony_ci : "r"(p), "r"((long)t), "r"((long)s) 19570af302Sopenharmony_ci : "memory"); 20570af302Sopenharmony_ci return old; 21570af302Sopenharmony_ci} 22570af302Sopenharmony_ci 23570af302Sopenharmony_ci#define a_cas_p a_cas_p 24570af302Sopenharmony_cistatic inline void *a_cas_p(volatile void *p, void *t, void *s) 25570af302Sopenharmony_ci{ 26570af302Sopenharmony_ci void *old; 27570af302Sopenharmony_ci int tmp; 28570af302Sopenharmony_ci __asm__ __volatile__ ( 29570af302Sopenharmony_ci "\n1: lr.d.aqrl %0, (%2)\n" 30570af302Sopenharmony_ci " bne %0, %3, 1f\n" 31570af302Sopenharmony_ci " sc.d.aqrl %1, %4, (%2)\n" 32570af302Sopenharmony_ci " bnez %1, 1b\n" 33570af302Sopenharmony_ci "1:" 34570af302Sopenharmony_ci : "=&r"(old), "=&r"(tmp) 35570af302Sopenharmony_ci : "r"(p), "r"(t), "r"(s) 36570af302Sopenharmony_ci : "memory"); 37570af302Sopenharmony_ci return old; 38570af302Sopenharmony_ci} 39