Cross-Platform build scripts for audio plugins
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.2KB

  1. diff --git a/src/dbinc/atomic.h b/src/dbinc/atomic.h
  2. index 9f338dc..ac116e6 100644
  3. --- a/src/dbinc/atomic.h
  4. +++ b/src/dbinc/atomic.h
  5. @@ -140,6 +140,28 @@ typedef LONG volatile *interlocked_val;
  6. #endif
  7. #if defined(HAVE_ATOMIC_X86_GCC_ASSEMBLY)
  8. +#ifdef __aarch64__
  9. +/* generic */
  10. +#define atomic_inc(env, p) \
  11. + __atomic_add_fetch(&(p)->value, 1, __ATOMIC_SEQ_CST)
  12. +#define atomic_dec(env, p) \
  13. + __atomic_sub_fetch(&(p)->value, 1, __ATOMIC_SEQ_CST)
  14. +#define atomic_add(env, p, val) \
  15. + __atomic_add_fetch(&(p)->value, (val), __ATOMIC_SEQ_CST)
  16. +#define atomic_compare_exchange(env, p, oval, nval) \
  17. + __atomic_compare_exchange_int((p), (oval), (nval))
  18. +static inline int __atomic_compare_exchange_int(
  19. + db_atomic_t *p, atomic_value_t oldval, atomic_value_t newval)
  20. +{
  21. + atomic_value_t expected;
  22. + int ret;
  23. +
  24. + expected = oldval;
  25. + ret = __atomic_compare_exchange_n(&p->value, &expected,
  26. + newval, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
  27. + return (ret);
  28. +}
  29. +#else
  30. /* x86/x86_64 gcc */
  31. #define atomic_inc(env, p) __atomic_inc(p)
  32. #define atomic_dec(env, p) __atomic_dec(p)
  33. @@ -190,6 +212,7 @@ static inline int __atomic_compare_exchange_db(
  34. return (was == oldval);
  35. }
  36. #endif
  37. +#endif
  38. #else
  39. /*
  40. diff --git a/src/dbinc/mutex_int.h b/src/dbinc/mutex_int.h
  41. index a6e5751..0fdb7fa 100644
  42. --- a/src/dbinc/mutex_int.h
  43. +++ b/src/dbinc/mutex_int.h
  44. @@ -799,6 +799,21 @@ MUTEX_UNSET(tsl_t *tsl) {
  45. typedef volatile unsigned char tsl_t;
  46. #ifdef LOAD_ACTUAL_MUTEX_CODE
  47. +#ifdef __aarch64__
  48. +/* gcc/arm: 0 is clear, 1 is set. */
  49. +#define MUTEX_SET(tsl) ({ \
  50. + register tsl_t __r, __old; \
  51. + __asm__ volatile( \
  52. + "ldxr %w1, [%3]\n\t" \
  53. + "stxr %w0, %w2, [%3]\n\t" \
  54. + "orr %w0, %w0, %w1\n\t" \
  55. + "mvn %w0, %w0\n\t" \
  56. + : "=&r" (__r), "+r" (__old) \
  57. + : "r" (1), "r" (tsl) \
  58. + ); \
  59. + __r & 1; \
  60. +})
  61. +#else
  62. /* gcc/x86: 0 is clear, 1 is set. */
  63. #define MUTEX_SET(tsl) ({ \
  64. tsl_t __r; \
  65. @@ -809,8 +824,9 @@ typedef volatile unsigned char tsl_t;
  66. : "memory", "cc"); \
  67. !__r; /* return 1 on success, 0 on failure */ \
  68. })
  69. +#endif
  70. -#define MUTEX_UNSET(tsl) (*(tsl_t *)(tsl) = 0)
  71. +#define MUTEX_UNSET(tsl) (*(volatile tsl_t *)(tsl) = 0)
  72. #define MUTEX_INIT(tsl) (MUTEX_UNSET(tsl), 0)
  73. /*
  74. * We need to pass a valid address to generate the memory barrier
  75. @@ -821,9 +837,14 @@ typedef volatile unsigned char tsl_t;
  76. #define MUTEX_MEMBAR(addr) \
  77. ({ __asm__ volatile ("lock; addl $0, %0" ::"m" (addr): "memory"); 1; })
  78. #else
  79. +#ifdef __aarch64__
  80. +#define MUTEX_MEMBAR(x) \
  81. + ({ __asm__ volatile ("dsb sy"); })
  82. +#else
  83. #define MUTEX_MEMBAR(addr) \
  84. ({ __asm__ volatile ("mfence" ::: "memory"); 1; })
  85. #endif
  86. +#endif
  87. /*
  88. * From Intel's performance tuning documentation (and see SR #6975):
  89. @@ -834,9 +855,13 @@ typedef volatile unsigned char tsl_t;
  90. * instruction does not affect the correctness of programs on existing
  91. * platforms, and it improves performance on Pentium 4 processor platforms."
  92. */
  93. +#ifdef __aarch64__
  94. +#define MUTEX_PAUSE __asm__ volatile ("isb\n");
  95. +#else
  96. #define MUTEX_PAUSE __asm__ volatile ("rep; nop" : : );
  97. #endif
  98. #endif
  99. +#endif
  100. /* End of operating system & hardware architecture-specific definitions */