From nobody Sun Feb 8 20:13:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1648053795; cv=none; d=zohomail.com; s=zohoarc; b=C6vprcTm1/413p4IZOC2Iqo31FgiX8KM6l80asgMMhMcbc6Gym47Y99MIj2ZHZRDmCkBkVW1Xa1m3QcoCWc3G+E2zs5lxZnguTkAeTx/FjLbZWjVC21kPjHuq6zSamkm+QPq49JhXciI9IaOzyQD30Lmmo+nVeAad5seVHBrdes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648053795; h=Content-Type: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=AMdJ3RUKWs8EouPEYWjz5BDHAJ7RA4XRurAaCGHvQTA=; b=gdNYv6CS8S/zs5nalHC9spZnjXCunM3FW1ih0GknUswNIXNANY5YakW03g8HQ0LggCJHTuruA6rLAYMTHbl7kZ14s7SqIMNXUtOtQwB1sKwB9B2KZjSMAMD1JAO3R/kcCFZyfWt1SFHqbStwtOSgMJKAAqk0YzwJTkxM7ylc8Jk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1648053795073789.8314753909162; Wed, 23 Mar 2022 09:43:15 -0700 (PDT) Received: from localhost ([::1]:33680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nX44o-00032C-36 for importer@patchew.org; Wed, 23 Mar 2022 12:43:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nX3oo-0000vJ-G8 for qemu-devel@nongnu.org; Wed, 23 Mar 2022 12:26:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26451) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nX3om-0000Fb-ID for qemu-devel@nongnu.org; Wed, 23 Mar 2022 12:26:42 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-198-vawnbkdFMoGWPEpsh-GO6A-1; Wed, 23 Mar 2022 12:26:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2E2863801EC1; Wed, 23 Mar 2022 16:26:36 +0000 (UTC) Received: from thuth.com (unknown [10.39.193.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC6C1112132C; Wed, 23 Mar 2022 16:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648052799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AMdJ3RUKWs8EouPEYWjz5BDHAJ7RA4XRurAaCGHvQTA=; b=PFGY4a7Vw3cdzvli/wUi9McJRb9d2Kckj/4jQalpFbivJ0LW8DscNPZ3hEqKWcNC6fFKPA 0IisRVWxuoFkTJfVS5ehOEj3sVjOlak2KQt/Zl0GR3sPlxWzqZfp8EPlW1UD+t6HctAAWa PihtBdirmgPjXlVC2gvPBa8wlm+gNls= X-MC-Unique: vawnbkdFMoGWPEpsh-GO6A-1 From: Thomas Huth To: Richard Henderson , David Hildenbrand , qemu-devel@nongnu.org Subject: [PATCH 1/2] target/s390x: Fix determination of overflow condition code after addition Date: Wed, 23 Mar 2022 17:26:20 +0100 Message-Id: <20220323162621.139313-2-thuth@redhat.com> In-Reply-To: <20220323162621.139313-1-thuth@redhat.com> References: <20220323162621.139313-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: qemu-s390x@nongnu.org, Bruno Haible Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1648053797156100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This program currently prints different results when run with TCG instead of running on real s390x hardware: #include int overflow_32 (int x, int y) { int sum; return ! __builtin_add_overflow (x, y, &sum); } int overflow_64 (long long x, long long y) { long sum; return ! __builtin_add_overflow (x, y, &sum); } int a1 =3D -2147483648; int b1 =3D -2147483648; long long a2 =3D -9223372036854775808L; long long b2 =3D -9223372036854775808L; int main () { { int a =3D a1; int b =3D b1; printf ("a =3D 0x%x, b =3D 0x%x\n", a, b); printf ("no_overflow =3D %d\n", overflow_32 (a, b)); } { long long a =3D a2; long long b =3D b2; printf ("a =3D 0x%llx, b =3D 0x%llx\n", a, b); printf ("no_overflow =3D %d\n", overflow_64 (a, b)); } } Resolves: https://gitlab.com/qemu-project/qemu/-/issues/616 Suggested-by: Bruno Haible Signed-off-by: Thomas Huth --- target/s390x/tcg/cc_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/s390x/tcg/cc_helper.c b/target/s390x/tcg/cc_helper.c index 8d04097f78..e11cdb745d 100644 --- a/target/s390x/tcg/cc_helper.c +++ b/target/s390x/tcg/cc_helper.c @@ -136,7 +136,7 @@ static uint32_t cc_calc_subu(uint64_t borrow_out, uint6= 4_t result) =20 static uint32_t cc_calc_add_64(int64_t a1, int64_t a2, int64_t ar) { - if ((a1 > 0 && a2 > 0 && ar < 0) || (a1 < 0 && a2 < 0 && ar > 0)) { + if ((a1 > 0 && a2 > 0 && ar < 0) || (a1 < 0 && a2 < 0 && ar >=3D 0)) { return 3; /* overflow */ } else { if (ar < 0) { @@ -196,7 +196,7 @@ static uint32_t cc_calc_comp_64(int64_t dst) =20 static uint32_t cc_calc_add_32(int32_t a1, int32_t a2, int32_t ar) { - if ((a1 > 0 && a2 > 0 && ar < 0) || (a1 < 0 && a2 < 0 && ar > 0)) { + if ((a1 > 0 && a2 > 0 && ar < 0) || (a1 < 0 && a2 < 0 && ar >=3D 0)) { return 3; /* overflow */ } else { if (ar < 0) { --=20 2.27.0 From nobody Sun Feb 8 20:13:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1648053524; cv=none; d=zohomail.com; s=zohoarc; b=P15KiEzO5FoT0/UN3Rcy06HEoBZlgSt7Tyd1TaAjUZH29/vJKzJX78TDiNp9afF1sG78yxl5U/xAM2Dut0B/2HJ0wiKH/pbnpa38+0GoQ4+PIRRHHPoZ9K0UVNYAV5qphgCjenCFuom9K1scrcCUA2dR1DCUP0vjO9CWhBOU9NU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648053524; h=Content-Type: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=sZJ6F7zwz3JUQnoV5gayNRArGMWPnCyzZnB8tAet9JY=; b=OGD+M8apRRrIuAssPnOxMMh6AafQc1f3+Vg03kSjEcr7pfPKF6p/KWg+1prfCbyncZ35OKsSNsf0lVT9sIWz7dQG5ad515S1mUTFMZcbM+4yusXHPhbPqHolafAwqKiY02mwX/DjONPgMXWSUiQtja85Q2X9xBrGMcq8XbTmuF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16480535240671005.6888784165377; Wed, 23 Mar 2022 09:38:44 -0700 (PDT) Received: from localhost ([::1]:51046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nX40Q-00041j-P6 for importer@patchew.org; Wed, 23 Mar 2022 12:38:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nX3oq-0000vM-5n for qemu-devel@nongnu.org; Wed, 23 Mar 2022 12:26:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nX3oo-0000G6-27 for qemu-devel@nongnu.org; Wed, 23 Mar 2022 12:26:43 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-503-O62v7gW4N9yAJG_HcKY1zQ-1; Wed, 23 Mar 2022 12:26:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E21D285A5BC; Wed, 23 Mar 2022 16:26:37 +0000 (UTC) Received: from thuth.com (unknown [10.39.193.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CD08112132C; Wed, 23 Mar 2022 16:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648052801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sZJ6F7zwz3JUQnoV5gayNRArGMWPnCyzZnB8tAet9JY=; b=PDctRmfWCW2UoHYoLTfiBo67pAgSV9eYnpM6bPmj9SyBd8c6yYPHisH3MzcLhfkIIJk4Ud 31MoOATU0KivyG5hxbNA1FiUK1G+E6pvFEBAB3P0V7bP9eIqYVoIYvKvsFGzOJppJ45Ssi vj/glga7n+aK+70zwYtKRggacQy7Q8s= X-MC-Unique: O62v7gW4N9yAJG_HcKY1zQ-1 From: Thomas Huth To: Richard Henderson , David Hildenbrand , qemu-devel@nongnu.org Subject: [PATCH 2/2] target/s390x: Fix determination of overflow condition code after subtraction Date: Wed, 23 Mar 2022 17:26:21 +0100 Message-Id: <20220323162621.139313-3-thuth@redhat.com> In-Reply-To: <20220323162621.139313-1-thuth@redhat.com> References: <20220323162621.139313-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: qemu-s390x@nongnu.org, Bruno Haible Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1648053524627100001 Content-Type: text/plain; charset="utf-8" Reported by Paul Eggert in https://lists.gnu.org/archive/html/bug-gnulib/2021-09/msg00050.html This program currently prints different results when run with TCG instead of running on real s390x hardware: #include int overflow_32 (int x, int y) { int sum; return __builtin_sub_overflow (x, y, &sum); } int overflow_64 (long long x, long long y) { long sum; return __builtin_sub_overflow (x, y, &sum); } int a1 =3D 0; int b1 =3D -2147483648; long long a2 =3D 0L; long long b2 =3D -9223372036854775808L; int main () { { int a =3D a1; int b =3D b1; printf ("a =3D 0x%x, b =3D 0x%x\n", a, b); printf ("no_overflow =3D %d\n", ! overflow_32 (a, b)); } { long long a =3D a2; long long b =3D b2; printf ("a =3D 0x%llx, b =3D 0x%llx\n", a, b); printf ("no_overflow =3D %d\n", ! overflow_64 (a, b)); } } Resolves: https://gitlab.com/qemu-project/qemu/-/issues/618 Suggested-by: Bruno Haible Signed-off-by: Thomas Huth --- target/s390x/tcg/cc_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/s390x/tcg/cc_helper.c b/target/s390x/tcg/cc_helper.c index e11cdb745d..b2e8d3d9f5 100644 --- a/target/s390x/tcg/cc_helper.c +++ b/target/s390x/tcg/cc_helper.c @@ -151,7 +151,7 @@ static uint32_t cc_calc_add_64(int64_t a1, int64_t a2, = int64_t ar) =20 static uint32_t cc_calc_sub_64(int64_t a1, int64_t a2, int64_t ar) { - if ((a1 > 0 && a2 < 0 && ar < 0) || (a1 < 0 && a2 > 0 && ar > 0)) { + if ((a1 >=3D 0 && a2 < 0 && ar < 0) || (a1 < 0 && a2 > 0 && ar > 0)) { return 3; /* overflow */ } else { if (ar < 0) { @@ -211,7 +211,7 @@ static uint32_t cc_calc_add_32(int32_t a1, int32_t a2, = int32_t ar) =20 static uint32_t cc_calc_sub_32(int32_t a1, int32_t a2, int32_t ar) { - if ((a1 > 0 && a2 < 0 && ar < 0) || (a1 < 0 && a2 > 0 && ar > 0)) { + if ((a1 >=3D 0 && a2 < 0 && ar < 0) || (a1 < 0 && a2 > 0 && ar > 0)) { return 3; /* overflow */ } else { if (ar < 0) { --=20 2.27.0