From patchwork Fri May 3 15:36:10 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: 794397 Delivered-To: patch@linaro.org Received: by 2002:adf:a153:0:b0:34d:5089:5a9e with SMTP id r19csp800760wrr; Fri, 3 May 2024 08:37:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVnvGuUSO+fyBMAIutxVMLvMhRKLCPrfkxsefyzvv2bqWce5402/xYymDPfuVClmkZnVU63u2IOWiB/Yk4S8TIC X-Google-Smtp-Source: AGHT+IHFoA2Vqa/5cRO/IB5BokI8Rasln0KbM6m9X4qHh9ISdb9tDF4o2rIS2Op+3m9n5L+xO0LZ X-Received: by 2002:a05:6102:2377:b0:47b:ce8f:fb9 with SMTP id o23-20020a056102237700b0047bce8f0fb9mr2857043vsa.33.1714750662253; Fri, 03 May 2024 08:37:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714750662; cv=none; d=google.com; s=arc-20160816; b=yQ2eQjlmbhXGUj6d+AeE0U2Vj6xtv4WezANfwnWZKNwpLNzhcqWy+3Xf5ezZAVk7vp +4l1EyhqkcrxSokEpL7DbKLKrmm1BOvA1dy+d7UTpKSOO+7yrbbJ6CW7jkXMPjaK9uNx +h/1JCRe0glfaI4Orf3Ca7rCHTONmBu/j/QG14uQ+o4ldxP+0aLZpAVzrX5vy/taV2Xq gjeyjgmyhb2arau7fqw9nd1LgGxYJ1pp1MC5r7zx+C+xZ4GAdE50AONQpM7scC2pWUCe rCIRR+224q6RHrRwQB9mvixNo95bqJ4Y0YVI+HQwIszEvkphn8q5dbInz4+UXGrbuG2s Yhkw== 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=JZ76gv7i8YSHM81Ab5Mv7SVtJJSc8rRsU348TrrHgtg=; fh=XulqFHQlNobwzF7PQUD/SGnPoAu+ZjQHRlkDJqU/s+g=; b=MRPjIrUSuknaFR8uo//Cr52F3b4XJkAzYpkcfC5aDwUXC5k98xofeaccE/WPDXZNb+ cnHUPG22exlqu2EFc4qPpi4JPh4Pu5l/7rUEkQ8KnaMDGIw2MLC0BoUaSUOTzP+/vIT1 paaw1CuukA3QpvBE+/FdZU2gkaEjRIIXlGSP90K97giINdgDOXvjHxHs/JlILgnBjFW0 1doWRP6wkwCnICkpjF+03U61C5fo1rB8ZZqPS7F9Pk7hl6gyX9asXiirgY7AfVw21+WL qwMdsoPILaUmd2na/1B3QLtv0e0kHN6ECL8aYglBJR2lyV63tQJeaPUgOuRGlPzVh28y 28WA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VVfx94PR; 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 ic2-20020a0561024b8200b0047d9013c0bdsi864374vsb.616.2024.05.03.08.37.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2024 08:37:41 -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=VVfx94PR; 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 1s2uyc-0004ZC-Sa; Fri, 03 May 2024 11:37:36 -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 1s2uyT-0004NC-3y for qemu-devel@nongnu.org; Fri, 03 May 2024 11:37:25 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s2uyM-0002ly-Av for qemu-devel@nongnu.org; Fri, 03 May 2024 11:37:23 -0400 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a58fc650f8fso900971266b.1 for ; Fri, 03 May 2024 08:37:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714750636; x=1715355436; 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=JZ76gv7i8YSHM81Ab5Mv7SVtJJSc8rRsU348TrrHgtg=; b=VVfx94PRR1vbSJEA+5dz/eXx6X80jtwIHJs1D0vjnbBK0WDMRe5K8IlcE4inSCfYH7 b3iyHipIIKctAJGld9x5uCAdkudiH/2sa8H6Kjbh5VHOQnxv8vo7EISGU2TfOEZw5mvB FeTKcVWwYzG1BHaZUPq4ZuNysekK+1T2UPt9pvefgy7FXPE/kSAL7TQ1Fz88XLPuh7FG C31dEhlqj8qr+uisAI9vzxBpBIbniK4YR3L3bCgVbadFAp7ROmbyGFwefyi2Y3fh/Ka3 s32+RxrajruShiU9V/vUEjEv/0Z9IgZYADA4SJXTpLhNAnsHJGV4sHDbt2ConlJ7/+Sc 81Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714750636; x=1715355436; 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=JZ76gv7i8YSHM81Ab5Mv7SVtJJSc8rRsU348TrrHgtg=; b=i03LWoFdLnQCu0kQbu56AdwjoaPKWet7Y0vkt4fQfP7ckME9fT9HwM7foPr0jkrfE3 gcVImsE4RwC+29MRMUSDgBUQfYDvnhFBzvhXtYOw7j1Qk/nqjnavsfIrXN/vcswEZjnm c4gSbIRytHEfNZViNsAkEswLbF0sdu7xYo7c0VnFuGiMCmVH10nEVCtN0cx7gmMYCuhv yv+J2FWo2fh5oYIs9sH5rCq+J4sO6szn/rn9WDmbhwf4Er+/dLHh5pY5qaNyUyDx7+Rq u5iWQKXs0kJFgefmvsaA7lm9FjFqj0BiCOo3KYBa0EiyySW0Gmn5D1uEfHE/XcdhyE5K Xf2Q== X-Gm-Message-State: AOJu0YwSv2tSnTWliyNu2Wjnd29ujZkdZ6lDz5Ynt/rgW0ijH/A4JaBx c5cpCfxPsml8q9S3WpbjJFfCavRB2bjYjuvoXKgIfYvs0OiunW8c8QsmHC31OfIPYzjrxqF+3yh Y X-Received: by 2002:a17:907:174d:b0:a58:dd06:b8bb with SMTP id lf13-20020a170907174d00b00a58dd06b8bbmr1867268ejc.70.1714750636493; Fri, 03 May 2024 08:37:16 -0700 (PDT) Received: from m1x-phil.lan ([176.176.179.187]) by smtp.gmail.com with ESMTPSA id lb24-20020a170906add800b00a58de09fd92sm1816023ejb.27.2024.05.03.08.37.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 03 May 2024 08:37:16 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org, Paul Cercueil , Richard Henderson , Yoshinori Sato Subject: [PULL 11/14] target/sh4: Fix SUBV opcode Date: Fri, 3 May 2024 17:36:10 +0200 Message-ID: <20240503153613.38709-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240503153613.38709-1-philmd@linaro.org> References: <20240503153613.38709-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=philmd@linaro.org; helo=mail-ej1-x631.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: SUBV Rm, Rn Rn - Rm -> Rn, underflow -> T The overflow / underflow can be calculated as: T = ((Rn ^ Rm) & (Result ^ Rn)) >> 31 However we were using the incorrect: T = ((Rn ^ Rm) & (Result ^ Rm)) >> 31 Fix by using the Rn register instead of Rm. 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 Suggested-by: Paul Cercueil Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2318 Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Yoshinori Sato Message-Id: <20240430163125.77430-3-philmd@linaro.org> --- 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 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 = tcg_temp_new(); tcg_gen_sub_i32(t0, REG(B11_8), REG(B7_4)); t1 = tcg_temp_new(); - tcg_gen_xor_i32(t1, t0, REG(B7_4)); + tcg_gen_xor_i32(t1, t0, REG(B11_8)); t2 = 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..a3c2db96e4 --- /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 carry) +{ + int o = a, c; + + asm volatile("subv %2,%0\n" + "movt %1\n" + : "+r"(o), "=r"(c) : "r"(b) : ); + + if (c != carry || o != res) { + printf("SUBV %d, %d = %d/%d [T = %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 += test-macw test-addv: CFLAGS += -O -g TESTS += test-addv + +test-subv: CFLAGS += -O -g +TESTS += test-subv