From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3xLe-0006FW-QR for qemu-devel@nongnu.org; Mon, 07 Nov 2016 22:45:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3xLb-00060N-Nd for qemu-devel@nongnu.org; Mon, 07 Nov 2016 22:45:22 -0500 Date: Tue, 8 Nov 2016 14:29:43 +1100 From: David Gibson Message-ID: <20161108032943.GH28688@umbus.fritz.box> References: <1478013888-22242-1-git-send-email-joserz@linux.vnet.ibm.com> <1478013888-22242-5-git-send-email-joserz@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="AqCDj3hiknadvR6t" Content-Disposition: inline In-Reply-To: <1478013888-22242-5-git-send-email-joserz@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v4 4/4] target-ppc: Implement bcdctz. instruction List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jose Ricardo Ziviani Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, nikunj@linux.vnet.ibm.com, bharata@linux.vnet.ibm.com --AqCDj3hiknadvR6t Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Nov 01, 2016 at 01:24:48PM -0200, Jose Ricardo Ziviani wrote: > bcdctz. converts from BCD to Zoned numeric format. Zoned format uses > a byte to represent a digit where the most significant nibble is 0x3 > or 0xf, depending on the preferred signal. >=20 > Signed-off-by: Jose Ricardo Ziviani > --- > target-ppc/helper.h | 1 + > target-ppc/int_helper.c | 49 +++++++++++++++++++++++++++++++= ++++++ > target-ppc/translate/vmx-impl.inc.c | 7 ++++++ > 3 files changed, 57 insertions(+) >=20 > diff --git a/target-ppc/helper.h b/target-ppc/helper.h > index 8546bb9..5412da5 100644 > --- a/target-ppc/helper.h > +++ b/target-ppc/helper.h > @@ -374,6 +374,7 @@ DEF_HELPER_4(bcdsub, i32, avr, avr, avr, i32) > 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) > =20 > 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 c546a9a..5983a32 100644 > --- a/target-ppc/int_helper.c > +++ b/target-ppc/int_helper.c > @@ -2774,6 +2774,55 @@ uint32_t helper_bcdcfz(ppc_avr_t *r, ppc_avr_t *b,= uint32_t ps) > return cr; > } > =20 > +uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) > +{ > + int i; > + int j; > + int cr =3D 0; > + uint8_t digit =3D 0; > + int sgnb =3D bcd_get_sgn(b); > + int zone_lead =3D (ps) ? 0xF0 : 0x30; > + int invalid =3D (sgnb =3D=3D 0); > + ppc_avr_t ret =3D { .u64 =3D { 0, 0 } }; > + > + int eq_flag =3D (b->u64[HI_IDX] =3D=3D 0) && ((b->u64[LO_IDX] >> 4) = =3D=3D 0); > + int ox_flag =3D ((b->u64[HI_IDX] >> 4) !=3D 0); As in 2/4 you can simplify this by using bcd_cmp_zero(). > + > + for (i =3D 0, j =3D 1; i < 32; i +=3D 2, j++) { And you can reduce this to a single loop variable. > + digit =3D bcd_get_digit(b, j, &invalid); > + > + if (unlikely(invalid)) { > + break; > + } > + > + ret.u8[BCD_DIG_BYTE(i)] =3D zone_lead + digit; > + } > + > + if (ps) { > + bcd_put_digit(&ret, (sgnb =3D=3D 1) ? 0xC : 0xD, 1); > + } else { > + bcd_put_digit(&ret, (sgnb =3D=3D 1) ? 0x3 : 0x7, 1); > + } > + > + if (!eq_flag) { > + cr =3D (sgnb =3D=3D 1) ? 1 << CRF_GT : 1 << CRF_LT; > + } else { > + cr =3D 1 << CRF_EQ; > + } > + > + if (ox_flag) { > + cr |=3D 1 << CRF_SO; > + } > + > + if (unlikely(invalid)) { > + cr =3D 1 << CRF_SO; > + } > + > + *r =3D 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/v= mx-impl.inc.c > index 7e902a9..b05c874 100644 > --- a/target-ppc/translate/vmx-impl.inc.c > +++ b/target-ppc/translate/vmx-impl.inc.c > @@ -973,10 +973,14 @@ GEN_BCD(bcdsub) > GEN_BCD2(bcdcfn) > GEN_BCD2(bcdctn) > GEN_BCD2(bcdcfz) > +GEN_BCD2(bcdctz) > =20 > static void gen_xpnd04_1(DisasContext *ctx) > { > switch (opc4(ctx->opcode)) { > + case 4: > + gen_bcdctz(ctx); > + break; > case 5: > gen_bcdctn(ctx); > break; > @@ -995,6 +999,9 @@ static void gen_xpnd04_1(DisasContext *ctx) > static void gen_xpnd04_2(DisasContext *ctx) > { > switch (opc4(ctx->opcode)) { > + case 4: > + gen_bcdctz(ctx); > + break; > case 6: > gen_bcdcfz(ctx); > break; --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --AqCDj3hiknadvR6t Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYIUamAAoJEGw4ysog2bOSJBMP/0qw2G6E5kNg5CuBbTM5+yf4 sbtDNdENuhvlOux9LGrjc14QULlPg6CqHgyHy+yFqwDcugSELbHIIFWYFlynzOL7 gNIDEcVc/LB9uzjlDTjiuLzCd9RRgU87zme9SJ6IiNw+ke5teNf7j+TqJo3mZZkE gt6jql6itZRgxBZvfdKAI2A5Ko8b+vhl3r7dgkq4TZSX5OuFFSRbZEXbclOZhiUv LQyhF9xtD38cy6D2JxVIy/BrXLVHIdOA1mbXE1dEtsMsmRS04HBcAMPkWZ/yYNFU GolwDadAATHX2Azfx3X/YVKFEX+5jg8fZn+PDiP2JdjWTVzfQoybvvGR3hUYamm+ vC/MGXKU8pLld8YUfKS/RrsCtUlEvWE1+Z3yidadU34JjB6hNlLQwFCiPlA2xOjN igIGsoHSXEo48veW1Ncev7uX40duZr67xK2X2RVSBIW4h/oiLNCb8sCG/X4lZaKY MclJT1xcDR0MQZ75e3KqG+Lr3Co9anxZhpFUAROeOpzdCPxonikH691uwL8lftL0 /Db2Q0QRl3DCAMATxoSYnvx+9jkxtlFXRN4lfCG9iQROBj8c9ctLZvgSHovNNJyf sXb9ydfkLrAUTUoTDOSogX2MD0eCvFAmjHr1eQ4AHmgCytZLtihLh++jTyboa17W memIDEBWq1+4qqbmNrgu =9o4g -----END PGP SIGNATURE----- --AqCDj3hiknadvR6t--