From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK4EM-0003XO-JF for qemu-devel@nongnu.org; Mon, 25 Mar 2013 06:02:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UK4EJ-0002Cm-Tu for qemu-devel@nongnu.org; Mon, 25 Mar 2013 06:02:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK4EJ-0002Cf-M6 for qemu-devel@nongnu.org; Mon, 25 Mar 2013 06:02:15 -0400 Message-ID: <515020E8.2050901@redhat.com> Date: Mon, 25 Mar 2013 12:03:20 +0200 From: Orit Wasserman MIME-Version: 1.0 References: <939022496.13000836.1364204547097.JavaMail.root@redhat.com> In-Reply-To: <939022496.13000836.1364204547097.JavaMail.root@redhat.com> 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: Paolo Bonzini Cc: Stefan Hajnoczi , Peter Lieven , qemu-devel@nongnu.org, quintela@redhat.com On 03/25/2013 11:42 AM, Paolo Bonzini wrote: > >>>>> +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. > I know it does for x86 but I wasn't sure for other platforms. I'm fine with as is. Orit > Paolo >