* [PATCH] tcg/s390: Fix compare instruction from extended-immediate facility
@ 2021-02-04 18:29 Philippe Mathieu-Daudé
2021-02-04 18:54 ` Richard Henderson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-02-04 18:29 UTC (permalink / raw)
To: qemu-devel
Cc: Thomas Huth, David Hildenbrand, Cornelia Huck, Richard Henderson,
Philippe Mathieu-Daudé,
Richard W . M . Jones, qemu-s390x, Miroslav Rezanina
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).
Fixes: a534bb15f30 ("tcg/s390: Use constant pool for cmpi")
Reported-by: Miroslav Rezanina <mrezanin@redhat.com>
Reported-by: Richard W.M. Jones <rjones@redhat.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Suggested-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
tcg/s390/tcg-target.c.inc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tcg/s390/tcg-target.c.inc b/tcg/s390/tcg-target.c.inc
index b67470137c4..695d7ee6523 100644
--- a/tcg/s390/tcg-target.c.inc
+++ b/tcg/s390/tcg-target.c.inc
@@ -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;
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] tcg/s390: Fix compare instruction from extended-immediate facility
2021-02-04 18:29 [PATCH] tcg/s390: Fix compare instruction from extended-immediate facility Philippe Mathieu-Daudé
@ 2021-02-04 18:54 ` Richard Henderson
2021-02-04 19:25 ` David Hildenbrand
2021-02-04 22:06 ` Richard W.M. Jones
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2021-02-04 18:54 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Thomas Huth, David Hildenbrand, Cornelia Huck,
Richard W . M . Jones, qemu-s390x, Miroslav Rezanina
On 2/4/21 8:29 AM, Philippe Mathieu-Daudé wrote:
> 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).
>
> Fixes: a534bb15f30 ("tcg/s390: Use constant pool for cmpi")
> Reported-by: Miroslav Rezanina <mrezanin@redhat.com>
> Reported-by: Richard W.M. Jones <rjones@redhat.com>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Suggested-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> tcg/s390/tcg-target.c.inc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
A most excellent catch, thanks. Queued.
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tcg/s390: Fix compare instruction from extended-immediate facility
2021-02-04 18:29 [PATCH] tcg/s390: Fix compare instruction from extended-immediate facility Philippe Mathieu-Daudé
2021-02-04 18:54 ` Richard Henderson
@ 2021-02-04 19:25 ` David Hildenbrand
2021-02-04 22:06 ` Richard W.M. Jones
2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2021-02-04 19:25 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Thomas Huth, Cornelia Huck, Richard Henderson,
Richard W . M . Jones, qemu-s390x, Miroslav Rezanina
On 04.02.21 19:29, Philippe Mathieu-Daudé wrote:
> 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).
>
> Fixes: a534bb15f30 ("tcg/s390: Use constant pool for cmpi")
> Reported-by: Miroslav Rezanina <mrezanin@redhat.com>
> Reported-by: Richard W.M. Jones <rjones@redhat.com>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Suggested-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> tcg/s390/tcg-target.c.inc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tcg/s390/tcg-target.c.inc b/tcg/s390/tcg-target.c.inc
> index b67470137c4..695d7ee6523 100644
> --- a/tcg/s390/tcg-target.c.inc
> +++ b/tcg/s390/tcg-target.c.inc
> @@ -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;
>
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tcg/s390: Fix compare instruction from extended-immediate facility
2021-02-04 18:29 [PATCH] tcg/s390: Fix compare instruction from extended-immediate facility Philippe Mathieu-Daudé
2021-02-04 18:54 ` Richard Henderson
2021-02-04 19:25 ` David Hildenbrand
@ 2021-02-04 22:06 ` Richard W.M. Jones
2 siblings, 0 replies; 4+ messages in thread
From: Richard W.M. Jones @ 2021-02-04 22:06 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Thomas Huth, David Hildenbrand, Cornelia Huck, Richard Henderson,
qemu-devel, qemu-s390x, Miroslav Rezanina
On Thu, Feb 04, 2021 at 07:29:02PM +0100, Philippe Mathieu-Daudé wrote:
> 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).
>
> Fixes: a534bb15f30 ("tcg/s390: Use constant pool for cmpi")
> Reported-by: Miroslav Rezanina <mrezanin@redhat.com>
> Reported-by: Richard W.M. Jones <rjones@redhat.com>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Suggested-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> tcg/s390/tcg-target.c.inc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tcg/s390/tcg-target.c.inc b/tcg/s390/tcg-target.c.inc
> index b67470137c4..695d7ee6523 100644
> --- a/tcg/s390/tcg-target.c.inc
> +++ b/tcg/s390/tcg-target.c.inc
> @@ -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:
Tested-by: Richard W.M. Jones <rjones@redhat.com>
Rich.
--
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-02-04 22:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-04 18:29 [PATCH] tcg/s390: Fix compare instruction from extended-immediate facility Philippe Mathieu-Daudé
2021-02-04 18:54 ` Richard Henderson
2021-02-04 19:25 ` David Hildenbrand
2021-02-04 22:06 ` Richard W.M. Jones
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.