alpha.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
  3. * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
  4. * Copyright (c) 1999-2003 by Hewlett-Packard Company. All rights reserved.
  5. *
  6. *
  7. * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  8. * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
  9. *
  10. * Permission is hereby granted to use or copy this program
  11. * for any purpose, provided the above notices are retained on all copies.
  12. * Permission to modify the code and to distribute modified code is granted,
  13. * provided the above notices are retained, and a notice that the code was
  14. * modified is included with the above copyright notice.
  15. *
  16. */
  17. #include "../loadstore/atomic_load.h"
  18. #include "../loadstore/atomic_store.h"
  19. #include "../test_and_set_t_is_ao_t.h"
  20. #define AO_NO_DD_ORDERING
  21. /* Data dependence does not imply read ordering. */
  22. AO_INLINE void
  23. AO_nop_full(void)
  24. {
  25. __asm__ __volatile__("mb" : : : "memory");
  26. }
  27. #define AO_HAVE_nop_full
  28. AO_INLINE void
  29. AO_nop_write(void)
  30. {
  31. __asm__ __volatile__("wmb" : : : "memory");
  32. }
  33. #define AO_HAVE_nop_write
  34. /* mb should be used for AO_nop_read(). That's the default. */
  35. /* TODO: implement AO_fetch_and_add explicitly. */
  36. /* We believe that ldq_l ... stq_c does not imply any memory barrier. */
  37. AO_INLINE int
  38. AO_compare_and_swap(volatile AO_t *addr,
  39. AO_t old, AO_t new_val)
  40. {
  41. unsigned long was_equal;
  42. unsigned long temp;
  43. __asm__ __volatile__(
  44. "1: ldq_l %0,%1\n"
  45. " cmpeq %0,%4,%2\n"
  46. " mov %3,%0\n"
  47. " beq %2,2f\n"
  48. " stq_c %0,%1\n"
  49. " beq %0,1b\n"
  50. "2:\n"
  51. : "=&r" (temp), "+m" (*addr), "=&r" (was_equal)
  52. : "r" (new_val), "Ir" (old)
  53. :"memory");
  54. return (int)was_equal;
  55. }
  56. #define AO_HAVE_compare_and_swap
  57. /* TODO: implement AO_fetch_compare_and_swap */