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_linux__
  16. #define __JackAtomic_linux__
  17. #include "JackTypes.h"
  18. #ifdef __PPC__
  19. static inline int CAS(register UInt32 value, register UInt32 newvalue, register volatile void* addr)
  20. {
  21. register int result;
  22. register UInt32 tmp;
  23. asm volatile (
  24. "# CAS \n"
  25. " lwarx %4, 0, %1 \n" // creates a reservation on addr
  26. " cmpw %4, %2 \n" // test value at addr
  27. " bne- 1f \n"
  28. " sync \n" // synchronize instructions
  29. " stwcx. %3, 0, %1 \n" // if the reservation is not altered
  30. // stores the new value at addr
  31. " bne- 1f \n"
  32. " li %0, 1 \n"
  33. " b 2f \n"
  34. "1: \n"
  35. " li %0, 0 \n"
  36. "2: \n"
  37. : "=r" (result)
  38. : "r" (addr), "r" (value), "r" (newvalue), "r" (tmp)
  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