From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Rp1-00039a-9b for qemu-devel@nongnu.org; Thu, 02 Jun 2016 08:34:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8Roy-00066n-ON for qemu-devel@nongnu.org; Thu, 02 Jun 2016 08:33:57 -0400 References: <1464234529-13018-1-git-send-email-eblake@redhat.com> <1464234529-13018-6-git-send-email-eblake@redhat.com> <5746FCFC.2060708@openvz.org> <574709AD.4020805@redhat.com> <20160602101450.GA6867@noname.redhat.com> From: Eric Blake Message-ID: <575027AC.5070004@redhat.com> Date: Thu, 2 Jun 2016 06:33:48 -0600 MIME-Version: 1.0 In-Reply-To: <20160602101450.GA6867@noname.redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="87aLqmdLnU3j7jE9PwUC9IcQdP60uWI7P" Subject: Re: [Qemu-devel] [PATCH v3 5/5] qcow2: Catch more unaligned write_zero into zero cluster List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: "Denis V. Lunev" , qemu-devel@nongnu.org, qemu-block@nongnu.org, Max Reitz , Paolo Bonzini This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --87aLqmdLnU3j7jE9PwUC9IcQdP60uWI7P Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/02/2016 04:14 AM, Kevin Wolf wrote: >> If you prefer, I could have written '-tail % s->cluster_sectors', but = as >> % on a negative signed integer gives different results than what you g= et >> for an unsigned number, I felt that & was nicer than % for making it >> more obvious that I'm grabbing particular bits. >> >> If you can think of any cleaner expression that represents the number = of >> sectors occurring after the tail until the next cluster boundary, I'm >> game; the hardest part is that when tail is 0, we want the number pass= ed >> to is_zero_sectors() to also be 0, not s->cluster_sectors (so the naiv= e >> 's->cluster_sectors - tail' is wrong). >=20 > The obvious one would be translating your English into C: >=20 > tail ? s->cluster_sectors - tail : 0 Would gcc optimize this into a bit operation rather than a branch? If not, that's a missed optimization bug that we should probably report (that is, if gcc has enough information elsewhere that s->cluster_sectors is a power of 2, since the bit operation optimization depends on that fact). >=20 > Another option which doesn't require an unsigned type would be > (s->cluster_sectors - tail) % s->cluster_sectors. That's the same thing as '-tail % s->cluster_sectors', since the distributive rule applies to modulo arithmetic, and since 'a % a' is 0 for non-zero 'a'. So you can argue I was just saving typing :) >=20 > I'm okay with merging the "more interesting" version, though I must > admit that I had to read it twice. That's certainly your call as maintainer :) --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --87aLqmdLnU3j7jE9PwUC9IcQdP60uWI7P Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXUCesAAoJEKeha0olJ0Nq2IoH/ibquggvxe2qSuWl8VXIEHo8 tR5w434mkgmAU0IKV3gb8g+GW5zpLGAVaKsr/72OnuWlw5WzzI/aYvH+B84h+d5u aEsouiKj9XbK8WDnpjaW627ccdteCQnRt70K/1IaV5HdcqiQKheIGrlIM8G3ZnMc 1ZahC3v++VCWiPXrktgKNWiqMU81R7v531lRvGOmLrhWfZnVW991J4PANSPqo8Kp rQcGaLZIzpKfJeTIvPrT+pmGF3zT4zOGfTX3T3AyPRfy+NtZ3DB0tKisqYmXotgi A1WHm/7PAkIH/o1rNS0PGLhDh6iGKt8ysED3+l+3j0pTzCEzVSvrXx37jrUzqtw= =EnRg -----END PGP SIGNATURE----- --87aLqmdLnU3j7jE9PwUC9IcQdP60uWI7P--