1
0

atomic_arch.h 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #define a_ll a_ll
  2. static inline int a_ll(volatile int *p)
  3. {
  4. int v;
  5. __asm__ __volatile__ (
  6. "ll %0, %1"
  7. : "=r"(v) : "m"(*p));
  8. return v;
  9. }
  10. #define a_sc a_sc
  11. static inline int a_sc(volatile int *p, int v)
  12. {
  13. int r;
  14. __asm__ __volatile__ (
  15. "sc %0, %1"
  16. : "=r"(r), "=m"(*p) : "0"(v) : "memory");
  17. return r;
  18. }
  19. #define a_ll_p a_ll_p
  20. static inline void *a_ll_p(volatile void *p)
  21. {
  22. void *v;
  23. __asm__ __volatile__ (
  24. "lld %0, %1"
  25. : "=r"(v) : "m"(*(void *volatile *)p));
  26. return v;
  27. }
  28. #define a_sc_p a_sc_p
  29. static inline int a_sc_p(volatile void *p, void *v)
  30. {
  31. long r;
  32. __asm__ __volatile__ (
  33. "scd %0, %1"
  34. : "=r"(r), "=m"(*(void *volatile *)p) : "0"(v) : "memory");
  35. return r;
  36. }
  37. #define a_barrier a_barrier
  38. static inline void a_barrier()
  39. {
  40. /* mips2 sync, but using too many directives causes
  41. * gcc not to inline it, so encode with .long instead. */
  42. __asm__ __volatile__ (".long 0xf" : : : "memory");
  43. }
  44. #define a_pre_llsc a_barrier
  45. #define a_post_llsc a_barrier