[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Behaviour of jit_qrsh()
From: |
Paul Cercueil |
Subject: |
Re: Behaviour of jit_qrsh() |
Date: |
Tue, 03 Oct 2023 00:46:49 +0200 |
Hi Paulo,
Le lundi 02 octobre 2023 à 08:57 -0300, Paulo César Pereira de Andrade
a écrit :
> Em qui., 28 de set. de 2023 às 10:20, Paul Cercueil
> <paul@crapouillou.net> escreveu:
> >
> > Hi Paulo,
>
> Hi Paul,
>
> > I'm trying to implement the q-shift operations on SH4.
> >
> > In the doc, jit_qrsh() is defined as this operation:
> > O1 = O3 >> O4, O2 = O3 << (WORDSIZE - O4)
>
> I considered writing a "fast" version without special cases. But at
> the end decided to keep only a long version, with defined behavior
> for special cases. The special cases are 0 and wordsize shifts.
> Shift values not in the inclusive 0 ... wordsize range are undefined.
>
> > qalu_shift.tst does this test:
> > QRSH(0, 0x89abcdef, 0, 0x89abcdef, 0xffffffff)
>
> It is just a weird way to sign extend 0x89abcdef with a zero signed
> shift to right. Essentially simple reproducer is C is:
> #include <stdio.h>
> int main() {
> int i = 0x89abcdef;
> printf("%llx\n", (long long)i);
> return 0;
> }
That would be the behaviour of RSHR #32, which indeed sign-extends the
value into two registers. For RSHR #0, you left-shift by WORDSIZE bits,
not right-shift, so O2 should always be 0.
Besides, for any other value of O4, the behaviour is that the LSBs of
O3, not the MSBs, will be shifted into O2. So I really don't see a
reason why O3 would contain the LSBs for all values of O4 but 0, where
it would contain the sign-extended MSBs. It just doesn't make sense to
me.
Do you really depend on this behaviour somewhere?
> > However, I don't see how this can be valid. "O3 << (32 - 0)" should
> > always be 0, not 0xffffffff. So I believe this check should
> > actually
> > be:
> > QRSH(0, 0x89abcdef, 0, 0x89abcdef, 0x00000000)
>
> The unsigned test shows this:
>
> QRSHU(0, 0x89abcdef, 0, 0x89abcdef, 0x00000000)
QRSH / QRSHU #0 would be equivalent, yes, but the O0 register would be
different for any other value, as the former uses an arithmetic right-
shift while the latter uses a logical right-shift.
Speaking about tests, qalu_shift.txt only tests with a single value
0x89abcdef, it should probably also use a signed positive value for
signed QRSH / QLSH.
Cheers,
-Paul