From nobody Sat Jul 12 15:16:24 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486014394047596.2733155675928; Wed, 1 Feb 2017 21:46:34 -0800 (PST) Received: from localhost ([::1]:54370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZAE3-0003fF-KE for importer@patchew.org; Thu, 02 Feb 2017 00:46:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZ9jm-0007Iv-5z for qemu-devel@nongnu.org; Thu, 02 Feb 2017 00:15:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZ9ji-0003ef-Rk for qemu-devel@nongnu.org; Thu, 02 Feb 2017 00:15:14 -0500 Received: from ozlabs.org ([103.22.144.67]:43709) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZ9ji-0003ao-Cc; Thu, 02 Feb 2017 00:15:10 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3vDSqP2nX4z9s7g; Thu, 2 Feb 2017 16:14:55 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1486012497; bh=amEd7Mf9K+0Kcjao219sc1FMgRUWgFP0k46/14D53kk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0qDAsDwOdThV3yHvE4TJKPAxOdp8jQzVMwEK+Sl4HvJk9vXlLuZf1XnsBMmdvaPE LhUthd4QKAnmstMsSgzgcjC/czKynMReHGj3WZ/ylP0AMniqMpcigtJuSb5SLDMsHM Fus6z2scEW1Njci9KltOIKU/q88xJ4qz+GbLMOg0= From: David Gibson To: peter.maydell@linaro.org Date: Thu, 2 Feb 2017 16:13:21 +1100 Message-Id: <20170202051445.5735-24-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170202051445.5735-1-david@gibson.dropbear.id.au> References: <20170202051445.5735-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 023/107] target-ppc: Implement bcd_is_valid function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, Jose Ricardo Ziviani , mdroth@linux.vnet.ibm.com, agraf@suse.de, aik@ozlabs.ru, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jose Ricardo Ziviani A function to check if all digits of a given BCD number is valid is here presented because more instructions will need to reuse the same code. Signed-off-by: Jose Ricardo Ziviani Signed-off-by: David Gibson --- target/ppc/int_helper.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index a33b18b..14eb4e4 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -2564,6 +2564,24 @@ static void bcd_put_digit(ppc_avr_t *bcd, uint8_t di= git, int n) } } =20 +static bool bcd_is_valid(ppc_avr_t *bcd) +{ + int i; + int invalid =3D 0; + + if (bcd_get_sgn(bcd) =3D=3D 0) { + return false; + } + + for (i =3D 1; i < 32; i++) { + bcd_get_digit(bcd, i, &invalid); + if (unlikely(invalid)) { + return false; + } + } + return true; +} + static int bcd_cmp_zero(ppc_avr_t *bcd) { if (bcd->u64[HI_IDX] =3D=3D 0 && (bcd->u64[LO_IDX] >> 4) =3D=3D 0) { @@ -2981,18 +2999,13 @@ uint32_t helper_bcdcpsgn(ppc_avr_t *r, ppc_avr_t *a= , ppc_avr_t *b, uint32_t ps) =20 uint32_t helper_bcdsetsgn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) { - int i; - int invalid =3D 0; int sgnb =3D bcd_get_sgn(b); =20 *r =3D *b; bcd_put_digit(r, bcd_preferred_sgn(sgnb, ps), 0); =20 - for (i =3D 1; i < 32; i++) { - bcd_get_digit(b, i, &invalid); - if (unlikely(invalid)) { - return CRF_SO; - } + if (bcd_is_valid(b) =3D=3D false) { + return CRF_SO; } =20 return bcd_cmp_zero(r); --=20 2.9.3