From patchwork Thu Feb 2 05:13:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 722771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vDTWL0QrZz9ryv for ; Thu, 2 Feb 2017 16:46:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.b="U0qDAsDw"; dkim-atps=neutral Received: from localhost ([::1]:54370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZADa-0003fF-BS for incoming@patchwork.ozlabs.org; Thu, 02 Feb 2017 00:46:02 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 digit, int n) } } +static bool bcd_is_valid(ppc_avr_t *bcd) +{ + int i; + int invalid = 0; + + if (bcd_get_sgn(bcd) == 0) { + return false; + } + + for (i = 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] == 0 && (bcd->u64[LO_IDX] >> 4) == 0) { @@ -2981,18 +2999,13 @@ uint32_t helper_bcdcpsgn(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) uint32_t helper_bcdsetsgn(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) { - int i; - int invalid = 0; int sgnb = bcd_get_sgn(b); *r = *b; bcd_put_digit(r, bcd_preferred_sgn(sgnb, ps), 0); - for (i = 1; i < 32; i++) { - bcd_get_digit(b, i, &invalid); - if (unlikely(invalid)) { - return CRF_SO; - } + if (bcd_is_valid(b) == false) { + return CRF_SO; } return bcd_cmp_zero(r);