x86 - How do I optimize this assembly code? -
can here me optimize assembly code? i'm trying make execute faster now, can't find other way it.
code: mov eax, x mov a, eax again : mov ecx, shr ecx, 1 cmp ecx, 2 jb skip mov ebx, 2 inc ecx sub ecx, ebx mov count, 0 repeat : mov eax, sub edx,edx div ebx sub dx,0 jnz finish inc count finish : inc ebx loop repeat mov ecx,count cmp ecx,max jbe done mov max, ecx mov eax,a mov num,eax done : skip : mov ecx, y inc ecx sub ecx, inc loop again
there several redundant lines in code, example:
mov ebx, 2 inc ecx sub ecx, ebx
is identical to:
mov ebx, 2 dec ecx
etc... writing nicely not speed @ on modern cpu, redundant lines cost nothing (or nothing).
the loop looks run uselessly long, if understand (looks counting number of divisors of x, going till sqrt(x) enough, go till (x/2) ).
anyway didn't bother decipher supposed calculate. if dare enlighten function should calculate, may propose faster algorithms (which can make faster, opposed changing x86 instructions - gains negligible there).
Comments
Post a Comment