Skip to contentSkip to conversation

tcg/loongarch64: Fix cmp_vec with TCG_COND_NE

PATCH In review Richard Henderson 2 participants 4 messages Jun 23 – Jul 9

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg/loongarch64: Fix cmp_vec with TCG_COND_NE

For NE we need to invert EQ, not swap operands.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3589

---
 tcg/loongarch64/tcg-target.c.inc | 39 +++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 11 deletions(-)
tcg/loongarch64/tcg-target.c.inc +28 -11
index c3350c90fc..182dcfd5eb 100644
@@ -2371,19 +2371,36 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
                 default:
                     g_assert_not_reached();
                 }
-                break;
-            }
-
-            insn = cmp_vec_insn[cond][lasx][vece];
-            if (insn == 0) {
-                TCGArg t;
-                t = a1, a1 = a2, a2 = t;
-                cond = tcg_swap_cond(cond);
-                insn = cmp_vec_insn[cond][lasx][vece];
-                tcg_debug_assert(insn != 0);
+            } else {
+                switch (cond) {
+                case TCG_COND_EQ:
+                case TCG_COND_LE:
+                case TCG_COND_LEU:
+                case TCG_COND_LT:
+                case TCG_COND_LTU:
+                    insn = cmp_vec_insn[cond][lasx][vece];
+                    tcg_out32(s, encode_vdvjvk_insn(insn, a0, a1, a2));
+                    break;
+                case TCG_COND_GE:
+                case TCG_COND_GEU:
+                case TCG_COND_GT:
+                case TCG_COND_GTU:
+                    insn = cmp_vec_insn[tcg_swap_cond(cond)][lasx][vece];
+                    tcg_out32(s, encode_vdvjvk_insn(insn, a0, a2, a1));
+                    break;
+                case TCG_COND_NE:
+                    /* ne -> not(eq) */
+                    insn = cmp_vec_insn[TCG_COND_EQ][lasx][vece];
+                    tcg_out32(s, encode_vdvjvk_insn(insn, a0, a1, a2));
+                    insn = lasx ? OPC_XVNOR_V : OPC_VNOR_V;
+                    tcg_out32(s, encode_vdvjvk_insn(insn, a0, a0, a0));
+                    break;
+                default:
+                    g_assert_not_reached();
+                }
             }
         }
-        goto vdvjvk;
+        break;
     case INDEX_op_add_vec:
         tcg_out_addsub_vec(s, lasx, vece, a0, a1, a2, const_args[2], true);
         break;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 4 lines · Richard Henderson

For NE we need to invert EQ, not swap operands.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3589

This feels like a qemu-stable material.
I'm picking it up for the stable series,
please let me know if I should not.

Thanks,

/mjt

Quoted 52 lines
tcg/loongarch64/tcg-target.c.inc +28 -11
index c3350c90fc..182dcfd5eb 100644
@@ -2371,19 +2371,36 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
                  default:
                      g_assert_not_reached();
                  }
-                break;
-            }
-
-            insn = cmp_vec_insn[cond][lasx][vece];
-            if (insn == 0) {
-                TCGArg t;
-                t = a1, a1 = a2, a2 = t;
-                cond = tcg_swap_cond(cond);
-                insn = cmp_vec_insn[cond][lasx][vece];
-                tcg_debug_assert(insn != 0);
+            } else {
+                switch (cond) {
+                case TCG_COND_EQ:
+                case TCG_COND_LE:
+                case TCG_COND_LEU:
+                case TCG_COND_LT:
+                case TCG_COND_LTU:
+                    insn = cmp_vec_insn[cond][lasx][vece];
+                    tcg_out32(s, encode_vdvjvk_insn(insn, a0, a1, a2));
+                    break;
+                case TCG_COND_GE:
+                case TCG_COND_GEU:
+                case TCG_COND_GT:
+                case TCG_COND_GTU:
+                    insn = cmp_vec_insn[tcg_swap_cond(cond)][lasx][vece];
+                    tcg_out32(s, encode_vdvjvk_insn(insn, a0, a2, a1));
+                    break;
+                case TCG_COND_NE:
+                    /* ne -> not(eq) */
+                    insn = cmp_vec_insn[TCG_COND_EQ][lasx][vece];
+                    tcg_out32(s, encode_vdvjvk_insn(insn, a0, a1, a2));
+                    insn = lasx ? OPC_XVNOR_V : OPC_VNOR_V;
+                    tcg_out32(s, encode_vdvjvk_insn(insn, a0, a0, a0));
+                    break;
+                default:
+                    g_assert_not_reached();
+                }
              }
          }
-        goto vdvjvk;
+        break;
      case INDEX_op_add_vec:
          tcg_out_addsub_vec(s, lasx, vece, a0, a1, a2, const_args[2], true);
          break;
#2 lore raw
Quoted 9 lines · Michael Tokarev
Quoted 4 lines · Richard Henderson

For NE we need to invert EQ, not swap operands.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3589

This feels like a qemu-stable material.
I'm picking it up for the stable series,
please let me know if I should not.

And for 10.0.x "LTS" series, I'm also picking up 2 extra commits:

a079836005 tcg/loongarch64: Fix vec_val computation in tcg_target_const_match 911f7328e9 tcg/loongarch64: Improve constraints for TCG_CT_CONST_VCMP

which looks like an improvement too :)

Again, please let me know if I should not.

Thanks,

/mjt

#3 lore raw
Quoted 11 lines · Michael Tokarev
Quoted 9 lines · Michael Tokarev
Quoted 4 lines · Richard Henderson

For NE we need to invert EQ, not swap operands.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3589

This feels like a qemu-stable material.
I'm picking it up for the stable series,
please let me know if I should not.

Quoted 8 lines

And for 10.0.x "LTS" series, I'm also picking up 2 extra commits:

a079836005 tcg/loongarch64: Fix vec_val computation in tcg_target_const_match 911f7328e9 tcg/loongarch64: Improve constraints for TCG_CT_CONST_VCMP

which looks like an improvement too :)

Again, please let me know if I should not.

Thanks.

r~