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 >