As for size = -size I think he was inverting the bits then adding 1 in one step (or something similar). Just a guess.
If he had indeed meant that, he should have written
x = ~x + 1;
GCC, even with optimisation turned off, will turn that into a negl instruction.In any case, there are unknowns here. Perhaps you should be less hasty in declaring people's work 'pointless' and telling others what they 'should' have done?
The advantage of this construct is that you can use the flags set by the increment to test for loop termination, rather than needing an additional comparison. The problem in C is that the compiler tends to "unoptimize" it for you after seemingly innocuous changes.
Anyway, the loop ends up looking something like this:
char *end = start + size;
size_t neg = -size;
do {
register = *(end + neg);
process(register);
neg += advance;
} while (neg);
For certain loops this construct shaves off 1 cycle per iteration, at the cost of ~1 cycle of initial setup cost. I'm wagering that he was doing something similar, but just kept the name "size" after the negation, rather than switching to "neg" as I did here.I don't understand your optimization. ZF is also set for dec, so why not just use dec and not negate the size?