Karl-Filip Faxen <[EMAIL PROTECTED]> writes:
> There is a hidden cost to trapping Int overflow ...
> operations on Ints become unsafe i.e. may raise exceptions
> This is a problem both for a global
> instruction scheduler (e.g. a trace scheduler) and for other
> optimizations based on speculative execution.
Just as a note, the computer architecture folks have designed support
for speculative execution in the presence of exception-causing
instructions. The idea, as embodied, for example, in the
Hewlett-Packard Playdoh architecture, is that there is a speculative
version of each instruction. The speculative version of the
instruction behaves indentically to the normal instruction, except
that if an exceptional condition occurs (such as divide by zero), an
exception is not raised. Rather, a bit (called the speculative bit) is
set in the destination register to indicate that the condition
occurred. If a normal (i.e. non-speculative) instruction ever has an
operand whose speculative bit is set, then the exception is raised. If
a speculative instruction encounters an operand register with its speculative
bit set, the speculative bit on the destination register is set (i.e.
speculative bits propagate through speculative instructions).
For example, if a compiler moves a divide instruction to a point where
it is being executed eagerly (i.e. will execute in the transformed
program wheras it might not have executed in the original program), it
replaces the instruction by its speculative version. Thus, if a
divide by zero occurs, the exception will be raised only if the
result of the divide is subsequently accessed by an instruction
that is not executing eagerly.
In any case, I'm not using this as an argument for or against
Haskell exceptions for integer overflow. I'm just noting that
this problem is being considered by hardware and compiler people
for imperative languages as well.
-Ben
Dept. of Computer Science (212) 998-3495
Courant Institute of Mathematical Sciences Fax: (212) 995-4123
New York University __@
251 Mercer Street _-\<,
New York, NY 10012 (*)/(*)
email: [EMAIL PROTECTED]
www: http://cs.nyu.edu/cs/faculty/goldberg/
--------------------------------------------------------------------