qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: David Hildenbrand <david@redhat.com>,
	Thomas Huth <thuth@redhat.com>,
	qemu-devel@nongnu.org
Cc: qemu-s390x@nongnu.org, Bruno Haible <bruno@clisp.org>
Subject: Re: [PATCH 2/2] target/s390x: Fix determination of overflow condition code after subtraction
Date: Wed, 30 Mar 2022 08:04:20 -0600	[thread overview]
Message-ID: <a59957f4-ad6f-609e-eb29-e14f16694fbc@linaro.org> (raw)
In-Reply-To: <c12a3830-053e-11b7-9e6c-325a7d03df5f@redhat.com>

On 3/30/22 02:57, David Hildenbrand wrote:
>> diff --git a/target/s390x/tcg/cc_helper.c b/target/s390x/tcg/cc_helper.c
>> index e11cdb745d..b2e8d3d9f5 100644
>> --- a/target/s390x/tcg/cc_helper.c
>> +++ b/target/s390x/tcg/cc_helper.c
>> @@ -151,7 +151,7 @@ static uint32_t cc_calc_add_64(int64_t a1, int64_t a2, int64_t ar)
>>   
>>   static uint32_t cc_calc_sub_64(int64_t a1, int64_t a2, int64_t ar)
>>   {
>> -    if ((a1 > 0 && a2 < 0 && ar < 0) || (a1 < 0 && a2 > 0 && ar > 0)) {
>> +    if ((a1 >= 0 && a2 < 0 && ar < 0) || (a1 < 0 && a2 > 0 && ar > 0)) {
>>           return 3; /* overflow */
>>       } else {
>>           if (ar < 0) {
>> @@ -211,7 +211,7 @@ static uint32_t cc_calc_add_32(int32_t a1, int32_t a2, int32_t ar)
>>   
>>   static uint32_t cc_calc_sub_32(int32_t a1, int32_t a2, int32_t ar)
>>   {
>> -    if ((a1 > 0 && a2 < 0 && ar < 0) || (a1 < 0 && a2 > 0 && ar > 0)) {
>> +    if ((a1 >= 0 && a2 < 0 && ar < 0) || (a1 < 0 && a2 > 0 && ar > 0)) {
>>           return 3; /* overflow */
>>       } else {
>>           if (ar < 0) {
> 
> Again, intuitively I'd check for
> 
> a) Subtracting a negative number from a positive one -> Adding two
> positive numbers should result in the result being bigger than the first
> parameter.
> 
> a1 > 0 && a2 < 0 && ar < a1
> 
> a) Subtracting a positive number from a negative one -> Adding two
> negative numbers should result in something that's smaller than the
> first parameter
> 
> a1 < 0 && a2 > 0 && ar > a1
> 
> 
> But maybe I am missing something :)

Again, see ssub64_overflow in qemu/host-utils.h.


r~


      reply	other threads:[~2022-03-30 14:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 16:26 [PATCH 0/2] target/s390x: Fix determination of overflow condition code Thomas Huth
2022-03-23 16:26 ` [PATCH 1/2] target/s390x: Fix determination of overflow condition code after addition Thomas Huth
2022-03-30  8:52   ` David Hildenbrand
2022-03-30  9:29     ` Thomas Huth
2022-03-30  9:34       ` David Hildenbrand
2022-03-30  9:42         ` Thomas Huth
2022-03-30  9:47           ` David Hildenbrand
2022-03-30 10:12             ` Thomas Huth
2022-03-30 10:15               ` Thomas Huth
2022-03-30 14:03     ` Richard Henderson
2022-03-31 14:52       ` Thomas Huth
2022-03-23 16:26 ` [PATCH 2/2] target/s390x: Fix determination of overflow condition code after subtraction Thomas Huth
2022-03-30  8:57   ` David Hildenbrand
2022-03-30 14:04     ` Richard Henderson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a59957f4-ad6f-609e-eb29-e14f16694fbc@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=bruno@clisp.org \
    --cc=david@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).