atomic.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef __CSKY_ATOMIC_H_
  2. #define __CSKY_ATOMIC_H_
  3. #include <stdint.h>
  4. #include <sysdep.h>
  5. typedef int8_t atomic8_t;
  6. typedef uint8_t uatomic8_t;
  7. typedef int_fast8_t atomic_fast8_t;
  8. typedef uint_fast8_t uatomic_fast8_t;
  9. typedef int16_t atomic16_t;
  10. typedef uint16_t uatomic16_t;
  11. typedef int_fast16_t atomic_fast16_t;
  12. typedef uint_fast16_t uatomic_fast16_t;
  13. typedef int32_t atomic32_t;
  14. typedef uint32_t uatomic32_t;
  15. typedef int_fast32_t atomic_fast32_t;
  16. typedef uint_fast32_t uatomic_fast32_t;
  17. typedef int64_t atomic64_t;
  18. typedef uint64_t uatomic64_t;
  19. typedef int_fast64_t atomic_fast64_t;
  20. typedef uint_fast64_t uatomic_fast64_t;
  21. typedef intptr_t atomicptr_t;
  22. typedef uintptr_t uatomicptr_t;
  23. typedef intmax_t atomic_max_t;
  24. typedef uintmax_t uatomic_max_t;
  25. # define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval) \
  26. (abort (), 0)
  27. # define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval) \
  28. (abort (), 0)
  29. # define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval) \
  30. ({ __typeof(mem) _mem = (mem); \
  31. __typeof(oldval) _oldval = oldval; \
  32. __typeof(newval) _newval = newval; \
  33. register __typeof(oldval) _a0 __asm__ ("a0") = _oldval; \
  34. register __typeof(newval) _a1 __asm__ ("a1") = _newval; \
  35. register __typeof(mem) _a2 __asm__ ("a2") = _mem; \
  36. __asm__ __volatile__ ("trap 2;" \
  37. : "+r" (_a0) : "r" (_a1) , "r" (_a2) \
  38. : "a3", "memory"); \
  39. _a0; })
  40. # define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval) \
  41. (abort (), 0)
  42. #define __arch_compare_and_exchange_val_8_int(mem, newval, oldval) \
  43. (abort (), 0)
  44. #define __arch_compare_and_exchange_val_16_int(mem, newval, oldval) \
  45. (abort (), 0)
  46. #define __arch_compare_and_exchange_val_32_int(mem, newval, oldval) \
  47. ({ __typeof (mem) _mem = (mem); \
  48. __typeof (*mem) __gret = *_mem; \
  49. unsigned int _tmp = 0; \
  50. __typeof (oldval) _oldval = oldval; \
  51. __typeof (newval) _newval = newval; \
  52. register __typeof (oldval) _a0 __asm__ ("a0") = _oldval; \
  53. register __typeof (newval) _a1 __asm__ ("a1") = _newval; \
  54. register __typeof (mem) _a2 __asm__ ("a2") = _mem; \
  55. __asm__ __volatile__ ("1:\n\t" \
  56. "ldw %1, (%4, 0x0)\n\t" \
  57. "cmpne %1, %0\n\t" \
  58. "bt 2f\n\t" \
  59. "mov %2, %0\n\t" \
  60. "trap 2\n\t" \
  61. "cmpnei %0, 0\n\t" \
  62. "mov %0, %2\n\t" \
  63. "bt 1b\n\t" \
  64. "2: \n\t" \
  65. :"+r" (_a0), "+r"(__gret), "+r" (_tmp) :"r" (_a1) , "r" (_a2) \
  66. : "a3", "memory"); \
  67. __gret; })
  68. # define __arch_compare_and_exchange_val_64_int(mem, newval, oldval) \
  69. (abort (), 0)
  70. # define atomic_compare_and_exchange_bool_acq(mem, new, old) \
  71. __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
  72. mem, new, old)
  73. # define atomic_compare_and_exchange_val_acq(mem, new, old) \
  74. __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
  75. mem, new, old)
  76. #endif