Skip to contentSkip to conversation

tcg/s390: Fix compare instruction from extended-immediate facility

PATCH In review Philippe Mathieu-Daudé 4 participants 4 messages Feb 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg/s390: Fix compare instruction from extended-immediate facility

The code is currently comparing c2 to the type promotion of uint32_t and int32_t. That is, the conversion rules are as:

(common_type) c2 == (common_type) (uint32_t)

                        (is_unsigned
                        ? (uint32_t)c2
                        : (uint32_t)(int32_t)c2)

In the signed case we lose the desired sign extensions because of the argument promotion rules of the ternary operator.

Solve the problem by doing the round-trip parsing through the intermediate type and back to the desired common type (all at one expression).

---
 tcg/s390/tcg-target.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/s390/tcg-target.c.inc +1 -1
index b67470137c4..695d7ee6523 100644
@@ -1067,7 +1067,7 @@ static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1,
                 op = (is_unsigned ? RIL_CLFI : RIL_CFI);
                 tcg_out_insn_RIL(s, op, r1, c2);
                 goto exit;
-            } else if (c2 == (is_unsigned ? (uint32_t)c2 : (int32_t)c2)) {
+            } else if (c2 == (is_unsigned ? (TCGArg)(uint32_t)c2 : (TCGArg)(int32_t)c2)) {
                 op = (is_unsigned ? RIL_CLGFI : RIL_CGFI);
                 tcg_out_insn_RIL(s, op, r1, c2);
                 goto exit;
Signature · 1 line
2.26.2
#1 lore raw
Quoted 21 lines · Philippe Mathieu-Daudé

The code is currently comparing c2 to the type promotion of uint32_t and int32_t. That is, the conversion rules are as:

(common_type) c2 == (common_type) (uint32_t)

                        (is_unsigned
                        ? (uint32_t)c2
                        : (uint32_t)(int32_t)c2)

In the signed case we lose the desired sign extensions because of the argument promotion rules of the ternary operator.

Solve the problem by doing the round-trip parsing through the intermediate type and back to the desired common type (all at one expression).

Quoted 3 lines
---
 tcg/s390/tcg-target.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

A most excellent catch, thanks. Queued.

r~

Reviewed-by on v1 1/1
#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 31 lines · Philippe Mathieu-Daudé

The code is currently comparing c2 to the type promotion of uint32_t and int32_t. That is, the conversion rules are as:

   (common_type) c2 == (common_type) (uint32_t)
                         (is_unsigned
                         ? (uint32_t)c2
                         : (uint32_t)(int32_t)c2)

In the signed case we lose the desired sign extensions because of the argument promotion rules of the ternary operator.

Solve the problem by doing the round-trip parsing through the intermediate type and back to the desired common type (all at one expression).

---
  tcg/s390/tcg-target.c.inc | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tcg/s390/tcg-target.c.inc +0 -0
index b67470137c4..695d7ee6523 100644

tcg/s390/tcg-target.c.inc static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1, · line 1073

Quoted 8 lines
tcg/s390/tcg-target.c.inc +1 -1
@@ -1067,7 +1067,7 @@ static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1,
                  op = (is_unsigned ? RIL_CLFI : RIL_CFI);
                  tcg_out_insn_RIL(s, op, r1, c2);
                  goto exit;
-            } else if (c2 == (is_unsigned ? (uint32_t)c2 : (int32_t)c2)) {
+            } else if (c2 == (is_unsigned ? (TCGArg)(uint32_t)c2 : (TCGArg)(int32_t)c2)) {
                  op = (is_unsigned ? RIL_CLGFI : RIL_CGFI);
                  tcg_out_insn_RIL(s, op, r1, c2);
                  goto exit;
Signature · 3 lines
Thanks,

David / dhildenb
Tested-by on v1 1/1
#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 30 lines · Philippe Mathieu-Daudé

The code is currently comparing c2 to the type promotion of uint32_t and int32_t. That is, the conversion rules are as:

(common_type) c2 == (common_type) (uint32_t)

                        (is_unsigned
                        ? (uint32_t)c2
                        : (uint32_t)(int32_t)c2)

In the signed case we lose the desired sign extensions because of the argument promotion rules of the ternary operator.

Solve the problem by doing the round-trip parsing through the intermediate type and back to the desired common type (all at one expression).

---
 tcg/s390/tcg-target.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/s390/tcg-target.c.inc +0 -0
index b67470137c4..695d7ee6523 100644

tcg/s390/tcg-target.c.inc static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1, · line 1073

Quoted 8 lines
tcg/s390/tcg-target.c.inc +1 -1
@@ -1067,7 +1067,7 @@ static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1,
                 op = (is_unsigned ? RIL_CLFI : RIL_CFI);
                 tcg_out_insn_RIL(s, op, r1, c2);
                 goto exit;
-            } else if (c2 == (is_unsigned ? (uint32_t)c2 : (int32_t)c2)) {
+            } else if (c2 == (is_unsigned ? (TCGArg)(uint32_t)c2 : (TCGArg)(int32_t)c2)) {
                 op = (is_unsigned ? RIL_CLGFI : RIL_CGFI);
                 tcg_out_insn_RIL(s, op, r1, c2);
                 goto exit;

I have tested this patch on an s390x host on top of 1ed9228f63e "Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2021-02-02-v2' into staging" and I can confirm that it fixes both previously reported problems. Therefore you can add:

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org