From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK3vH-0007d0-O8 for qemu-devel@nongnu.org; Mon, 25 Mar 2013 05:42:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UK3vF-0004BR-GD for qemu-devel@nongnu.org; Mon, 25 Mar 2013 05:42:35 -0400 Received: from mx3-phx2.redhat.com ([209.132.183.24]:45038) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK3vF-0004BA-6o for qemu-devel@nongnu.org; Mon, 25 Mar 2013 05:42:33 -0400 Date: Mon, 25 Mar 2013 05:42:27 -0400 (EDT) From: Paolo Bonzini Message-ID: <939022496.13000836.1364204547097.JavaMail.root@redhat.com> In-Reply-To: <51501862.8000909@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCHv4 2/9] cutils: add a function to find non-zero content in a buffer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Orit Wasserman Cc: Stefan Hajnoczi , Peter Lieven , qemu-devel@nongnu.org, quintela@redhat.com > >>> +size_t buffer_find_nonzero_offset(const void *buf, size_t len) > >>> +{ > >>> + VECTYPE *p = (VECTYPE *)buf; > >>> + VECTYPE zero = ZERO_SPLAT; > >>> + size_t i; > >>> + > >>> + assert(len % (BUFFER_FIND_NONZERO_OFFSET_UNROLL_FACTOR > >>> + * sizeof(VECTYPE)) == 0); > >>> + assert(((uintptr_t) buf) % sizeof(VECTYPE) == 0); > >>> + > >>> + if (*((const long *) buf)) { > >>> + return 0; > >>> + } > >>> + > >>> + for (i = 0; i < len / sizeof(VECTYPE); > >> Why not put len/sizeof(VECTYPE) in a variable? > > > > are you afraid that there is a division at each iteration? > > > > sizeof(VECTYPE) is a power of 2 so i think the compiler will > > optimize it > > to a >> at compile time. > true, but it still is done every iteration. len is an invariant, the compiler will move it out of the loop automatically. Write readable code unless you have good clues that it is also slow. Paolo