Re: [fpc-devel] Math.DivMod results should be signed

2006-11-09 Thread Kai Olav Fredriksen
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

Re: [fpc-devel] Math.DivMod results should be signed

2006-11-09 Thread Daniël Mantione
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 -

Re: [fpc-devel] Math.DivMod results should be signed

2006-11-09 Thread Peter Vreman
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

Re: [fpc-devel] Math.DivMod results should be signed

2006-11-09 Thread Micha Nelissen
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 -

Re: Re: [fpc-devel] Math.DivMod results should be signed

2006-11-09 Thread k
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

Re: [fpc-devel] Math.DivMod results should be signed

2006-11-09 Thread Peter Vreman
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

Re: [fpc-devel] Math.DivMod results should be signed

2006-11-08 Thread k
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

Re: [fpc-devel] Math.DivMod results should be signed

2006-11-08 Thread Florian Klaempfl
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 }

Re: [fpc-devel] Math.DivMod results should be signed

2006-11-08 Thread Daniël Mantione
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

Re: [fpc-devel] Math.DivMod results should be signed

2006-11-08 Thread Florian Klaempfl
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 -

Re: [fpc-devel] Math.DivMod results should be signed

2006-03-21 Thread Vinzent Hoefler
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