1570af302Sopenharmony_ci#define a_ll a_ll 2570af302Sopenharmony_cistatic inline int a_ll(volatile int *p) 3570af302Sopenharmony_ci{ 4570af302Sopenharmony_ci int v; 5570af302Sopenharmony_ci __asm__ __volatile__ ("lwarx %0, 0, %2" : "=r"(v) : "m"(*p), "r"(p)); 6570af302Sopenharmony_ci return v; 7570af302Sopenharmony_ci} 8570af302Sopenharmony_ci 9570af302Sopenharmony_ci#define a_sc a_sc 10570af302Sopenharmony_cistatic inline int a_sc(volatile int *p, int v) 11570af302Sopenharmony_ci{ 12570af302Sopenharmony_ci int r; 13570af302Sopenharmony_ci __asm__ __volatile__ ( 14570af302Sopenharmony_ci "stwcx. %2, 0, %3 ; mfcr %0" 15570af302Sopenharmony_ci : "=r"(r), "=m"(*p) : "r"(v), "r"(p) : "memory", "cc"); 16570af302Sopenharmony_ci return r & 0x20000000; /* "bit 2" of "cr0" (backwards bit order) */ 17570af302Sopenharmony_ci} 18570af302Sopenharmony_ci 19570af302Sopenharmony_ci#define a_barrier a_barrier 20570af302Sopenharmony_cistatic inline void a_barrier() 21570af302Sopenharmony_ci{ 22570af302Sopenharmony_ci __asm__ __volatile__ ("sync" : : : "memory"); 23570af302Sopenharmony_ci} 24570af302Sopenharmony_ci 25570af302Sopenharmony_ci#define a_pre_llsc a_barrier 26570af302Sopenharmony_ci 27570af302Sopenharmony_ci#define a_post_llsc a_post_llsc 28570af302Sopenharmony_cistatic inline void a_post_llsc() 29570af302Sopenharmony_ci{ 30570af302Sopenharmony_ci __asm__ __volatile__ ("isync" : : : "memory"); 31570af302Sopenharmony_ci} 32570af302Sopenharmony_ci 33570af302Sopenharmony_ci#define a_clz_32 a_clz_32 34570af302Sopenharmony_cistatic inline int a_clz_32(uint32_t x) 35570af302Sopenharmony_ci{ 36570af302Sopenharmony_ci __asm__ ("cntlzw %0, %1" : "=r"(x) : "r"(x)); 37570af302Sopenharmony_ci return x; 38570af302Sopenharmony_ci} 39