From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPvhn-0007st-Vp for qemu-devel@nongnu.org; Mon, 23 Feb 2015 11:18:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YPvhk-00051R-OK for qemu-devel@nongnu.org; Mon, 23 Feb 2015 11:17:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33383) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPvhk-000514-Gj for qemu-devel@nongnu.org; Mon, 23 Feb 2015 11:17:56 -0500 Message-ID: <54EB52AE.4030002@redhat.com> Date: Mon, 23 Feb 2015 09:17:50 -0700 From: Eric Blake MIME-Version: 1.0 References: <1424694237-22786-1-git-send-email-aik@ozlabs.ru> <877fv8sp97.fsf@blackfin.pond.sub.org> In-Reply-To: <877fv8sp97.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="JvVq46do3nicSfRrGMJCaPaATHoTuqw0o" Subject: Re: [Qemu-devel] [PATCH v2] utils: Add pow2ceil() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , Alexey Kardashevskiy Cc: Peter Maydell , qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --JvVq46do3nicSfRrGMJCaPaATHoTuqw0o Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/23/2015 06:59 AM, Markus Armbruster wrote: > Alexey Kardashevskiy writes: >=20 >> This adds a helper to get closest bigger power-of-two value. >> >=20 > Here's how I'd do these functions: >=20 > int64_t pow2floor(int64_t value) > { > assert(value > 0); > return 0x8000000000000000u >> clz64(value); > } Needs to be 0x8000000000000000ull for 32-bit machines to compile correctl= y. Why is the parameter int64_t? Wouldn't it be more useful to have: uint64_t pow2floor(uint64_t value) >=20 > int64_t pow2ceil(int64_t value) > { Again, why allow signed inputs? > assert(value <=3D 0x4000000000000000) > if (value <=3D 1) > return 1; In particular, this slams all negative values to a result of 1, which doesn't necessarily make sense. > return 0x8000000000000000u >> (clz64(value - 1) - 1); > } >=20 >=20 >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --JvVq46do3nicSfRrGMJCaPaATHoTuqw0o Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJU61KuAAoJEKeha0olJ0Nqgs8IAII3nbdoTqM1XQmajtQ3Pq25 8JqxOb5ZXErdtI7XSnA9bG7P1sUIb5JqZsgaIA43gp403pI06VDGeCmy4q5XiMF+ ulFVfH9Ze074pGROo6Xe7osH/nXifkuwQvxktqX8p0DZTJDSsnfZtyz/S+rgSbRI BMovu95XRZbrt+aGSfdJNM9P2oRk1vcSsgwPBgWCkBRb/g4trTVXrAFf8fVs1FP+ TF9mLcJV5C8xHAVL7dwQ+jYruqA743sb+amhyir/DLP6yNTHO7/hck7eBlO5HAeW Es7zL5x1h/FF7fRCw672Sy6MWMrEOuc056QNweWs+Ao9OtxXm8hn6cg1rsxRM34= =nqTF -----END PGP SIGNATURE----- --JvVq46do3nicSfRrGMJCaPaATHoTuqw0o--