A naive compiler will branch when generating (remainder255 >= (255 +
128)); that's a comparison, and comparisons generate branches.
A smarter compiler might have a clever way of avoiding the branch,
perhaps involving a subtract followed by a cntlzw (?). That's just off
the top of my head; I haven't tested it.
And sho'nuff, it does:
tmp = alpha * red;
remainder256 = tmp & 0xFF; // get alpha * red (mod 256)
dividend = tmp >> 8; // compute alpha * red / 256
remainder255 = dividend + remainder256; // compute alpha * red (mod
255)
dividend += ((remainder255 >= (255 + 128)) & 1) + ((remainder255 >=
128) & 1); // add 0, 1, 2 depending on how large the remainder (mod
255) is
I always think of (x >= y) as an int which happens to be either 0 or 1,
but I guess that's not the case on the PowerPC at least, since the
comparison operators don't put the results in the GPRs. Phooey :)