/vendor/gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/gcc/s390.h

http://github.com/feyeleanor/RubyGoLightly · C++ Header · 63 lines · 21 code · 7 blank · 35 comment · 1 complexity · ad6b9ad0d2f8f7e3449ce98b49321456 MD5 · raw file

  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. /* FIXME: untested. */
  18. /* The relevant documentation appears to be at */
  19. /* http://publibz.boulder.ibm.com/epubs/pdf/dz9zr003.pdf */
  20. /* around page 5-96. Apparently: */
  21. /* - Memory references in general are atomic only for a single */
  22. /* byte. But it appears that the most common load/store */
  23. /* instructions also guarantee atomicity for aligned */
  24. /* operands of standard types. WE FOOLISHLY ASSUME that */
  25. /* compilers only generate those. If that turns out to be */
  26. /* wrong, we need inline assembly code for AO_load and */
  27. /* AO_store. */
  28. /* - A store followed by a load is unordered since the store */
  29. /* may be delayed. Otherwise everything is ordered. */
  30. /* - There is a hardware compare-and-swap (CS) instruction. */
  31. #include "ordered_except_wr.h"
  32. #include "all_aligned_atomic_load_store.h"
  33. #include "../test_and_set_t_is_ao_t.h"
  34. /* FIXME: Is there a way to do byte-sized test-and-set? */
  35. /* FIXME: AO_nop_full should probably be implemented directly. */
  36. /* It appears that certain BCR instructions have that effect. */
  37. /* Presumably they're cheaper than CS? */
  38. AO_INLINE AO_t AO_compare_and_swap_full(volatile AO_t *addr,
  39. AO_t old, AO_t new_val)
  40. {
  41. int retval;
  42. __asm__ __volatile__ (
  43. # ifndef __s390x__
  44. " cs %1,%2,0(%3)\n"
  45. # else
  46. " csg %1,%2,0(%3)\n"
  47. # endif
  48. " ipm %0\n"
  49. " srl %0,28\n"
  50. : "=&d" (retval), "+d" (old)
  51. : "d" (new_val), "a" (addr)
  52. : "cc", "memory");
  53. return retval == 0;
  54. }
  55. #define AO_HAVE_compare_and_swap_full
  56. /* FIXME: Add double-wide compare-and-swap for 32-bit executables. */