Timo said:
Patricia Shanahan wrote:
Hmm. do you see a way to speed up this (clamping):
if( ox >= width ) ox = width - 1;
else if( ox < 0 ) ox = 0;
Try getting rid of the "else", and see if it helps. Some
processors have fast ways of conditionally skipping a single
operation, but have to invalidate the pipeline on
mispredicted branch around more than one operation.
and
l = (dx + dy) >> 1;
if( l > 0xff ) l = 0xff;
else if( l < -0xff ) l = -0xff;
Same comment about the "else".
How about some context? Presumably, these things happen in
VERY frequently executed loops, or you wouldn't care about
them, and the objective is to improve the performance of the
whole loop, not just the snippet. What else goes on in each
loop? What goes on around it? Where do the operands come from?
Incidentally, I'm assuming that each piece of code gets
compiled to machine language for execution. If the bytecode
is being interpreted on each iteration, you need a better JVM.
Patricia