On 28/10/23 21:45, Richard Henderson wrote:
Merge tcg_out_testi into tcg_out_cmp and adjust the two uses.

Signed-off-by: Richard Henderson <richard.hender...@linaro.org>
---
  tcg/i386/tcg-target.c.inc | 83 ++++++++++++++++++++++-----------------
  1 file changed, 47 insertions(+), 36 deletions(-)


  #if TCG_TARGET_REG_BITS == 64
@@ -1422,15 +1424,35 @@ static void tcg_out_jxx(TCGContext *s, int opc, 
TCGLabel *l, bool small)
  static int tcg_out_cmp(TCGContext *s, TCGCond cond, TCGArg arg1,
                         TCGArg arg2, int const_arg2, int rexw)
  {
-    if (const_arg2) {
-        if (arg2 == 0) {
-            /* test r, r */
-            tcg_out_modrm(s, OPC_TESTL + rexw, arg1, arg1);
+    if (is_tst_cond(cond)) {
+        if (!const_arg2) {
+            tcg_out_modrm(s, OPC_TESTL + rexw, arg1, arg2);
+        } else if (arg2 <= 0xff && (TCG_TARGET_REG_BITS == 64 || arg1 < 4)) {
+            tcg_out_modrm(s, OPC_GRP3_Eb | P_REXB_RM, EXT3_TESTi, arg1);
+            tcg_out8(s, arg2);
+        } else if ((arg2 & ~0xff00) == 0 && arg1 < 4) {
+            tcg_out_modrm(s, OPC_GRP3_Eb, EXT3_TESTi, arg1 + 4);
+            tcg_out8(s, arg2 >> 8);
          } else {

For this part, a double-review from x86 developer is welcomed,

-            tgen_arithi(s, ARITH_CMP + rexw, arg1, arg2, 0);
+            if (rexw) {
+                if (arg2 == (uint32_t)arg2) {
+                    rexw = 0;
+                } else {
+                    tcg_debug_assert(arg2 == (int32_t)arg2);
+                }
+            }
+            tcg_out_modrm(s, OPC_GRP3_Ev + rexw, EXT3_TESTi, arg1);
+            tcg_out32(s, arg2);
          }
      } else {

then the rest is OK.

Reviewed-by: Philippe Mathieu-Daudé <phi...@linaro.org>


Reply via email to