Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

Assembler optimalisation - how to avoid a jump? (Developers)

posted by Rugxulo(R) Homepage, Usono, 13.05.2012, 21:10

> 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:

Back to the forum
Board view  Mix view
15317 Postings in 1383 Threads, 254 registered users, 15 users online (0 registered, 15 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum