[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCHv4 2/9] cutils: add a function to find non-zero c
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCHv4 2/9] cutils: add a function to find non-zero content in a buffer |
Date: |
Mon, 25 Mar 2013 05:42:27 -0400 (EDT) |
> >>> +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
[Qemu-devel] [PATCHv4 7/9] migration: do not sent zero pages in bulk stage, Peter Lieven, 2013/03/22
Re: [Qemu-devel] [PATCHv4 0/9] buffer_is_zero / migration optimizations, Paolo Bonzini, 2013/03/22