Thanks for CDQ info, I didn't know it existed :)
I just made the algotithm because I needed speedy div and mod, that could
handle signed and unsigned Int32, also with a Int32 as divisor. And the one
in Delphi6/7 doesn't do that.
I haven't used assembler since 1985 on a Dragon32, so I have a lot to catch
up with.
It might be that it could be a lot better, I hope someone could tell me how.
But as it is now, it runs about 90% faster than using div and then mod in
Delphi code.
Kai
----- Original Message -----
From: "Florian Klaempfl" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "FPC developers' list"
<fpc-devel@lists.freepascal.org>
Sent: Thursday, November 09, 2006 8:42 AM
Subject: Re: [fpc-devel] Math.DivMod results should be signed
function DivWithRemainder(Value, Divisor: Integer; var Remainder:
Integer): Integer;
{
In:
EAX = Value
ECX = @Remainder
EDX = Divisor
Out:
EAX = Result
ECX = @Remainder
}
asm
PUSH EBX { Save EBX - this register is not free to use }
MOV EBX , EDX { Copy Divisor to EBX, using it as a store }
TEST EAX , $80000000 { Test if Value is signed }
JNZ @Signed { If Value is negative, prepare signed EDX }
MOV EDX , 0 { If Value is positive, prepare unsigned EDX
(Clear it) }
@Continue:
IDIV EBX { Divides Value (actually EDX + EAX (64 bit)) by
EBX. Result -> EAX, remainder -> EDX }
MOV [ECX], EDX { Copies EDX to ECX^ (Remainder) }
POP EBX { Restore EBX }
RET
@Signed:
MOV EDX , -1 { Fill EDX with $FFFFFFFF if Value was signed }
JMP @Continue
Is this really faster than using CDQ?
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.14.0/524 - Release Date: 08.11.2006
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel