From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWxiN-0001rh-1Q for qemu-devel@nongnu.org; Mon, 08 Aug 2016 23:28:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWxiJ-0002PJ-RQ for qemu-devel@nongnu.org; Mon, 08 Aug 2016 23:28:26 -0400 Date: Tue, 9 Aug 2016 13:28:17 +1000 From: David Gibson Message-ID: <20160809032817.GG9057@voom.fritz.box> References: <1470591415-3268-1-git-send-email-nikunj@linux.vnet.ibm.com> <1470591415-3268-3-git-send-email-nikunj@linux.vnet.ibm.com> <1470605617.12584.182.camel@kernel.crashing.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="RMedoP2+Pr6Rq0N2" Content-Disposition: inline In-Reply-To: <1470605617.12584.182.camel@kernel.crashing.org> Subject: Re: [Qemu-devel] [PATCH 2/6] target-ppc: Implement darn instruction List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Benjamin Herrenschmidt Cc: Nikunj A Dadhania , qemu-ppc@nongnu.org, rth@twiddle.net, qemu-devel@nongnu.org, Ravi Bangoria --RMedoP2+Pr6Rq0N2 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Aug 08, 2016 at 07:33:37AM +1000, Benjamin Herrenschmidt wrote: > On Sun, 2016-08-07 at 23:06 +0530, Nikunj A Dadhania wrote: > > +target_ulong helper_darn(uint32_t l) > > +{ > > +=A0=A0=A0 target_ulong r =3D UINT64_MAX; > > + > > +=A0=A0=A0 if (l <=3D 2) { > > +=A0=A0=A0=A0=A0=A0=A0 do { > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 r =3D random() * random(); > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 r &=3D l ? UINT64_MAX : UINT32_MAX; > > +=A0=A0=A0=A0=A0=A0=A0 } while (r =3D=3D UINT64_MAX); > > +=A0=A0=A0 } > > + > > +=A0=A0=A0 return r; > > +} > > =A0#endif >=20 > Isn't this a bit week ? Look at the implementation of H_RANDOM... Indeed, you should be using the rng backend that H_RANDOM, virtio-rng and the Intel random number instruction all use. But, worse than that: even if random() was a good RNG, I'm pretty sure than although random() * random() will give you a random number with twice as many bits as random() alone, it won't be uniformly distributed. That's probably not what you want. --=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 --RMedoP2+Pr6Rq0N2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXqU3RAAoJEGw4ysog2bOSBoIP/0S++cTTd911Qgw6NcfrPQOv fVkwRNbSQs7w2SF9kpWlhiBBzDhFZmfdKipHgQAjddN4Vmg3Gq3lNoogrX4qNUUb T+KfW5gdPmwdr3HsXj7PXZ6mhQlH76eRnoENn18onaKcCY/MVdolZbmUkzKC/870 V1o6VJbT1R2v0l9/yKkB4l605yq5zXCiZEzAiRc+mgwran7igksqWwja7OHRIJMi YKJ3bT7uqPisoosZF7p9p+4ZWcG3e2QtvzOkiGH5yDf1EfC+wQtyu2ag8mC2PxDd HOoZEVlbrWlhXP2fx1oEPdUWP6JjDNhy30E5SCeiHqbGNrjK71HLzE88gVAPhrnn 8L3G1IHofkJV9ShGXeGSqpW4P6Weu1BHq9CCcglRpE2oktcccpBSXu2ffCj8Y0r8 V+qA5xnETkxQkB8Ws/e1eau0AM7Oc1JwmYFsoGvXLG9TYdb9Xfj+5aMNvewsSdbX eEktPoI9IXpVWY8CddZdCxLk1mtiwYcOrKVp6w7ngF5aGcVdSNVeR5igqhc2+UwE r/c2+gPRzQQWs99afyDRMjTXu+G5R2ZKfUcuPs/OBReYFB6SHIfIIBsfgCS9loSr W9ZjQyrvp6BtI1oMMpg8mThuwUXAclYzLLTcQE9wgv0NOCqo1OB8t/OG2BghGp7k DTaA7I32+2+auS+veqRh =jauV -----END PGP SIGNATURE----- --RMedoP2+Pr6Rq0N2--