From patchwork Mon May 27 08:21:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 799229 Delivered-To: patch@linaro.org Received: by 2002:a5d:6a47:0:b0:354:fb4b:99cd with SMTP id t7csp1769123wrw; Mon, 27 May 2024 01:36:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVlUVmbA8XoaiVpsAUpB2HYddWNZve1yBgSFl0+fSHE65n9CBa/C6NkdCz7amJ6R4rK68OFz0asN/ZYg0QeQFV6 X-Google-Smtp-Source: AGHT+IEuhDoeSQHY3kywzT1ZlvWL8PqbjsnpZNMS+/YC/NC2Xf+WpCKsUxxLaqLjlj9F7zHsXqBO X-Received: by 2002:a0d:e20f:0:b0:62a:2a7d:b512 with SMTP id 00721157ae682-62a2a7dcc66mr36976097b3.10.1716798971678; Mon, 27 May 2024 01:36:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716798971; cv=none; d=google.com; s=arc-20160816; b=YJN4Q43tAXof6mwf+WOptOR549cZVp3ziAtcjGkREZImPKGsT23qYuHYAHb0BppELX VEpMyA4bJ3XPzoCWOgfnJSz7mj5wSM7svfPdAWeD83Fz7GC/1ndYy6tJ1kw4rOHYa1nQ LX2iIJJGhXErCSSdY00Fb6mMZFyUfZ+3rMhqoW1bel8Hy+YeqjtI+KhY+bNvnqTSUboP g0c+TC5TMxXPEyZUig+cwThlsn4NdLYV9z+0Nx/rkP2RyD1qYFhNCiOfkCCbFyy7gCzp a+bloNM643/yWLbO47d4BVfwxD7AMft5AeTcksHpJ7DNQy1rXruGfP4mX8vERp+MDtTd 6MJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=KVwu43qkr+h12lc8iljSg1ryiaxfyRCvD2CRD3/WcsQ=; fh=q09TJcPvxotL9gCkIe59Ge7cfqcjMrdjel2txRsy8jw=; b=OQWQPi6oMivxQS3M6pi2HKTrG32LxIYlJktqqKUrfWB0gTWVTgGk1XVXGbQbQnIxok yXUW8IQtwaINul/QlkwfYYngnwaSdfU1V78CEPHzzbxyB6QQU1BuiMxMrUuZN9lQqThT /yzyuvgWB7s3UvMXZjLe71EswakH59Cw9aHvNf6mp6ynSb/2urnmQ/4L3AInxP60Fny7 r8WxAEdOR8hL2RBmnOI+vASt5mAnJv/BEg5/SbMRB7HO3QfN/w/OGqtWF7i6hMzzxuBm USJhyYL6XCkSKXi9lTvNpFZorkWapvpXdgAJZOLk6yPCnMbApNUPniPvMJMwmb7e+4eP 3WqQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-794abd4d5casi739302085a.602.2024.05.27.01.36.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 May 2024 01:36:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBVdp-0001x3-QE; Mon, 27 May 2024 04:23:38 -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 1sBVcm-00018r-KF; Mon, 27 May 2024 04:22:33 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBVck-0000px-Pz; Mon, 27 May 2024 04:22:32 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 94CC36A56C; Mon, 27 May 2024 11:22:13 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id BF32AD8509; Mon, 27 May 2024 11:21:39 +0300 (MSK) Received: (nullmailer pid 66396 invoked by uid 1000); Mon, 27 May 2024 08:21:38 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Paul Cercueil , Richard Henderson , Yoshinori Sato , Michael Tokarev Subject: [Stable-9.0.1 15/44] target/sh4: Fix ADDV opcode Date: Mon, 27 May 2024 11:21:06 +0300 Message-Id: <20240527082138.66217-15-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé The documentation says: ADDV Rm, Rn Rn + Rm -> Rn, overflow -> T But QEMU implementation was: ADDV Rm, Rn Rn + Rm -> Rm, overflow -> T Fix by filling the correct Rm register. Add tests provided by Paul Cercueil. Cc: qemu-stable@nongnu.org Fixes: ad8d25a11f ("target-sh4: implement addv and subv using TCG") Reported-by: Paul Cercueil Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2317 Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Yoshinori Sato Message-Id: <20240430163125.77430-2-philmd@linaro.org> (cherry picked from commit c365e6b0705788866a65e7b8206bd4c5332595cd) Signed-off-by: Michael Tokarev diff --git a/target/sh4/translate.c b/target/sh4/translate.c index ebb6c901bf..4a1dd0d1f4 100644 --- a/target/sh4/translate.c +++ b/target/sh4/translate.c @@ -714,7 +714,7 @@ static void _decode_opc(DisasContext * ctx) tcg_gen_xor_i32(t2, REG(B7_4), REG(B11_8)); tcg_gen_andc_i32(cpu_sr_t, t1, t2); tcg_gen_shri_i32(cpu_sr_t, cpu_sr_t, 31); - tcg_gen_mov_i32(REG(B7_4), t0); + tcg_gen_mov_i32(REG(B11_8), t0); } return; case 0x2009: /* and Rm,Rn */ diff --git a/tests/tcg/sh4/Makefile.target b/tests/tcg/sh4/Makefile.target index 4d09291c0c..521b8b0a76 100644 --- a/tests/tcg/sh4/Makefile.target +++ b/tests/tcg/sh4/Makefile.target @@ -17,3 +17,6 @@ TESTS += test-macl test-macw: CFLAGS += -O -g TESTS += test-macw + +test-addv: CFLAGS += -O -g +TESTS += test-addv diff --git a/tests/tcg/sh4/test-addv.c b/tests/tcg/sh4/test-addv.c new file mode 100644 index 0000000000..ca87fe746a --- /dev/null +++ b/tests/tcg/sh4/test-addv.c @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include + +static void addv(const int a, const int b, const int res, const int carry) +{ + int o = a, c; + + asm volatile("addv %2,%0\n" + "movt %1\n" + : "+r"(o), "=r"(c) : "r"(b) : ); + + if (c != carry || o != res) { + printf("ADDV %d, %d = %d/%d [T = %d/%d]\n", a, b, o, res, c, carry); + abort(); + } +} + +int main(void) +{ + addv(INT_MAX, 1, INT_MIN, 1); + addv(INT_MAX - 1, 1, INT_MAX, 0); + + return 0; +}