From nobody Sat May 10 02:34:49 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=fail  header.i=@wdc.com;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=fail(p=none dis=none)  header.from=wdc.com
ARC-Seal: i=1; a=rsa-sha256; t=1620729529; cv=none;
	d=zohomail.com; s=zohoarc;
	b=h4nDDzfoyouEAcR10k1qthobao6AzecHSHtJpaUp8rHyeW1zyKEzleKggbNt3Iz1dCAWuKMcICAaQNundb4lg6mdz0mMs0aVu5CSeLurR/7tfiYsCNu3T1mCD0qrUYxKximjQIalk3t987xiCukNAQ8BWirAIycutlLB26eTcnI=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1620729529;
 h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To;
	bh=/vOurlA3z9/CGAOd0/OpoSDGU450NAibZQtKBeb2U2A=;
	b=JshbmHpwPa7TGxpoIlktsLgM+GAqllTRiaXoTAh9QM39b+huMBLexaj1QP3hvjXwyCtQAC/kSq7YHDvNAvY8uJFAkvy4Uy5HaKPHhy1LCP8z4yjPMSse/QGrTdwXh47XAJGoy+F1CLnKDMebzeggfn45lrfRT/HgPAw6G5jkvaE=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=fail  header.i=@wdc.com;
	spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as
 permitted sender)
  smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org;
	dmarc=fail header.from=<alistair.francis@wdc.com> (p=none dis=none)
 header.from=<alistair.francis@wdc.com>
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 162072952976040.081687472452586;
 Tue, 11 May 2021 03:38:49 -0700 (PDT)
Received: from localhost ([::1]:46544 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1lgPmq-0005gt-DJ
	for importer@patchew.org; Tue, 11 May 2021 06:38:48 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:38084)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1)
 (envelope-from <prvs=7584e029c=alistair.francis@wdc.com>)
 id 1lgPWC-0000yx-4r
 for qemu-devel@nongnu.org; Tue, 11 May 2021 06:21:36 -0400
Received: from esa5.hgst.iphmx.com ([216.71.153.144]:41095)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1)
 (envelope-from <prvs=7584e029c=alistair.francis@wdc.com>)
 id 1lgPW3-0006TG-H5
 for qemu-devel@nongnu.org; Tue, 11 May 2021 06:21:35 -0400
Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com)
 ([199.255.45.14])
 by ob1.hgst.iphmx.com with ESMTP; 11 May 2021 18:20:59 +0800
Received: from uls-op-cesaip01.wdc.com ([10.248.3.36])
 by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 11 May 2021 03:00:59 -0700
Received: from unknown (HELO alistair-risc6-laptop.wdc.com) ([10.225.165.48])
 by uls-op-cesaip01.wdc.com with ESMTP; 11 May 2021 03:20:58 -0700
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple;
 d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com;
 t=1620728485; x=1652264485;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=eBNCyqtOfzNeogyxUlf2PGSAY8yQsr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cd8
 s68ipQAzaL/DKsecsozGRAR+
IronPort-SDR: 
 kui9oBkgCzOZVHXy/ensks9+ME4FPk+Dd03eXRbifl0x6wVGxWFmsn4W5NM4F2JFBIB9HiVtbg
 Sd8i1C9ofmqpFR63fm916qX+ANyGy3cDirlr4MHZhxzfJgVkBWK/JqXU87QXXVz3F5fIciN5yx
 GWk2wlp70cnQNJmhab/z4vGPIbJpRxYdvc280NCl83EzOGJjRi6ksIo+xz/5vbaO3TCdL7TNCL
 IGPYU+ZiI0frCliTJY/3RxFJUicREeWSQuTgFnMDskjeTns1SK6OHokaSTikjg3aFhBesxH/wv
 AoQ=
WDCIronportException: Internal
From: Alistair Francis <alistair.francis@wdc.com>
To: peter.maydell@linaro.org
Subject: [PULL v3 18/42] target/riscv: Fixup saturate subtract function
Date: Tue, 11 May 2021 20:19:27 +1000
Message-Id: <20210511101951.165287-19-alistair.francis@wdc.com>
X-Mailer: git-send-email 2.31.1
In-Reply-To: <20210511101951.165287-1-alistair.francis@wdc.com>
References: <20210511101951.165287-1-alistair.francis@wdc.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17
 as permitted sender) client-ip=209.51.188.17;
 envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org;
 helo=lists.gnu.org;
Received-SPF: pass client-ip=216.71.153.144;
 envelope-from=prvs=7584e029c=alistair.francis@wdc.com;
 helo=esa5.hgst.iphmx.com
X-Spam_score_int: -27
X-Spam_score: -2.8
X-Spam_bar: --
X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: alistair23@gmail.com, Alistair Francis <alistair.francis@wdc.com>,
 Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org,
 LIU Zhiwei <zhiwei_liu@c-sky.com>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: fail (Header signature does not verify)
Content-Type: text/plain; charset="utf-8"

From: LIU Zhiwei <zhiwei_liu@c-sky.com>

The overflow predication ((a - b) ^ a) & (a ^ b) & INT64_MIN is right.
However, when the predication is ture and a is 0, it should return maximum.

Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-id: 20210212150256.885-4-zhiwei_liu@c-sky.com
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
 target/riscv/vector_helper.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
index a156573d28..356cef8a09 100644
--- a/target/riscv/vector_helper.c
+++ b/target/riscv/vector_helper.c
@@ -2451,7 +2451,7 @@ static inline int8_t ssub8(CPURISCVState *env, int vx=
rm, int8_t a, int8_t b)
 {
     int8_t res =3D a - b;
     if ((res ^ a) & (a ^ b) & INT8_MIN) {
-        res =3D a > 0 ? INT8_MAX : INT8_MIN;
+        res =3D a >=3D 0 ? INT8_MAX : INT8_MIN;
         env->vxsat =3D 0x1;
     }
     return res;
@@ -2461,7 +2461,7 @@ static inline int16_t ssub16(CPURISCVState *env, int =
vxrm, int16_t a, int16_t b)
 {
     int16_t res =3D a - b;
     if ((res ^ a) & (a ^ b) & INT16_MIN) {
-        res =3D a > 0 ? INT16_MAX : INT16_MIN;
+        res =3D a >=3D 0 ? INT16_MAX : INT16_MIN;
         env->vxsat =3D 0x1;
     }
     return res;
@@ -2471,7 +2471,7 @@ static inline int32_t ssub32(CPURISCVState *env, int =
vxrm, int32_t a, int32_t b)
 {
     int32_t res =3D a - b;
     if ((res ^ a) & (a ^ b) & INT32_MIN) {
-        res =3D a > 0 ? INT32_MAX : INT32_MIN;
+        res =3D a >=3D 0 ? INT32_MAX : INT32_MIN;
         env->vxsat =3D 0x1;
     }
     return res;
@@ -2481,7 +2481,7 @@ static inline int64_t ssub64(CPURISCVState *env, int =
vxrm, int64_t a, int64_t b)
 {
     int64_t res =3D a - b;
     if ((res ^ a) & (a ^ b) & INT64_MIN) {
-        res =3D a > 0 ? INT64_MAX : INT64_MIN;
+        res =3D a >=3D 0 ? INT64_MAX : INT64_MIN;
         env->vxsat =3D 0x1;
     }
     return res;
--=20
2.31.1