From patchwork Tue Apr 30 14:56:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 793325 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:54f:b0:34d:5089:5a9e with SMTP id b15csp306111wrf; Tue, 30 Apr 2024 07:57:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVTN1VWqrSDh8icrNYnfruiTDmSVRNBA2bCPVolSZgoJBsK0uV8jClTFV18C71nN4/gnMqSdRVMRxdV57ybA0GN X-Google-Smtp-Source: AGHT+IHkcvIJQs04NmFlnrfAnG2kEfdMnaGDbVeJB9DJ9Dn78UOW362mTvVX0l2ywCfHlhkQSeS1 X-Received: by 2002:a05:6214:409:b0:69b:5576:49e7 with SMTP id z9-20020a056214040900b0069b557649e7mr15063529qvx.45.1714489020838; Tue, 30 Apr 2024 07:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714489020; cv=none; d=google.com; s=arc-20160816; b=ZfYhEVAVmtOx892WghDpIHv8knya0BS4UbwMbXyuy+MtdJ0RvBHTYcaDYjYRIL8fwt gic8rFqORplYCy27znAXXXA3Bnsqe7PRpF73ViGQqbAccJEfzZO7QV2jWyBHiwpSiVdk zUletKVqpV8BJmorCPbdLufOGPJkDObV+Ge6J883puMo6iadLkWM24yzKqsPve3FabWt EmqrokQGfldJaUqFCmGZO85a2oL1mz514r/o858B1JeFJ+KhJwRA5atR+MhmZXrxYiMt ZhiiMNRjcDomdCa91bVb9akoTo5EV5CNW5Ar3O3mz2QTFAiB9NiL6u2SK+ywSDwyy0oP 3t3w== 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:dkim-signature; bh=e0X80mS9yZh3HbIdA8l9s4NtXPfqvlI+J4uan4HO+FY=; fh=45NLiQg4EMU6ZaU2NF2rceaXURtE7z0ozrvxeA9ySDM=; b=hQTr7uVDkb8ENuenwTSBwFYdsYqlyAqq/xydAIWOWDU66bi2bdUNMfooDiFgZqqfWT d5nSBGGMIYpBB2MMrQoYvJmVxX7k7naYtbctcwiGkS/aAcCOOXP3/xRHIlZZv15QmGmI pIGdQc0XRR/KQFeuM/IEZg5kgaBlxOa2u1q/KEjtEf3L4WpTzHZXs7F6JkRMhP+Xf7cv 4S3rvGc7Z8G/zy1g8SjdvV606pN5lrQ244t1uQ40gbebwjg8XKcp6+HOEWi4HxoUU/CT PszzVXOqFUw5e4CTYdyJN7lRGGfFyYvMHOIYR8hOTxQM2JEr+caRcp/0gnwyoSEigDlj qfdw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cljq54H6; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q7-20020ad45ca7000000b006a0ca91d5e6si5764882qvh.238.2024.04.30.07.57.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Apr 2024 07:57:00 -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; dkim=pass header.i=@linaro.org header.s=google header.b=Cljq54H6; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1ouB-0002yP-MI; Tue, 30 Apr 2024 10:56:27 -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 1s1ouA-0002y2-Ok for qemu-devel@nongnu.org; Tue, 30 Apr 2024 10:56:26 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1ou8-0006dn-AN for qemu-devel@nongnu.org; Tue, 30 Apr 2024 10:56:26 -0400 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-51acb95b892so7186752e87.2 for ; Tue, 30 Apr 2024 07:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714488982; x=1715093782; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e0X80mS9yZh3HbIdA8l9s4NtXPfqvlI+J4uan4HO+FY=; b=Cljq54H6VZ+OsZ+Bfl5IGDso0eqP3uE0EvEU6dfHQQY9Yd2mbAFV6lvC7t7xo0YErJ 2G3PekTUnpQglaDBnC2RPUy8cDi7s98rAYx+0kk1pmBwwcuC8NVYFXo8Crjg9NKWYzRt 9hLWoxvDyv0W9yp7xFivZ1PWji/utqg898288sxZVd86m5AHb9esNlRZgUyQLrKlnxeO P2NfGchPu9gvzvm9Utf57JfOEGQrL6kaP5wL8IrzZTIBPC3VEv11GE0BdTcNdAFugeSJ AHtQ+bEhq5QVL6HNdTTQUqDLODfsZ8Ga4vFWlUXtIq1gZOs1+X1Lzj6q0EVa9NWpPB2n uWsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714488982; x=1715093782; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e0X80mS9yZh3HbIdA8l9s4NtXPfqvlI+J4uan4HO+FY=; b=oqX0loldzYgHxOsp64sq+ye8R1cPRGMnW9Qk79SPhSWKITWuXeFNOxpFJ2fX0nKeBM 3mF/RDlkxAGLWTr9yf3oF5l6uX6JmoKVjPFgmajODMc3hiQkj5pPeqjsupXjAP684/Zp LQDQkpc020peaboLEpVElUWt2U6Yshj80G1l61Dh9XSIfT8w32hRO7J4Oyhcjh5Egw+5 T4KlrdOJpeZ4lU/oG9ZkanbbmAZMyVg1YndsFPwS9EOnB879KLZ/zrsa44Q5HtgSdykN O6r8WfAE/5Fum5RXhEc8Y+jLmGTYum0q0WxbxyKIh2llu29E8NRWUTWmL2PR7lCULgaM 9fhQ== X-Gm-Message-State: AOJu0YxXCJhRiCJGjpUma3PnlNEGhPA7UtCQnqLrnz73KawEcH9ZOfkl 6eguvj+tGbRq3v7UgcpLaiZH7hw6W5mseWCc+/Mn4l+s4nRI6kD0Mi21kF5aURx/9Kwvv+HB/U+ c X-Received: by 2002:a05:6512:1592:b0:51d:5ffd:efe4 with SMTP id bp18-20020a056512159200b0051d5ffdefe4mr8042664lfb.1.1714488982217; Tue, 30 Apr 2024 07:56:22 -0700 (PDT) Received: from m1x-phil.lan (mab78-h01-176-184-55-179.dsl.sta.abo.bbox.fr. [176.184.55.179]) by smtp.gmail.com with ESMTPSA id w5-20020a5d6805000000b0034c8b0354a6sm9626938wru.106.2024.04.30.07.56.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 30 Apr 2024 07:56:21 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Yoshinori Sato , Paul Cercueil , John Paul Adrian Glaubitz , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org Subject: [PATCH v3 1/4] target/sh4: Fix ADDV opcode Date: Tue, 30 Apr 2024 16:56:11 +0200 Message-ID: <20240430145614.76475-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240430145614.76475-1-philmd@linaro.org> References: <20240430145614.76475-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::136; envelope-from=philmd@linaro.org; helo=mail-lf1-x136.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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 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 Signed-off-by: Philippe Mathieu-Daudé --- target/sh4/translate.c | 2 +- tests/tcg/sh4/test-addv.c | 23 +++++++++++++++++++++++ tests/tcg/sh4/Makefile.target | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/sh4/test-addv.c 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/test-addv.c b/tests/tcg/sh4/test-addv.c new file mode 100644 index 0000000000..54ac77b867 --- /dev/null +++ b/tests/tcg/sh4/test-addv.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include + +static void addv(int a, int b, int res, int carry) +{ + unsigned int c; + + asm volatile("addv %2,%0\n" + "movt %1\n" + : "+r"(a), "=r"(c) : "r"(b) :); + + assert(c == carry && a == res); +} + +int main(void) +{ + addv(INT_MAX, 1, INT_MIN, 1); + addv(INT_MAX - 1, 1, INT_MAX, 0); + + return 0; +} 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