[Cfp-interest] more background: why we don't have presubstitution

David Hough CFP pcfp at oakapple.net
Wed Jun 11 12:43:02 PDT 2014


I left this out of the historical material I sent yesterday:

One can imagine the original idea being implemented by having all
hardware trap enable bits on all the time.      There would be a table
of actions to be taken for all floating-point traps....

Now the foregoing sounds very inefficient - taking a hardware trap on every
rounding error?      But there's an obvious optimization available -
once the detail record has been created/flag has been raised, there's no
need to take a trap to implement the default exception handling - just
compute the default result and continue.    And this is what almost all
hardware does almost all the time.

The idea of a table of actions on exceptions lends itself to presubstitution.
After all, if the default action were to return a value that is
just an entry in the (user space)
table, how hard can it be to substitute a different value?
But the obvious optimization mentioned above, hardware handling exceptions by
returning a default value without trapping, interferes with  this idea.
The hardware does not have a table of default actions; it synthesizes the
infs and NaNs it needs when it needs them.    To get to a table of
substituted values in user space, that might be thread-specific or worse
global to many threads and hence subject to read/write race conditions
or deadlocks... is going to be at least as expensive as taking a trap to
user mode.     So while attaching a presubstituted value to an exceptional
operation might be a clean syntactic way to express the intended
program flow, the actual implementation is
going to have to at least involve tests and branches if not traps.



More information about the Cfp-interest mailing list