[MLton-devel] improvement for Int.{div,mod}
Matthew Fluet
fluet@cs.cornell.edu
Tue, 22 Jul 2003 09:25:20 -0400 (EDT)
> Because of Franck Arnaud's question, I was looking into the x86
> assembly for Int.{quot,rem}, which are used to implement
> Int.{div,mod}. I noticed a possible improvement -- since the basis
> library code is testing whether the arguments are greater than zero,
> there is no need for the codegen to have to retest, as it appears to.
> We could either put some negations in the basis library code so that
> quot and rem are always called with positives, or we could add quot
> and rem primitives that know the sign of the arguments.
I don't believe that the x86 codegen is doing anything tricky.
z = Prim.Int_quot(x,y) and z = Prim.Int_mod(x,y) are both translated to:
mov x, z
idiv z, y
Note that Int.{quot,rem} are _not_ used to implement Int.{div,mod}. The
Integer functor implements Int.{quot,rem,div,mod} in terms of I.{quot,rem}
(where I : PRE_INTEGER_EXTRA). That is, all of Int.{quot,rem,div,mod}
wrap some additional tests around the primitives. The actual primitives
are implemented as efficiently as possible.
-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel