[fpc-devel] Math.DivMod results should be signed
Peter Vreman
peter at freepascal.org
Thu Nov 9 12:00:32 CET 2006
> 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.
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 will work on all platforms and normally the oldval can be kept in a
register.
More information about the fpc-devel
mailing list