From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cA2tN-0007nR-FC for qemu-devel@nongnu.org; Thu, 24 Nov 2016 17:53:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cA2tK-0002ls-Gi for qemu-devel@nongnu.org; Thu, 24 Nov 2016 17:53:21 -0500 Date: Fri, 25 Nov 2016 09:16:48 +1100 From: David Gibson Message-ID: <20161124221648.GG23872@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> <20161124163121.GA5922@pacoca> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="BzCohdixPhurzSK4" Content-Disposition: inline In-Reply-To: <20161124163121.GA5922@pacoca> Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 1/4] target-ppc: Implement bcdcfsq. instruction List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: joserz@linux.vnet.ibm.com Cc: Richard Henderson , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, bharata@linux.vnet.ibm.com --BzCohdixPhurzSK4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 24, 2016 at 02:31:21PM -0200, joserz@linux.vnet.ibm.com wrote: > Hello Richard, >=20 > Thank you for your review, please read my answer below. >=20 >=20 > 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. > > > > > >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(+) > > > > > >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 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; > > > } > > > > > >+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 > OK >=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 >=20 > OK >=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++? > >=20 > > If hi_value =3D=3D 1 && lo_value =3D=3D 1, this should not produce 11, = but > > 10000000000000001. > >=20 >=20 > Suppose we have hi_value =3D lo_value =3D 1 >=20 > after divu128 above we will have No, Richard means if you have hi_value =3D=3D 1 and lo_value =3D=3D 1 *afte= r* the divide. This will happen if input has *decimal* value 1000000000000001. The point is that 'i' will have the wrong value if the low output word has any leading zeroes. > hi_value =3D 744073709551617 > lo_value =3D 18446 >=20 > then, after the first for loop: > hi_value =3D 0 > lo_value =3D 18446 > i =3D 16 > ret =3D u128 =3D 0x8376822234287792511 >=20 > finally, after the second loop: > hi_value =3D 0 > lo_value =3D 0 > i =3D 21 > ret =3D u128 =3D 0x0000000000018446744073709551617f >=20 > Which is correct, this function converted a signed quadword to bcd correc= tly, using two doubleword variables: > 1 << 64 | 1 =3D 18446744073709551617 >=20 > Am I missing anything? >=20 > Thank you! >=20 > >=20 > > r~ > >=20 >=20 --=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 --BzCohdixPhurzSK4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYN2bQAAoJEGw4ysog2bOS1tMQAMGV1qhOysYjC7tWRupqqvy0 CYlZi/OijBsWS0/Wos4RG1NGrxDt5RnAEduAKmMTVijfE2w2bMwcDZmeoW/LxHVl RngvysQkflHN0LcjFqrLXHHpn2EutpxZK7o/Cgg1Hh2zEeSpCC86IjU3ep+RY5IH 8lsEFQMchGUAeyqj2WJrPDR9oDjmAGXoCQKWCRStlhuXA6tvmuiPMcCMR8K+978K P7UQhaZYnl343pW2numsqvPPmq8Qx1eyG0Rbw2NakCz9PQCNsA5ABaGoTBgiQB4G drh02bQXPNXoWJTwzICa0Q0W6TC1ImvY677trwR1Cpn3aAOhPFwCoYGC4mvwBOyt dCvdddCW+UhozyTkDKg7XDBPdAA6EpUQEcHvDAtXZS8rUKXVoHzZGEZo5hgMemMC 4s4Gt2AtG+HvvY4rR24PNW7m055I7XYaRzcddEcP5uv/YvkLQ1/tmrimgjC2p69q nlO4bzXHvnzZp0eotUINcXRwrYLzDrW9a13XzOn78CI4Dufdy17AcSCAbVEO64Tt WSeUrU4H0jHoWbuIJn7ZDO+aMABpFvVpjDbOk/+NlAnxkWH05gAcgUeENQdtP0yu u7KGEBdW7Mz86IL7HOxR58W2lrQw/9/wjWyI+/eDlKt8E8xiHciAAI85uwDApY5G VB9swuSKLwTxSMDEZP/M =3gYB -----END PGP SIGNATURE----- --BzCohdixPhurzSK4--