jack2 codebase
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.

78 lines
2.1KB

  1. /*
  2. Copyright (C) 2004-2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __JackAtomic_APPLE__
  16. #define __JackAtomic_APPLE__
  17. #include "JackTypes.h"
  18. #if defined(__ppc__) || defined(__ppc64__)
  19. static inline int CAS(register UInt32 value, register UInt32 newvalue, register volatile void* addr)
  20. {
  21. register int result;
  22. asm volatile (
  23. "# CAS \n"
  24. " lwarx r0, 0, %1 \n" // creates a reservation on addr
  25. " cmpw r0, %2 \n" // test value at addr
  26. " bne- 1f \n"
  27. " sync \n" // synchronize instructions
  28. " stwcx. %3, 0, %1 \n" // if the reservation is not altered
  29. // stores the new value at addr
  30. " bne- 1f \n"
  31. " li %0, 1 \n"
  32. " b 2f \n"
  33. "1: \n"
  34. " li %0, 0 \n"
  35. "2: \n"
  36. : "=r" (result)
  37. : "r" (addr), "r" (value), "r" (newvalue)
  38. : "r0"
  39. );
  40. return result;
  41. }
  42. #endif
  43. #if defined(__i386__) || defined(__x86_64__)
  44. #ifdef __SMP__
  45. # define LOCK "lock ; "
  46. #else
  47. # define LOCK ""
  48. #endif
  49. static inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void* addr)
  50. {
  51. register char ret;
  52. __asm__ __volatile__ (
  53. "# CAS \n\t"
  54. LOCK "cmpxchg %2, (%1) \n\t"
  55. "sete %0 \n\t"
  56. : "=a" (ret)
  57. : "c" (addr), "d" (newvalue), "a" (value)
  58. );
  59. return ret;
  60. }
  61. #endif
  62. #endif