From patchwork Wed Nov 16 20:07:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Ricardo Ziviani X-Patchwork-Id: 695832 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 3tJx3P3VMkz9sBR for ; Thu, 17 Nov 2016 07:40:33 +1100 (AEDT) Received: from localhost ([::1]:54749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c770Q-0007b4-FD for incoming@patchwork.ozlabs.org; Wed, 16 Nov 2016 15:40:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c76V0-0006AE-Jw for qemu-devel@nongnu.org; Wed, 16 Nov 2016 15:08:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c76Ux-0003nI-DS for qemu-devel@nongnu.org; Wed, 16 Nov 2016 15:08:02 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58010) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c76Ux-0003nC-4w for qemu-devel@nongnu.org; Wed, 16 Nov 2016 15:07:59 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAGK4Bai127954 for ; Wed, 16 Nov 2016 15:07:58 -0500 Received: from e24smtp03.br.ibm.com (e24smtp03.br.ibm.com [32.104.18.24]) by mx0a-001b2d01.pphosted.com with ESMTP id 26rvx2kjjf-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 16 Nov 2016 15:07:58 -0500 Received: from localhost by e24smtp03.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 Nov 2016 18:07:55 -0200 Received: from d24dlp02.br.ibm.com (9.18.248.206) by e24smtp03.br.ibm.com (10.172.0.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 16 Nov 2016 18:07:53 -0200 Received: from d24relay02.br.ibm.com (d24relay02.br.ibm.com [9.18.232.42]) by d24dlp02.br.ibm.com (Postfix) with ESMTP id 4DE371DC0029; Wed, 16 Nov 2016 15:07:53 -0500 (EST) Received: from d24av04.br.ibm.com (d24av04.br.ibm.com [9.8.31.97]) by d24relay02.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uAGK7rUP14155946; Wed, 16 Nov 2016 18:07:53 -0200 Received: from d24av04.br.ibm.com (localhost [127.0.0.1]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id uAGK7qDF003302; Wed, 16 Nov 2016 18:07:53 -0200 Received: from pacoca.ibm.com ([9.85.153.183]) by d24av04.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id uAGK7coE003052; Wed, 16 Nov 2016 18:07:50 -0200 From: Jose Ricardo Ziviani To: qemu-ppc@nongnu.org Date: Wed, 16 Nov 2016 18:07:27 -0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479326850-8369-1-git-send-email-joserz@linux.vnet.ibm.com> References: <1479326850-8369-1-git-send-email-joserz@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111620-0024-0000-0000-0000012B0847 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111620-0025-0000-0000-000015EEC90A Message-Id: <1479326850-8369-2-git-send-email-joserz@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-16_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611160299 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH 1/4] target-ppc: Implement bcdcfsq. instruction 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: bharata@linux.vnet.ibm.com, qemu-devel@nongnu.org, nikunj@linux.vnet.ibm.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" bcdcfsq.: Decimal convert from signed quadword. It is possible to convert values less than 10^31-1 or greater than -10^31-1 to be represented in packed decimal format. Signed-off-by: Jose Ricardo Ziviani --- target-ppc/helper.h | 1 + target-ppc/int_helper.c | 48 +++++++++++++++++++++++++++++++++++++ target-ppc/translate/vmx-impl.inc.c | 7 ++++++ 3 files changed, 56 insertions(+) diff --git a/target-ppc/helper.h b/target-ppc/helper.h index da00f0a..87f533c 100644 --- a/target-ppc/helper.h +++ b/target-ppc/helper.h @@ -382,6 +382,7 @@ DEF_HELPER_3(bcdcfn, i32, avr, avr, i32) DEF_HELPER_3(bcdctn, i32, avr, avr, i32) DEF_HELPER_3(bcdcfz, i32, avr, avr, i32) DEF_HELPER_3(bcdctz, i32, avr, avr, i32) +DEF_HELPER_3(bcdcfsq, i32, avr, avr, i32) DEF_HELPER_2(xsadddp, void, env, i32) DEF_HELPER_2(xssubdp, void, env, i32) diff --git a/target-ppc/int_helper.c b/target-ppc/int_helper.c index 9ac204a..db65a51 100644 --- a/target-ppc/int_helper.c +++ b/target-ppc/int_helper.c @@ -2874,6 +2874,54 @@ uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) return cr; } +uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) +{ + int i; + int cr = 0; + int ox_flag = 0; + uint64_t digit = 0; + uint64_t carry = 0; + uint64_t lo_value = 0; + uint64_t hi_value = 0; + uint64_t max = ULLONG_MAX; + ppc_avr_t ret = { .u64 = { 0, 0 } }; + + if (b->s64[HI_IDX] < 0) { + hi_value = -b->s64[HI_IDX]; + lo_value = b->s64[LO_IDX]; + bcd_put_digit(&ret, 0xD, 0); + } else if (b->s64[HI_IDX] == 0 && b->s64[LO_IDX] < 0) { + lo_value = -b->s64[LO_IDX]; + bcd_put_digit(&ret, 0xD, 0); + } else { + hi_value = b->s64[HI_IDX]; + lo_value = b->s64[LO_IDX]; + bcd_put_digit(&ret, bcd_preferred_sgn(0, ps), 0); + } + + if (unlikely(hi_value > 0x7e37be2022)) { + ox_flag = 1; + } + + carry = hi_value; + for (i = 0; i < 32; i++, max /= 10, lo_value /= 10) { + digit = ((max % 10) * hi_value) + (lo_value % 10) + carry; + carry = (digit > 9) ? digit / 10 : 0; + + bcd_put_digit(&ret, (carry) ? digit % 10 : digit, i + 1); + } + + cr = bcd_cmp_zero(&ret); + + if (unlikely(ox_flag)) { + cr |= 1 << CRF_SO; + } + + *r = ret; + + return cr; +} + void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a) { int i; diff --git a/target-ppc/translate/vmx-impl.inc.c b/target-ppc/translate/vmx-impl.inc.c index 7143eb3..36141e5 100644 --- a/target-ppc/translate/vmx-impl.inc.c +++ b/target-ppc/translate/vmx-impl.inc.c @@ -989,10 +989,14 @@ GEN_BCD2(bcdcfn) GEN_BCD2(bcdctn) GEN_BCD2(bcdcfz) GEN_BCD2(bcdctz) +GEN_BCD2(bcdcfsq) static void gen_xpnd04_1(DisasContext *ctx) { switch (opc4(ctx->opcode)) { + case 2: + gen_bcdcfsq(ctx); + break; case 4: gen_bcdctz(ctx); break; @@ -1014,6 +1018,9 @@ static void gen_xpnd04_1(DisasContext *ctx) static void gen_xpnd04_2(DisasContext *ctx) { switch (opc4(ctx->opcode)) { + case 2: + gen_bcdcfsq(ctx); + break; case 4: gen_bcdctz(ctx); break;