lea ecx,[eax-1]
test eax,ecx
je power2
That is good one.
Thanks for the idea.
The Svin, you may remove MMX ops:
bsr ecx,eax
lea edx,[eax-1]
test eax,edx
je @powerof2 ; ecx - shift
mov [shift],ecx
mov edx,1
shl edx,cl
mov [d,r+0],0
mov [r+4],edx
fild [r]
Nexo, it's good idea so that the app can be used on
older procs wich don't have MMX.
I just change a lit bit implementation to make it shorter in bytes:
older procs wich don't have MMX.
I just change a lit bit implementation to make it shorter in bytes:
.data
r dq ?
ldivider dq ?
.code
bsr ecx,eax
lea edx,[eax-1]
mov edi,offset r
test eax,edx
je @powerof2
xor edx,edx
mov [shift],ecx
mov [edi],edx
mov [edi+12],edx
inc edx
mov [edi+8],eax
shl edx,cl
mov [edi +4],edx
fild qword ptr [edi]
fild qword ptr [edi+8]
It's nothing special about this version.
I just coded it a little bit more carefull. Speed and size improved.
Though I don't think that size and speed is matter for the app in previous
version too, even if it run on i486 :)
But it is normal expect that if code is submitted to the section it must be
done approprate way no matter whatever.
So I improved several lines. Code included so you can compare the difference yourselve.
In addition I accepted Nexo's suggestion to remove MMX from the code
so that the app can be run on any processor from i486 DX.
Size is now 3,5 kb.
I just coded it a little bit more carefull. Speed and size improved.
Though I don't think that size and speed is matter for the app in previous
version too, even if it run on i486 :)
But it is normal expect that if code is submitted to the section it must be
done approprate way no matter whatever.
So I improved several lines. Code included so you can compare the difference yourselve.
In addition I accepted Nexo's suggestion to remove MMX from the code
so that the app can be run on any processor from i486 DX.
Size is now 3,5 kb.
Then divider = 67.
mov edx,0F4898D60h
mul edx
SHR edx, 6
But code
mov edx,07A44C6Bh
mul edx
shr edx,1
is shorter on 1 byte.
May be adjust paremeters needs.
mov edx,0F4898D60h
mul edx
SHR edx, 6
But code
mov edx,07A44C6Bh
mul edx
shr edx,1
is shorter on 1 byte.
May be adjust paremeters needs.
Svin, this is an interesting discussion started by your tool. Is there an easy way to get the remainder without DIV? I understand we can use two MUL, but there are many dependancies.
Where can I download this tool please, and has anyone found an easy way to get the remainder yet, please? Actually, I would be happy just to be able to detect IF there is a remainder...
http://www.wasm.ru/tools/22/magicnumber.zip