[MLton] arith shrinking & bit fiddling

Matthew Fluet fluet@cs.cornell.edu
Tue, 21 Oct 2003 11:13:24 -0400 (EDT)


> > Without it, we don't simplify overflow checking operations like:
> >  0 - x
> >  ~1 * x
> >
> >
> > 2) Does anyone know an efficient way of doing overflow checking for signed
> > negation in assembly?  Note that defining:
> >   val Int64.~ =
> >                if detectOverflow
> > 		  then (fn i: int => if i = minInt'
> > 					then raise Overflow
> > 				     else ~? i)
> > 	       else ~?
> > is o.k., but the simplification above will introduce Int64_negCheck even
> > if it doesn't appear in the source program.
>
> You mean for  0 - x ---> ~x?  I don't understand why this is bad.
> It's replacing Int64_subCheck with Int64_negCheck.

The point was that if we define Int64.~ as above, rather than
  val Int64.~ = if detectOverflow
                  then _prim "Int64_negCheck": Int64.int -> Int64.int;
                  else ~?
then we might (mistakenly) believe that we don't need to implement the
primitive Int_negCheck IntSize.I64. (That primitive doesn't appear in the
basis, hence not in the original program.)  But, the simplifier might
introduce that primitive, so we need to implement it regardless of how we
define Int64.~.



_______________________________________________
MLton mailing list
MLton@mlton.org
http://www.mlton.org/mailman/listinfo/mlton