atomic_arch.h 767 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #define a_barrier a_barrier
  2. static inline void a_barrier()
  3. {
  4. __asm__ __volatile__ ("fence rw,rw" : : : "memory");
  5. }
  6. #define a_cas a_cas
  7. static inline int a_cas(volatile int *p, int t, int s)
  8. {
  9. int old, tmp;
  10. __asm__ __volatile__ (
  11. "\n1: lr.w.aqrl %0, (%2)\n"
  12. " bne %0, %3, 1f\n"
  13. " sc.w.aqrl %1, %4, (%2)\n"
  14. " bnez %1, 1b\n"
  15. "1:"
  16. : "=&r"(old), "=&r"(tmp)
  17. : "r"(p), "r"((long)t), "r"((long)s)
  18. : "memory");
  19. return old;
  20. }
  21. #define a_cas_p a_cas_p
  22. static inline void *a_cas_p(volatile void *p, void *t, void *s)
  23. {
  24. void *old;
  25. int tmp;
  26. __asm__ __volatile__ (
  27. "\n1: lr.d.aqrl %0, (%2)\n"
  28. " bne %0, %3, 1f\n"
  29. " sc.d.aqrl %1, %4, (%2)\n"
  30. " bnez %1, 1b\n"
  31. "1:"
  32. : "=&r"(old), "=&r"(tmp)
  33. : "r"(p), "r"(t), "r"(s)
  34. : "memory");
  35. return old;
  36. }