[MLton-user] power of 2 optimisation

Matthew Fluet fluet@cs.cornell.edu
Thu, 17 Jul 2003 16:07:26 -0400 (EDT)


> Does mlton optimise for div/mod by constant powers of 2?
> that is:
>
>  val const = 16
>  fun div16 x = x div const
>
> would compile to a bit shift by 4 bits rather than a division.
> (mlton's excellent profiler tells me I'm spending 1/4 of my
> time in div and mod, despite my having selected powers of 2s)

MLton will optimize quot/rem (corresponding to the machine instructions)
by constant powers of 2 in late stages of the compiler (i.e., the native
codegen will perform this optimization, while the C-codegen relies on gcc
to perform the optimization).

Note that performing div/mod requires some additional tests to raise the
Overflow and Div exceptions when appropriate, although some of those
should be simplified away since the divisor is constant.




-------------------------------------------------------
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-user mailing list
MLton-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-user