qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] tcg/loongarch64: constraint fix and improvement
@ 2025-04-24 19:07 Richard Henderson
  2025-04-24 19:07 ` [PATCH 1/2] tcg/loongarch64: Fix vec_val computation in tcg_target_const_match Richard Henderson
  2025-04-24 19:07 ` [PATCH 2/2] tcg/loongarch64: Improve constraints for TCG_CT_CONST_VCMP Richard Henderson
  0 siblings, 2 replies; 5+ messages in thread
From: Richard Henderson @ 2025-04-24 19:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: git

Fix an assertion failure in sextract64 which shows up in make check.
While in the area, improve the constraint match for VCMP.

r~

Richard Henderson (2):
  tcg/loongarch64: Fix vec_val computation in tcg_target_const_match
  tcg/loongarch64: Improve constraints for TCG_CT_CONST_VCMP

 tcg/loongarch64/tcg-target.c.inc | 48 ++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 21 deletions(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] tcg/loongarch64: Fix vec_val computation in tcg_target_const_match
  2025-04-24 19:07 [PATCH 0/2] tcg/loongarch64: constraint fix and improvement Richard Henderson
@ 2025-04-24 19:07 ` Richard Henderson
  2025-04-24 20:53   ` Philippe Mathieu-Daudé
  2025-04-24 19:07 ` [PATCH 2/2] tcg/loongarch64: Improve constraints for TCG_CT_CONST_VCMP Richard Henderson
  1 sibling, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2025-04-24 19:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: git

Only use vece for a vector constant.  This avoids an assertion
failure in sextract64 when vece contains garbage.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tcg/loongarch64/tcg-target.c.inc | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc
index cbd7642b58..740b7c264d 100644
--- a/tcg/loongarch64/tcg-target.c.inc
+++ b/tcg/loongarch64/tcg-target.c.inc
@@ -211,12 +211,14 @@ static bool tcg_target_const_match(int64_t val, int ct,
     if ((ct & TCG_CT_CONST_WSZ) && val == (type == TCG_TYPE_I32 ? 32 : 64)) {
         return true;
     }
-    int64_t vec_val = sextract64(val, 0, 8 << vece);
-    if ((ct & TCG_CT_CONST_VCMP) && -0x10 <= vec_val && vec_val <= 0x1f) {
-        return true;
-    }
-    if ((ct & TCG_CT_CONST_VADD) && -0x1f <= vec_val && vec_val <= 0x1f) {
-        return true;
+    if (ct & (TCG_CT_CONST_VCMP | TCG_CT_CONST_VADD)) {
+        int64_t vec_val = sextract64(val, 0, 8 << vece);
+        if ((ct & TCG_CT_CONST_VCMP) && -0x10 <= vec_val && vec_val <= 0x1f) {
+            return true;
+        }
+        if ((ct & TCG_CT_CONST_VADD) && -0x1f <= vec_val && vec_val <= 0x1f) {
+            return true;
+        }
     }
     return false;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] tcg/loongarch64: Improve constraints for TCG_CT_CONST_VCMP
  2025-04-24 19:07 [PATCH 0/2] tcg/loongarch64: constraint fix and improvement Richard Henderson
  2025-04-24 19:07 ` [PATCH 1/2] tcg/loongarch64: Fix vec_val computation in tcg_target_const_match Richard Henderson
@ 2025-04-24 19:07 ` Richard Henderson
  2025-04-24 20:55   ` Philippe Mathieu-Daudé
  1 sibling, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2025-04-24 19:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: git

