tcg-runtime.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. /* This file is compiled once, and thus we can't include the standard
  27. "exec/helper-proto.h", which has includes that are target specific. */
  28. #include "exec/helper-head.h"
  29. #define DEF_HELPER_FLAGS_2(name, flags, ret, t1, t2) \
  30. dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2));
  31. #include "tcg-runtime.h"
  32. /* 32-bit helpers */
  33. int32_t HELPER(div_i32)(int32_t arg1, int32_t arg2)
  34. {
  35. return arg1 / arg2;
  36. }
  37. int32_t HELPER(rem_i32)(int32_t arg1, int32_t arg2)
  38. {
  39. return arg1 % arg2;
  40. }
  41. uint32_t HELPER(divu_i32)(uint32_t arg1, uint32_t arg2)
  42. {
  43. return arg1 / arg2;
  44. }
  45. uint32_t HELPER(remu_i32)(uint32_t arg1, uint32_t arg2)
  46. {
  47. return arg1 % arg2;
  48. }
  49. /* 64-bit helpers */
  50. uint64_t HELPER(shl_i64)(uint64_t arg1, uint64_t arg2)
  51. {
  52. return arg1 << arg2;
  53. }
  54. uint64_t HELPER(shr_i64)(uint64_t arg1, uint64_t arg2)
  55. {
  56. return arg1 >> arg2;
  57. }
  58. int64_t HELPER(sar_i64)(int64_t arg1, int64_t arg2)
  59. {
  60. return arg1 >> arg2;
  61. }
  62. int64_t HELPER(div_i64)(int64_t arg1, int64_t arg2)
  63. {
  64. return arg1 / arg2;
  65. }
  66. int64_t HELPER(rem_i64)(int64_t arg1, int64_t arg2)
  67. {
  68. return arg1 % arg2;
  69. }
  70. uint64_t HELPER(divu_i64)(uint64_t arg1, uint64_t arg2)
  71. {
  72. return arg1 / arg2;
  73. }
  74. uint64_t HELPER(remu_i64)(uint64_t arg1, uint64_t arg2)
  75. {
  76. return arg1 % arg2;
  77. }
  78. uint64_t HELPER(muluh_i64)(uint64_t arg1, uint64_t arg2)
  79. {
  80. uint64_t l, h;
  81. mulu64(&l, &h, arg1, arg2);
  82. return h;
  83. }
  84. int64_t HELPER(mulsh_i64)(int64_t arg1, int64_t arg2)
  85. {
  86. uint64_t l, h;
  87. muls64(&l, &h, arg1, arg2);
  88. return h;
  89. }