From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WWAAb-0006cS-KD for qemu-devel@nongnu.org; Fri, 04 Apr 2014 15:53:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WWAAW-0007hs-Os for qemu-devel@nongnu.org; Fri, 04 Apr 2014 15:52:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6868) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WWAAW-0007hl-FC for qemu-devel@nongnu.org; Fri, 04 Apr 2014 15:52:52 -0400 Date: Fri, 4 Apr 2014 20:52:42 +0100 From: "Dr. David Alan Gilbert" Message-ID: <20140404195242.GB2492@work-vm> References: <1396605482-8720-1-git-send-email-arei.gonglei@huawei.com> <1396605482-8720-9-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1396605482-8720-9-git-send-email-arei.gonglei@huawei.com> Subject: Re: [Qemu-devel] [PATCH v5 08/10] xbzrle: check 8 bytes at a time after an concurrency scene List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com Cc: ChenLiang , weidong.huang@huawei.com, quintela@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com * arei.gonglei@huawei.com (arei.gonglei@huawei.com) wrote: > From: ChenLiang > > The logic of old code is correct. But Checking byte by byte will > consume time after an concurrency scene. > > Signed-off-by: ChenLiang > Signed-off-by: Gonglei > --- > xbzrle.c | 28 ++++++++++++++++++---------- > 1 file changed, 18 insertions(+), 10 deletions(-) > > diff --git a/xbzrle.c b/xbzrle.c > index 92cccd7..9d67309 100644 > --- a/xbzrle.c > +++ b/xbzrle.c > @@ -51,16 +51,24 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, > > /* word at a time for speed */ > if (!res) { > - while (i < slen && > - (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) { > - i += sizeof(long); > - zrun_len += sizeof(long); > - } > - > - /* go over the rest */ > - while (i < slen && old_buf[i] == new_buf[i]) { > - zrun_len++; > - i++; > + while (i < slen) { > + if ((*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) { > + i += sizeof(long); > + zrun_len += sizeof(long); > + } else { > + /* go over the rest */ > + for (j = 0; j < sizeof(long); j++) { > + if (old_buf[i] == new_buf[i]) { > + i++; > + zrun_len++; > + } else { > + break; > + } > + } > + if (j != sizeof(long)) { > + break; Is it not possible to make this code the same as the other loop, you could xor in the same way just change the comparison? (What do other people think - I was thinking that would just be better since it would be symmetric?) Dave > + } > + } > } > } > > -- > 1.7.12.4 > > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK