From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9iqF-0001Pe-GL for qemu-devel@nongnu.org; Wed, 23 Nov 2016 20:28:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c9iqE-0005S9-9c for qemu-devel@nongnu.org; Wed, 23 Nov 2016 20:28:47 -0500 Date: Thu, 24 Nov 2016 12:20:35 +1100 From: David Gibson Message-ID: <20161124012035.GM17795@umbus.fritz.box> References: <1479918105-15616-1-git-send-email-joserz@linux.vnet.ibm.com> <1479918105-15616-2-git-send-email-joserz@linux.vnet.ibm.com> <8988b8ba-85fb-3382-5191-440ed8405a52@twiddle.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4oQnj4jcM03NhqPN" Content-Disposition: inline In-Reply-To: <8988b8ba-85fb-3382-5191-440ed8405a52@twiddle.net> Subject: Re: [Qemu-devel] [PATCH v2 1/4] target-ppc: Implement bcdcfsq. instruction List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: Jose Ricardo Ziviani , qemu-ppc@nongnu.org, bharata@linux.vnet.ibm.com, qemu-devel@nongnu.org, nikunj@linux.vnet.ibm.com --4oQnj4jcM03NhqPN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 24, 2016 at 01:43:18AM +0100, Richard Henderson wrote: > On 11/23/2016 05:21 PM, Jose Ricardo Ziviani wrote: > > bcdcfsq.: Decimal convert from signed quadword. It is not possible > > to convert values less than 10^31-1 or greater than -10^31-1 to be > > represented in packed decimal format. > >=20 > > Signed-off-by: Jose Ricardo Ziviani > > --- > > target-ppc/helper.h | 1 + > > target-ppc/int_helper.c | 45 +++++++++++++++++++++++++++++= ++++++++ > > target-ppc/translate/vmx-impl.inc.c | 7 ++++++ > > 3 files changed, 53 insertions(+) > >=20 > > 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) > >=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 8886a72..751909c 100644 > > --- a/target-ppc/int_helper.c > > +++ b/target-ppc/int_helper.c > > @@ -2874,6 +2874,51 @@ uint32_t helper_bcdctz(ppc_avr_t *r, ppc_avr_t *= b, uint32_t ps) > > return cr; > > } > >=20 > > +uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) > > +{ > > + int cr; > > + int i; > > + int ox_flag =3D 0; > > + uint64_t lo_value; > > + uint64_t hi_value; > > + uint64_t max =3D 0x38d7ea4c68000; >=20 > This is at heart a decimal number, and should be written as such. > Also, you need ULL for a 32-bit host compile. >=20 > > + if (divu128(&lo_value, &hi_value, max)) { > > + ox_flag =3D 1; > > + } else if (lo_value >=3D max && hi_value =3D=3D 0) { > > + ox_flag =3D 1; > > + } >=20 > Dispense with ox_flag and set cr =3D CRF_SO now. >=20 > > + for (i =3D 1; hi_value; hi_value /=3D 10, i++) { > > + bcd_put_digit(&ret, hi_value % 10, i); > > + } > > + > > + for (; lo_value; lo_value /=3D 10, i++) { > > + bcd_put_digit(&ret, lo_value % 10, i); > > + } >=20 > How can this possibly work? You know there are 15 digits between high and > low, but you continue with i++? > > If hi_value =3D=3D 1 && lo_value =3D=3D 1, this should not produce 11, but > 10000000000000001. Ah, yes good catch, I missed that. I think it will be clearer to use fixed bounds on each loop, rather than testing the value of the remaining result. --=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 --4oQnj4jcM03NhqPN Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYNkBjAAoJEGw4ysog2bOS/BkP/2AgCKLFimidfk6K3ym2TvZZ 0pzdzPWCveah7oE8nH6rakeKe0oCOzSnju31ovIx6BlWCpCe661yTKynVKsq8sxH 1vKI/dWgNEBB712x1VvB46CAqEj9EiDjp0oKXJDCopPg6ffdZR1vdV+qTtadkYf/ JJPNnMwnUcMsFB54rXdn2fwC6bnM44YqYxngasMTqyXyQWclnTmmRIfz+qo8pGCV JBPQcxzB2Or4RSUxJCf3F53DeW1UbY17Phgn79Up31qekqGepd6fWfILntdER/K/ GBqy2kzuR/9tKYlfidrdTcvg5h7T/+FQlaWzfuHWq8oMLCBFoCrWazYYm1yJqztq qIaTnQP2icqly3WXome6U8q4XWrobWYVa8YViGQhpdhdGM+A0T5umKwx6XALiSk0 piGSd5nQzeTpSA6KX0WDyFen5F4maR0E01o8YxuAtDrdXk5jkjv1ddpPn59S5S6M izPORdhRl5Pyv36LCcZFfvT/f4ozbpwGlbEOGpSidOilpk/RRSseHZiOdn3RL1a7 yXPp3aXgoHSVe1VYrVeZGk0uSYz8vXDNpI0C8R95imSV34nX2X1uLwGNmC7NqUFv yfiygYkSj3jWkDjFXN317wQzcDzp3S90giw4QOGB6D41OaqW4m190+B+xAFwlAlo 8XijNSd2x5Q9q/eGnVkt =h4fN -----END PGP SIGNATURE----- --4oQnj4jcM03NhqPN--