futex_bits.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright (C) 2012-2015 Free Software Foundation, Inc.
  2. This file is part of the GNU Transactional Memory Library (libitm).
  3. Libitm is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
  8. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. Under Section 7 of GPL version 3, you are granted additional
  12. permissions described in the GCC Runtime Library Exception, version
  13. 3.1, as published by the Free Software Foundation.
  14. You should have received a copy of the GNU General Public License and
  15. a copy of the GCC Runtime Library Exception along with this program;
  16. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  17. <http://www.gnu.org/licenses/>. */
  18. #include <sys/syscall.h>
  19. static inline long
  20. sys_futex0 (std::atomic<int> *addr, int op, int val)
  21. {
  22. register long int g1 __asm__ ("g1");
  23. register long int o0 __asm__ ("o0");
  24. register long int o1 __asm__ ("o1");
  25. register long int o2 __asm__ ("o2");
  26. register long int o3 __asm__ ("o3");
  27. long res;
  28. g1 = SYS_futex;
  29. o0 = (long) addr;
  30. o1 = op;
  31. o2 = val;
  32. o3 = 0;
  33. #ifdef __arch64__
  34. __asm volatile ("ta 0x6d"
  35. #else
  36. __asm volatile ("ta 0x10"
  37. #endif
  38. : "=r"(g1), "=r"(o0)
  39. : "0"(g1), "1"(o0), "r"(o1), "r"(o2), "r"(o3)
  40. : "g2", "g3", "g4", "g5", "g6",
  41. "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
  42. "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
  43. "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
  44. "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
  45. "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
  46. "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
  47. "cc", "memory");
  48. res = o0;
  49. if (__builtin_expect ((unsigned long) res >= -515UL, 0))
  50. res =- res;
  51. return res;
  52. }