Use the TCGCond given to tcg_target_const_match to exactly match
the supported constant.  Adjust the code generation to assume this
has been done -- recall that encode_*_insn contain assertions that
the constants are valid.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tcg/loongarch64/tcg-target.c.inc | 38 ++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc
index 740b7c264d..879f66f255 100644
--- a/tcg/loongarch64/tcg-target.c.inc
+++ b/tcg/loongarch64/tcg-target.c.inc
@@ -213,8 +213,18 @@ static bool tcg_target_const_match(int64_t val, int ct,
     }
     if (ct & (TCG_CT_CONST_VCMP | TCG_CT_CONST_VADD)) {
         int64_t vec_val = sextract64(val, 0, 8 << vece);
-        if ((ct & TCG_CT_CONST_VCMP) && -0x10 <= vec_val && vec_val <= 0x1f) {
-            return true;
+        if (ct & TCG_CT_CONST_VCMP) {
+            switch (cond) {
+            case TCG_COND_EQ:
+            case TCG_COND_LE:
+            case TCG_COND_LT:
+                return -0x10 <= vec_val && vec_val <= 0x0f;
+            case TCG_COND_LEU:
+            case TCG_COND_LTU:
+                return 0x00 <= vec_val && vec_val <= 0x1f;
+            default:
+                return false;
+            }
         }
         if ((ct & TCG_CT_CONST_VADD) && -0x1f <= vec_val && vec_val <= 0x1f) {
             return true;
@@ -2029,28 +2039,22 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
                  * Try vseqi/vslei/vslti
                  */
                 int64_t value = sextract64(a2, 0, 8 << vece);
-                if ((cond == TCG_COND_EQ ||
-                     cond == TCG_COND_LE ||
-                     cond == TCG_COND_LT) &&
-                    (-0x10 <= value && value <= 0x0f)) {
+                switch (cond) {
+                case TCG_COND_EQ:
+                case TCG_COND_LE:
+                case TCG_COND_LT:
                     insn = cmp_vec_imm_insn[cond][lasx][vece];
                     tcg_out32(s, encode_vdvjsk5_insn(insn, a0, a1, value));
                     break;
-                } else if ((cond == TCG_COND_LEU ||
-                            cond == TCG_COND_LTU) &&
-                           (0x00 <= value && value <= 0x1f)) {
+                case TCG_COND_LEU:
+                case TCG_COND_LTU:
                     insn = cmp_vec_imm_insn[cond][lasx][vece];
                     tcg_out32(s, encode_vdvjuk5_insn(insn, a0, a1, value));
                     break;
+                default:
+                    g_assert_not_reached();
                 }
-
-                /*
-                 * Fallback to:
-                 * dupi_vec temp, a2
-                 * cmp_vec a0, a1, temp, cond
-                 */
-                tcg_out_dupi_vec(s, type, vece, TCG_VEC_TMP0, a2);
-                a2 = TCG_VEC_TMP0;
+                break;
             }
 
             insn = cmp_vec_insn[cond][lasx][vece];
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] tcg/loongarch64: Fix vec_val computation in tcg_target_const_match
  2025-04-24 19:07 ` [PATCH 1/2] tcg/loongarch64: Fix vec_val computation in tcg_target_const_match Richard Henderson
@ 2025-04-24 20:53   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-24 20:53 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: git

On 24/4/25 21:07, Richard Henderson wrote:
> Only use vece for a vector constant.  This avoids an assertion
> failure in sextract64 when vece contains garbage.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tcg/loongarch64/tcg-target.c.inc | 14 ++++++++------
>   1 file changed, 8 insertions(+), 6 deletions(-)

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] tcg/loongarch64: Improve constraints for TCG_CT_CONST_VCMP
  2025-04-24 19:07 ` [PATCH 2/2] tcg/loongarch64: Improve constraints for TCG_CT_CONST_VCMP Richard Henderson
@ 2025-04-24 20:55   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-04-24 20:55 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: git

On 24/4/25 21:07, Richard Henderson wrote:
> Use the TCGCond given to tcg_target_const_match to exactly match
> the supported constant.  Adjust the code generation to assume this
> has been done -- recall that encode_*_insn contain assertions that
> the constants are valid.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tcg/loongarch64/tcg-target.c.inc | 38 ++++++++++++++++++--------------
>   1 file changed, 21 insertions(+), 17 deletions(-)

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-24 20:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-24 19:07 [PATCH 0/2] tcg/loongarch64: constraint fix and improvement Richard Henderson
2025-04-24 19:07 ` [PATCH 1/2] tcg/loongarch64: Fix vec_val computation in tcg_target_const_match Richard Henderson
2025-04-24 20:53   ` Philippe Mathieu-Daudé
2025-04-24 19:07 ` [PATCH 2/2] tcg/loongarch64: Improve constraints for TCG_CT_CONST_VCMP Richard Henderson
2025-04-24 20:55   ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).