[MLton] arith shrinking & bit fiddling
Matthew Fluet
fluet@cs.cornell.edu
Mon, 20 Oct 2003 16:54:14 -0400 (EDT)
I had a little time over the weekend to start implementing 64bit ops in
the x86 codegen. But, two questions:
1) Is there any reason that the following case is absent from
shrinkTransfer in ssa/shrink.fun:
| Prim.ApplyResult.Apply (prim, args) =>
let val args = Vector.fromList args
in
([], Arith {prim = prim,
args = uses args,
overflow = simplifyLabel overflow,
success = simplifyLabel success,
ty = ty})
end
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.
gcc compiles
long long negate(long long x) { return -x; }
as
negl lo
adcl hi
negl hi
which produces the correct result, but sets the overflow flag when the lo
bits are nonzero (setting the carry flag) and the hi bits are
Int32.maxInt. The adcl hi rolls hi to Int32.minInt and the negation
overflows. But, the resulting bits are correct. We only "really"
overflow when the low bits are (~1: Int32.int).
_______________________________________________
MLton mailing list
MLton@mlton.org
http://www.mlton.org/mailman/listinfo/mlton