[MLton-devel] improvement for Int.{div,mod}
Matthew Fluet
fluet@cs.cornell.edu
Tue, 22 Jul 2003 15:31:29 -0400 (EDT)
> So, "x div 16" simplifies to
>
> if x >= zero
> then I.quot (x, 16)
> else I.quot (x + one, 16) -? one
>
> The assembly I see for the then branch is
>
> movl %esi,%edi
> sarl $3,%edi
> shrl $28,%edi
> addl %edi,%esi
> sarl $4,%esi
>
> The assembly I see for the else branch is
>
> incl %esi
> movl %esi,%edi
> sarl $3,%edi
> shrl $28,%edi
> addl %edi,%esi
> sarl $4,%esi
> decl %esi
>
> Both of these branches appear to be doing stuff to handle both
> negative and positive values of x (aka %esi). For example, the then
> branch could be simplified to a single shrl, since we know x >= 0.
O.k., now I understand. Unfortunately, this simplification is performed
as a peephole optimization, so the "context" is exactly idiv x,$16.
I.e., we don't have any information about the sign of x.
If we wanted to perform such an optimization, I think we would want to
introduce integer shift primitives and do the transformation at the SSA
IL.
-------------------------------------------------------
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