From: Richard Henderson <richard.henderson@linaro.org>
To: Zack Buhman <zack@buhman.org>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: Re: [PATCH v2] sh4: mac.l: implement saturation arithmetic logic
Date: Fri, 5 Apr 2024 13:02:12 -1000 [thread overview]
Message-ID: <48494079-af1c-419d-88a9-bc38ab18c346@linaro.org> (raw)
In-Reply-To: <20240404162641.27528-2-zack@buhman.org>
On 4/4/24 06:26, Zack Buhman wrote:
> The saturation arithmetic logic in helper_macl is not correct.
>
> I tested and verified this behavior on a SH7091, the general pattern
> is a code sequence such as:
>
> sets
>
> mov.l _mach,r2
> lds r2,mach
> mov.l _macl,r2
> lds r2,macl
>
> mova _n,r0
> mov r0,r1
> mova _m,r0
> mac.l @r0+,@r1+
>
> _mach: .long 0x00007fff
> _macl: .long 0x12345678
> _m: .long 0x7fffffff
> _n: .long 0x7fffffff
>
> Test case 0: (no int64_t overflow)
> given; prior to saturation mac.l:
> mach = 0x00007fff macl = 0x12345678
> @r0 = 0x7fffffff @r1 = 0x7fffffff
>
> expected saturation mac.l result:
> mach = 0x00007fff macl = 0xffffffff
>
> qemu saturation mac.l result (prior to this commit):
> mach = 0x00007ffe macl = 0x12345678
>
> Test case 1: (no int64_t overflow)
> given; prior to saturation mac.l:
> mach = 0xffff8000 macl = 0x00000000
> @r0 = 0xffffffff @r1 = 0x00000001
>
> expected saturation mac.l result:
> mach = 0xffff8000 macl = 0x00000000
>
> qemu saturation mac.l result (prior to this commit):
> mach = 0xffff7fff macl = 0xffffffff
>
> Test case 2: (int64_t addition overflow)
> given; prior to saturation mac.l:
> mach = 0x80000000 macl = 0x00000000
> @r0 = 0xffffffff @r1 = 0x00000001
>
> expected saturation mac.l result:
> mach = 0xffff8000 macl = 0x00000000
>
> qemu saturation mac.l result (prior to this commit):
> mach = 0xffff7fff macl = 0xffffffff
>
> Test case 3: (int64_t addition overflow)
> given; prior to saturation mac.l:
> mach = 0x7fffffff macl = 0x00000000
> @r0 = 0x7fffffff @r1 = 0x7fffffff
>
> expected saturation mac.l result:
> mach = 0x00007fff macl = 0xffffffff
>
> qemu saturation mac.l result (prior to this commit):
> mach = 0xfffffffe macl = 0x00000001
>
> All of the above also matches the description of MAC.L as documented
> in cd00147165-sh-4-32-bit-cpu-core-architecture-stmicroelectronics.pdf
> ---
> target/sh4/op_helper.c | 31 +++++++++++++++++++++----------
> 1 file changed, 21 insertions(+), 10 deletions(-)
Queued, thanks.
r~
prev parent reply other threads:[~2024-04-05 23:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-04 15:10 [PATCH] sh4: mac.l: implement saturation arithmetic logic Zack Buhman
2024-04-04 15:37 ` Peter Maydell
2024-04-04 16:26 ` [PATCH v2] " Zack Buhman
2024-04-04 16:39 ` Peter Maydell
2024-04-04 17:26 ` Philippe Mathieu-Daudé
2024-04-04 22:55 ` Zack Buhman
2024-04-05 23:02 ` 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=48494079-af1c-419d-88a9-bc38ab18c346@linaro.org \
--to=richard.henderson@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=zack@buhman.org \
/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).