atomic_arch.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #define a_cas a_cas
  2. static inline int a_cas(volatile int *p, int t, int s)
  3. {
  4. register int old, tmp;
  5. __asm__ __volatile__ (
  6. " addi %0, r0, 0\n"
  7. "1: lwx %0, %2, r0\n"
  8. " rsubk %1, %0, %3\n"
  9. " bnei %1, 1f\n"
  10. " swx %4, %2, r0\n"
  11. " addic %1, r0, 0\n"
  12. " bnei %1, 1b\n"
  13. "1: "
  14. : "=&r"(old), "=&r"(tmp)
  15. : "r"(p), "r"(t), "r"(s)
  16. : "cc", "memory" );
  17. return old;
  18. }
  19. #define a_swap a_swap
  20. static inline int a_swap(volatile int *x, int v)
  21. {
  22. register int old, tmp;
  23. __asm__ __volatile__ (
  24. " addi %0, r0, 0\n"
  25. "1: lwx %0, %2, r0\n"
  26. " swx %3, %2, r0\n"
  27. " addic %1, r0, 0\n"
  28. " bnei %1, 1b\n"
  29. "1: "
  30. : "=&r"(old), "=&r"(tmp)
  31. : "r"(x), "r"(v)
  32. : "cc", "memory" );
  33. return old;
  34. }
  35. #define a_fetch_add a_fetch_add
  36. static inline int a_fetch_add(volatile int *x, int v)
  37. {
  38. register int new, tmp;
  39. __asm__ __volatile__ (
  40. " addi %0, r0, 0\n"
  41. "1: lwx %0, %2, r0\n"
  42. " addk %0, %0, %3\n"
  43. " swx %0, %2, r0\n"
  44. " addic %1, r0, 0\n"
  45. " bnei %1, 1b\n"
  46. "1: "
  47. : "=&r"(new), "=&r"(tmp)
  48. : "r"(x), "r"(v)
  49. : "cc", "memory" );
  50. return new-v;
  51. }