From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C500FC4345F for ; Wed, 1 May 2024 12:56:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s29VL-0007rW-5X; Wed, 01 May 2024 08:56:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s29VI-0007qq-Gl; Wed, 01 May 2024 08:56:08 -0400 Received: from ik1-413-38519.vs.sakura.ne.jp ([153.127.30.23] helo=sakura.ysato.name) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s29VF-0004BB-RY; Wed, 01 May 2024 08:56:08 -0400 Received: from SIOS1075.ysato.ml (ZM005235.ppp.dion.ne.jp [222.8.5.235]) by sakura.ysato.name (Postfix) with ESMTPSA id 051531C01DF; Wed, 1 May 2024 21:56:03 +0900 (JST) Date: Wed, 01 May 2024 21:56:03 +0900 Message-ID: <87sez1ady4.wl-ysato@users.sourceforge.jp> From: Yoshinori Sato To: Philippe =?ISO-8859-1?Q?Mathieu-Daud=E9?= Cc: qemu-devel@nongnu.org, John Paul Adrian Glaubitz , Paul Cercueil , qemu-stable@nongnu.org, Richard Henderson Subject: Re: [PATCH v4 2/4] target/sh4: Fix SUBV opcode In-Reply-To: <20240430163125.77430-3-philmd@linaro.org> References: <20240430163125.77430-1-philmd@linaro.org> <20240430163125.77430-3-philmd@linaro.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Received-SPF: softfail client-ip=153.127.30.23; envelope-from=ysato@users.sourceforge.jp; helo=sakura.ysato.name X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, KHOP_HELO_FCRDNS=0.001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Wed, 01 May 2024 01:31:23 +0900, Philippe Mathieu-Daud=E9 wrote: >=20 > The documentation says: >=20 > SUBV Rm, Rn Rn - Rm -> Rn, underflow -> T >=20 > The overflow / underflow can be calculated as: >=20 > T =3D ((Rn ^ Rm) & (Result ^ Rn)) >> 31 >=20 > However we were using the incorrect: >=20 > T =3D ((Rn ^ Rm) & (Result ^ Rm)) >> 31 >=20 > Fix by using the Rn register instead of Rm. >=20 > Add tests provided by Paul Cercueil. >=20 > Cc: qemu-stable@nongnu.org > Fixes: ad8d25a11f ("target-sh4: implement addv and subv using TCG") > Reported-by: Paul Cercueil > Suggested-by: Paul Cercueil > Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2318 > Reviewed-by: Richard Henderson > Signed-off-by: Philippe Mathieu-Daud=E9 > --- > target/sh4/translate.c | 2 +- > tests/tcg/sh4/test-subv.c | 30 ++++++++++++++++++++++++++++++ > tests/tcg/sh4/Makefile.target | 3 +++ > 3 files changed, 34 insertions(+), 1 deletion(-) > create mode 100644 tests/tcg/sh4/test-subv.c >=20 > diff --git a/target/sh4/translate.c b/target/sh4/translate.c > index 4a1dd0d1f4..3e013b7c7c 100644 > --- a/target/sh4/translate.c > +++ b/target/sh4/translate.c > @@ -933,7 +933,7 @@ static void _decode_opc(DisasContext * ctx) > t0 =3D tcg_temp_new(); > tcg_gen_sub_i32(t0, REG(B11_8), REG(B7_4)); > t1 =3D tcg_temp_new(); > - tcg_gen_xor_i32(t1, t0, REG(B7_4)); > + tcg_gen_xor_i32(t1, t0, REG(B11_8)); > t2 =3D tcg_temp_new(); > tcg_gen_xor_i32(t2, REG(B11_8), REG(B7_4)); > tcg_gen_and_i32(t1, t1, t2); > diff --git a/tests/tcg/sh4/test-subv.c b/tests/tcg/sh4/test-subv.c > new file mode 100644 > index 0000000000..0dd8fcdaac > --- /dev/null > +++ b/tests/tcg/sh4/test-subv.c > @@ -0,0 +1,30 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > + > +#include > +#include > +#include > + > +static void subv(const int a, const int b, const int res, const int carr= y) > +{ > + int o =3D a, c; > + > + asm volatile("subv %2,%0\n" > + "movt %1\n" > + : "+r"(o), "=3Dr"(c) : "r"(b) :); > + > + if (c !=3D carry || o !=3D res) { > + printf("SUBV %d, %d =3D %d/%d [T =3D %d/%d]\n", a, b, o, res, c,= carry); > + abort(); > + } > +} > + > +int main(void) > +{ > + subv(INT_MIN, 1, INT_MAX, 1); > + subv(INT_MAX, -1, INT_MIN, 1); > + subv(INT_MAX, 1, INT_MAX - 1, 0); > + subv(0, 1, -1, 0); > + subv(-1, -1, 0, 0); > + > + return 0; > +} > diff --git a/tests/tcg/sh4/Makefile.target b/tests/tcg/sh4/Makefile.target > index 521b8b0a76..7852fa62d8 100644 > --- a/tests/tcg/sh4/Makefile.target > +++ b/tests/tcg/sh4/Makefile.target > @@ -20,3 +20,6 @@ TESTS +=3D test-macw > =20 > test-addv: CFLAGS +=3D -O -g > TESTS +=3D test-addv > + > +test-subv: CFLAGS +=3D -O -g > +TESTS +=3D test-subv > --=20 > 2.41.0 >=20 Reviewed-by: Yoshinori Sato --=20 Yosinori Sato