bitops-cas.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef __ASM_SH_BITOPS_CAS_H
  2. #define __ASM_SH_BITOPS_CAS_H
  3. static inline unsigned __bo_cas(volatile unsigned *p, unsigned old, unsigned new)
  4. {
  5. __asm__ __volatile__("cas.l %1,%0,@r0"
  6. : "+r"(new)
  7. : "r"(old), "z"(p)
  8. : "t", "memory" );
  9. return new;
  10. }
  11. static inline void set_bit(int nr, volatile void *addr)
  12. {
  13. unsigned mask, old;
  14. volatile unsigned *a = addr;
  15. a += nr >> 5;
  16. mask = 1U << (nr & 0x1f);
  17. do old = *a;
  18. while (__bo_cas(a, old, old|mask) != old);
  19. }
  20. static inline void clear_bit(int nr, volatile void *addr)
  21. {
  22. unsigned mask, old;
  23. volatile unsigned *a = addr;
  24. a += nr >> 5;
  25. mask = 1U << (nr & 0x1f);
  26. do old = *a;
  27. while (__bo_cas(a, old, old&~mask) != old);
  28. }
  29. static inline void change_bit(int nr, volatile void *addr)
  30. {
  31. unsigned mask, old;
  32. volatile unsigned *a = addr;
  33. a += nr >> 5;
  34. mask = 1U << (nr & 0x1f);
  35. do old = *a;
  36. while (__bo_cas(a, old, old^mask) != old);
  37. }
  38. static inline int test_and_set_bit(int nr, volatile void *addr)
  39. {
  40. unsigned mask, old;
  41. volatile unsigned *a = addr;
  42. a += nr >> 5;
  43. mask = 1U << (nr & 0x1f);
  44. do old = *a;
  45. while (__bo_cas(a, old, old|mask) != old);
  46. return !!(old & mask);
  47. }
  48. static inline int test_and_clear_bit(int nr, volatile void *addr)
  49. {
  50. unsigned mask, old;
  51. volatile unsigned *a = addr;
  52. a += nr >> 5;
  53. mask = 1U << (nr & 0x1f);
  54. do old = *a;
  55. while (__bo_cas(a, old, old&~mask) != old);
  56. return !!(old & mask);
  57. }
  58. static inline int test_and_change_bit(int nr, volatile void *addr)
  59. {
  60. unsigned mask, old;
  61. volatile unsigned *a = addr;
  62. a += nr >> 5;
  63. mask = 1U << (nr & 0x1f);
  64. do old = *a;
  65. while (__bo_cas(a, old, old^mask) != old);
  66. return !!(old & mask);
  67. }
  68. #include <asm-generic/bitops/non-atomic.h>
  69. #endif /* __ASM_SH_BITOPS_CAS_H */