N
Nobody
I have some code that I am trying to optimize for speed...
trying to squeeze every last CPU cycle out... I remembered an old trick
where dividing & multiplying can be sped up by using bitshifts and addition
/ subtraction instead (doing this saved me about 11% time on my 2.26ghz P4).
Really easy with powers of two. I implemented this last night when I was
tired, and this morning, I realize it was not exactly right (values were
slightly off)...
I am trying to multiply / divide by 255.
for some reason I thought:
(x << 8) - 1 = x * 255
(x >> 8) + 1 = x / 255
like I said, late at night....
seems like the correct formula is:
(x << 8) - x = x * 255;
but is it possible to do this for the division?
trying to squeeze every last CPU cycle out... I remembered an old trick
where dividing & multiplying can be sped up by using bitshifts and addition
/ subtraction instead (doing this saved me about 11% time on my 2.26ghz P4).
Really easy with powers of two. I implemented this last night when I was
tired, and this morning, I realize it was not exactly right (values were
slightly off)...
I am trying to multiply / divide by 255.
for some reason I thought:
(x << 8) - 1 = x * 255
(x >> 8) + 1 = x / 255
like I said, late at night....
seems like the correct formula is:
(x << 8) - x = x * 255;
but is it possible to do this for the division?