tcg-runtime.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Tiny Code Generator for QEMU
  3. *
  4. * Copyright (c) 2008 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "qemu/osdep.h"
  25. #include "qemu/host-utils.h"
  26. #include "cpu.h"
  27. #include "exec/helper-proto.h"
  28. #include "exec/cpu_ldst.h"
  29. #include "exec/exec-all.h"
  30. /* 32-bit helpers */
  31. int32_t HELPER(div_i32)(int32_t arg1, int32_t arg2)
  32. {
  33. return arg1 / arg2;
  34. }
  35. int32_t HELPER(rem_i32)(int32_t arg1, int32_t arg2)
  36. {
  37. return arg1 % arg2;
  38. }
  39. uint32_t HELPER(divu_i32)(uint32_t arg1, uint32_t arg2)
  40. {
  41. return arg1 / arg2;
  42. }
  43. uint32_t HELPER(remu_i32)(uint32_t arg1, uint32_t arg2)
  44. {
  45. return arg1 % arg2;
  46. }
  47. /* 64-bit helpers */
  48. uint64_t HELPER(shl_i64)(uint64_t arg1, uint64_t arg2)
  49. {
  50. return arg1 << arg2;
  51. }
  52. uint64_t HELPER(shr_i64)(uint64_t arg1, uint64_t arg2)
  53. {
  54. return arg1 >> arg2;
  55. }
  56. int64_t HELPER(sar_i64)(int64_t arg1, int64_t arg2)
  57. {
  58. return arg1 >> arg2;
  59. }
  60. int64_t HELPER(div_i64)(int64_t arg1, int64_t arg2)
  61. {
  62. return arg1 / arg2;
  63. }
  64. int64_t HELPER(rem_i64)(int64_t arg1, int64_t arg2)
  65. {
  66. return arg1 % arg2;
  67. }
  68. uint64_t HELPER(divu_i64)(uint64_t arg1, uint64_t arg2)
  69. {
  70. return arg1 / arg2;
  71. }
  72. uint64_t HELPER(remu_i64)(uint64_t arg1, uint64_t arg2)
  73. {
  74. return arg1 % arg2;
  75. }
  76. uint64_t HELPER(muluh_i64)(uint64_t arg1, uint64_t arg2)
  77. {
  78. uint64_t l, h;
  79. mulu64(&l, &h, arg1, arg2);
  80. return h;
  81. }
  82. int64_t HELPER(mulsh_i64)(int64_t arg1, int64_t arg2)
  83. {
  84. uint64_t l, h;
  85. muls64(&l, &h, arg1, arg2);
  86. return h;
  87. }
  88. uint32_t HELPER(clz_i32)(uint32_t arg, uint32_t zero_val)
  89. {
  90. return arg ? clz32(arg) : zero_val;
  91. }
  92. uint32_t HELPER(ctz_i32)(uint32_t arg, uint32_t zero_val)
  93. {
  94. return arg ? ctz32(arg) : zero_val;
  95. }
  96. uint64_t HELPER(clz_i64)(uint64_t arg, uint64_t zero_val)
  97. {
  98. return arg ? clz64(arg) : zero_val;
  99. }
  100. uint64_t HELPER(ctz_i64)(uint64_t arg, uint64_t zero_val)
  101. {
  102. return arg ? ctz64(arg) : zero_val;
  103. }
  104. uint32_t HELPER(clrsb_i32)(uint32_t arg)
  105. {
  106. return clrsb32(arg);
  107. }
  108. uint64_t HELPER(clrsb_i64)(uint64_t arg)
  109. {
  110. return clrsb64(arg);
  111. }
  112. uint32_t HELPER(ctpop_i32)(uint32_t arg)
  113. {
  114. return ctpop32(arg);
  115. }
  116. uint64_t HELPER(ctpop_i64)(uint64_t arg)
  117. {
  118. return ctpop64(arg);
  119. }
  120. void HELPER(exit_atomic)(CPUArchState *env)
  121. {
  122. cpu_loop_exit_atomic(ENV_GET_CPU(env), GETPC());
  123. }
  124. #ifndef CONFIG_SOFTMMU
  125. /* The softmmu versions of these helpers are in cputlb.c. */
  126. /* Do not allow unaligned operations to proceed. Return the host address. */
  127. static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
  128. int size, uintptr_t retaddr)
  129. {
  130. /* Enforce qemu required alignment. */
  131. if (unlikely(addr & (size - 1))) {
  132. cpu_loop_exit_atomic(ENV_GET_CPU(env), retaddr);
  133. }
  134. return g2h(addr);
  135. }
  136. /* Macro to call the above, with local variables from the use context. */
  137. #define ATOMIC_MMU_LOOKUP atomic_mmu_lookup(env, addr, DATA_SIZE, GETPC())
  138. #define ATOMIC_NAME(X) HELPER(glue(glue(atomic_ ## X, SUFFIX), END))
  139. #define EXTRA_ARGS
  140. #define DATA_SIZE 1
  141. #include "atomic_template.h"
  142. #define DATA_SIZE 2
  143. #include "atomic_template.h"
  144. #define DATA_SIZE 4
  145. #include "atomic_template.h"
  146. #ifdef CONFIG_ATOMIC64
  147. #define DATA_SIZE 8
  148. #include "atomic_template.h"
  149. #endif
  150. /* The following is only callable from other helpers, and matches up
  151. with the softmmu version. */
  152. #ifdef CONFIG_ATOMIC128
  153. #undef EXTRA_ARGS
  154. #undef ATOMIC_NAME
  155. #undef ATOMIC_MMU_LOOKUP
  156. #define EXTRA_ARGS , TCGMemOpIdx oi, uintptr_t retaddr
  157. #define ATOMIC_NAME(X) \
  158. HELPER(glue(glue(glue(atomic_ ## X, SUFFIX), END), _mmu))
  159. #define ATOMIC_MMU_LOOKUP atomic_mmu_lookup(env, addr, DATA_SIZE, retaddr)
  160. #define DATA_SIZE 16
  161. #include "atomic_template.h"
  162. #endif /* CONFIG_ATOMIC128 */
  163. #endif /* !CONFIG_SOFTMMU */