Assembler optimalisation - how to avoid a jump? (Developers)
> I write some kind of RLE sprite routine with clipping.
> I would like to write nice code. I know I could somehow remove the ugly
> jump "jnc @RLE_CLIP_MOVE_CONT" but I don't know how.
Is the jump hurting performance or just "feels" bad? I wouldn't sweat it, honestly.
> @RLE_CLIP_MOVE:
> sub edx,ecx
> jnc @RLE_CLIP_MOVE_CONT
>
> add ecx,edx
Seems redundant. "cmp" is better here (esp. since it's basically "sub" without saving result but changes flags). If your target is 686+, try "cmovle" or similar.
> @RLE_CLIP_MOVE_CONT:
> shr ecx,1;rep movsd;adc ecx,ecx;rep movsw {fast 32bit write}
This still assumes an even number. Anyways, adc ecx,ecx is pointless as it's always one or zero after rep. Hmmm, maybe that's the point? Otherwise I'd say drop the second "rep".
Dunno, I'm not good thinking outside of a debugger, but ...
shr ecx,1 ; div by 2? should this be "shr ecx,2" (div by 4)?
rep movsd ; should this be "rep movsw"?
adc ecx,ecx ; would "adc cl,cl" be smaller?
rep movsw ; should this be "rep movsb"?
> cmp edx,0
> jle @RLE_CLIP_END_LOOP
> jmp @RLE_CLIP_SCANLINE_LOOP
Use "test edx,edx" here. Very very minor difference, I know, but still ....
Complete thread:
- Assembler optimalisation - how to avoid a jump? - Laaca, 13.05.2012, 20:38 (Developers)
![Open in board view [Board]](img/board_d.gif)
![Open in mix view [Mix]](img/mix_d.gif)
- Assembler optimalisation - how to avoid a jump? - Rugxulo, 13.05.2012, 21:10
- Assembler optimalisation - how to avoid a jump? - Laaca, 13.05.2012, 22:15
- Assembler optimalisation - how to avoid a jump? - marcov, 13.05.2012, 23:22
- Assembler optimalisation - how to avoid a jump? - Laaca, 13.05.2012, 22:15
- Assembler optimisation - how to avoid a jump? - ecm, 13.05.2012, 23:32
- Assembler optimisation - how to avoid a jump? - Laaca, 14.05.2012, 18:15
- Assembler optimisation - variant 3, sbb - ecm, 14.05.2012, 18:22
- Assembler optimisation - how to avoid a jump? - Rugxulo, 16.05.2012, 10:34
- Assembler optimisation - how to avoid a jump? - bretjohn, 16.05.2012, 16:42
- Assembler optimisation - speed, size, etc - ecm, 16.05.2012, 16:59
- Assembler optimisation - how to avoid a jump? - bretjohn, 16.05.2012, 16:42
- Assembler optimisation - how to avoid a jump? - Laaca, 14.05.2012, 18:15
- Assembler optimalisation - how to avoid a jump? - Rugxulo, 13.05.2012, 21:10
Mix view