0092-target-riscv-add-gen_shifti-and-gen_shiftiw-helper-f.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. From 0139ed25d8f0ebc592e8bd6fb78842e6e2b37be2 Mon Sep 17 00:00:00 2001
  2. From: Frank Chang <frank.chang@sifive.com>
  3. Date: Mon, 11 Jan 2021 23:31:49 +0800
  4. Subject: [PATCH 092/107] target/riscv: add gen_shifti() and gen_shiftiw()
  5. helper functions
  6. Add gen_shifti() and gen_shiftiw() helper functions to reuse the same
  7. interfaces for immediate shift instructions.
  8. Signed-off-by: Frank Chang <frank.chang@sifive.com>
  9. Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
  10. ---
  11. target/riscv/insn_trans/trans_rvi.c.inc | 54 ++-----------------------
  12. target/riscv/translate.c | 43 ++++++++++++++++++++
  13. 2 files changed, 47 insertions(+), 50 deletions(-)
  14. diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc
  15. index d04ca0394c..7b89420184 100644
  16. --- a/target/riscv/insn_trans/trans_rvi.c.inc
  17. +++ b/target/riscv/insn_trans/trans_rvi.c.inc
  18. @@ -261,54 +261,17 @@ static bool trans_andi(DisasContext *ctx, arg_andi *a)
  19. }
  20. static bool trans_slli(DisasContext *ctx, arg_slli *a)
  21. {
  22. - if (a->shamt >= TARGET_LONG_BITS) {
  23. - return false;
  24. - }
  25. -
  26. - if (a->rd != 0) {
  27. - TCGv t = tcg_temp_new();
  28. - gen_get_gpr(t, a->rs1);
  29. -
  30. - tcg_gen_shli_tl(t, t, a->shamt);
  31. -
  32. - gen_set_gpr(a->rd, t);
  33. - tcg_temp_free(t);
  34. - } /* NOP otherwise */
  35. - return true;
  36. + return gen_shifti(ctx, a, tcg_gen_shl_tl);
  37. }
  38. static bool trans_srli(DisasContext *ctx, arg_srli *a)
  39. {
  40. - if (a->shamt >= TARGET_LONG_BITS) {
  41. - return false;
  42. - }
  43. -
  44. - if (a->rd != 0) {
  45. - TCGv t = tcg_temp_new();
  46. - gen_get_gpr(t, a->rs1);
  47. -
  48. - tcg_gen_shri_tl(t, t, a->shamt);
  49. - gen_set_gpr(a->rd, t);
  50. - tcg_temp_free(t);
  51. - } /* NOP otherwise */
  52. - return true;
  53. + return gen_shifti(ctx, a, tcg_gen_shr_tl);
  54. }
  55. static bool trans_srai(DisasContext *ctx, arg_srai *a)
  56. {
  57. - if (a->shamt >= TARGET_LONG_BITS) {
  58. - return false;
  59. - }
  60. -
  61. - if (a->rd != 0) {
  62. - TCGv t = tcg_temp_new();
  63. - gen_get_gpr(t, a->rs1);
  64. -
  65. - tcg_gen_sari_tl(t, t, a->shamt);
  66. - gen_set_gpr(a->rd, t);
  67. - tcg_temp_free(t);
  68. - } /* NOP otherwise */
  69. - return true;
  70. + return gen_shifti(ctx, a, tcg_gen_sar_tl);
  71. }
  72. static bool trans_add(DisasContext *ctx, arg_add *a)
  73. @@ -369,16 +332,7 @@ static bool trans_addiw(DisasContext *ctx, arg_addiw *a)
  74. static bool trans_slliw(DisasContext *ctx, arg_slliw *a)
  75. {
  76. - TCGv source1;
  77. - source1 = tcg_temp_new();
  78. - gen_get_gpr(source1, a->rs1);
  79. -
  80. - tcg_gen_shli_tl(source1, source1, a->shamt);
  81. - tcg_gen_ext32s_tl(source1, source1);
  82. - gen_set_gpr(a->rd, source1);
  83. -
  84. - tcg_temp_free(source1);
  85. - return true;
  86. + return gen_shiftiw(ctx, a, tcg_gen_shl_tl);
  87. }
  88. static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
  89. diff --git a/target/riscv/translate.c b/target/riscv/translate.c
  90. index 0152deef67..a6e50f77d4 100644
  91. --- a/target/riscv/translate.c
  92. +++ b/target/riscv/translate.c
  93. @@ -709,6 +709,49 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)
  94. return cpu_ldl_code(env, pc);
  95. }
  96. +static bool gen_shifti(DisasContext *ctx, arg_shift *a,
  97. + void(*func)(TCGv, TCGv, TCGv))
  98. +{
  99. + if (a->shamt >= TARGET_LONG_BITS) {
  100. + return false;
  101. + }
  102. +
  103. + TCGv source1 = tcg_temp_new();
  104. + TCGv source2 = tcg_temp_new();
  105. +
  106. + gen_get_gpr(source1, a->rs1);
  107. +
  108. + tcg_gen_movi_tl(source2, a->shamt);
  109. + (*func)(source1, source1, source2);
  110. +
  111. + gen_set_gpr(a->rd, source1);
  112. + tcg_temp_free(source1);
  113. + tcg_temp_free(source2);
  114. + return true;
  115. +}
  116. +
  117. +#ifdef TARGET_RISCV64
  118. +
  119. +static bool gen_shiftiw(DisasContext *ctx, arg_shift *a,
  120. + void(*func)(TCGv, TCGv, TCGv))
  121. +{
  122. + TCGv source1 = tcg_temp_new();
  123. + TCGv source2 = tcg_temp_new();
  124. +
  125. + gen_get_gpr(source1, a->rs1);
  126. + tcg_gen_movi_tl(source2, a->shamt);
  127. +
  128. + (*func)(source1, source1, source2);
  129. + tcg_gen_ext32s_tl(source1, source1);
  130. +
  131. + gen_set_gpr(a->rd, source1);
  132. + tcg_temp_free(source1);
  133. + tcg_temp_free(source2);
  134. + return true;
  135. +}
  136. +
  137. +#endif
  138. +
  139. static void gen_ctz(TCGv ret, TCGv arg1)
  140. {
  141. tcg_gen_ctzi_tl(ret, arg1, TARGET_LONG_BITS);
  142. --
  143. 2.33.1