From: Ilya Leoshkevich <iii@linux.ibm.com>
To: David Hildenbrand <david@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
Cornelia Huck <cohuck@redhat.com>, Thomas Huth <thuth@redhat.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
qemu-s390x@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 3/5] target/s390x: Fix cc_calc_sla_64() missing overflows
Date: Wed, 12 Jan 2022 17:38:52 +0100 [thread overview]
Message-ID: <4bf54d68d8e35db0c5555404934a3df47cacf8e1.camel@linux.ibm.com> (raw)
In-Reply-To: <c9544f5c-545a-8edf-dac6-a960aa00d4dd@redhat.com>
On Wed, 2022-01-12 at 16:45 +0100, David Hildenbrand wrote:
> > > If the sign is false, the shifted bits (mask) have to be 0.
> > > If the sign bit is true, the shifted bits (mask) have to be set.
> >
> > IIUC this logic handles sign bit + "shift - 1" bits. So if the last
> > shifted bit is different, the overflow is not detected.
>
> Ah, right, because of the - 1ULL ...
>
> [...]
>
> > > This looks like some black magic :)
> >
> > Yeah, I felt this way too, but didn't come up with anything better
> > and
> > just left a comment warning not to simplify.
> >
>
> I wonder if all we want is
>
> const uint64_t sign = 1ULL << 63;
> uint64_t mask = (-1ULL << (63 - shift)) & ~sign;
>
> For shift =
> * 0: 0000000...0b
> * 1: 0100000...0b
> * 2: 0110000...0b
> * 63: 0111111...1b
>
> Seems to survive your tests.
-1ULL does indeed help a lot to simplify this.
I don't think we even need to mask out the sign, since it should be
the same as the other bits anyway. So just
uint64_t mask = -1ULL << (63 - shift);
appears to be enough.
next prev parent reply other threads:[~2022-01-12 16:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-12 4:39 [PATCH v2 0/5] target/s390x: Fix shift instructions Ilya Leoshkevich
2022-01-12 4:39 ` [PATCH v2 1/5] target/s390x: Fix SLDA sign bit index Ilya Leoshkevich
2022-01-12 8:33 ` David Hildenbrand
2022-01-12 4:39 ` [PATCH v2 2/5] target/s390x: Fix SRDA CC calculation Ilya Leoshkevich
2022-01-12 8:46 ` David Hildenbrand
2022-01-12 4:39 ` [PATCH v2 3/5] target/s390x: Fix cc_calc_sla_64() missing overflows Ilya Leoshkevich
2022-01-12 8:59 ` David Hildenbrand
2022-01-12 12:51 ` Ilya Leoshkevich
2022-01-12 15:45 ` David Hildenbrand
2022-01-12 16:38 ` Ilya Leoshkevich [this message]
2022-01-12 4:39 ` [PATCH v2 4/5] target/s390x: Fix shifting 32-bit values for more than 31 bits Ilya Leoshkevich
2022-01-12 8:43 ` David Hildenbrand
2022-01-12 4:39 ` [PATCH v2 5/5] tests/tcg/s390x: Test shift instructions Ilya Leoshkevich
2022-01-12 9:07 ` David Hildenbrand
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=4bf54d68d8e35db0c5555404934a3df47cacf8e1.camel@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.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).