atomic.h 3.5 KB

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