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
Op Thu, 9 Nov 2006, schreef Kai Olav Fredriksen:
It might be that it could be a lot better, I hope someone could tell me how.
asm
push ebx
mov ebx,edx
cdq
idiv ebx
mov [ecx],edx
pop ebx
end;
Daniël___
fpc-devel maillist -
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
Peter Vreman wrote:
oldval:=value
divval:=value div divider
modval:=oldval-divval
I don't see how this is correct ? And why you need oldval, you don't
modify value ?
oldval=5
divval=5 div 2=2
modval=5-2=3
Micha
___
fpc-devel maillist -
of course... :) it lost 2 milliseconds on the assembly code in 100 million
iterations.
Thank you Peter and Daniël
Kai
-- Peter Vreman wrote :
If you need both the div and mod you can use a single divsion and
subtraction:
oldval:=value
divval:=value div divider
modval:=oldval-divval
This
Peter Vreman wrote:
oldval:=value
divval:=value div divider
modval:=oldval-divval
I don't see how this is correct ? And why you need oldval, you don't
modify value ?
oldval=5
divval=5 div 2=2
modval=5-2=3
Mistake... it should have been:
modval=oldval-(divval*divider)
oldval=5
I just read your posting on Delphi's DivMod. It doesn't work very well, not on
LongInt (Integer) values and negatives, not on Delphi 6, that I'm using, anyway.
I wrote an alternative that handles LongInt and negatives. It takes only
Integer parameters. It's a function, rather than a
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 }
Op Thu, 9 Nov 2006, schreef Florian Klaempfl:
Is this really faster than using CDQ?
At least on RISC86 CPU's, CDQ is a fast directpath instruction.
Daniël___
fpc-devel maillist - fpc-devel@lists.freepascal.org
Daniël Mantione schrieb:
Op Thu, 9 Nov 2006, schreef Florian Klaempfl:
Is this really faster than using CDQ?
At least on RISC86 CPU's, CDQ is a fast directpath instruction.
That's why I'am asking :)
___
fpc-devel maillist -
On Tuesday 21 March 2006 04:37, Michalis Kamburelis wrote:
I'm concerned with using DivMod in cases when Dividend is 0. DivMod
declaration is
procedure DivMod(Dividend: Integer; Divisor: Word; var Result,
Remainder: Word);
which means that it doesn't allow for Result and Remainder to
11 matches
Mail list logo