Dick Hendrickson <[log in to unmask]> Wrote:
>QUESTION: Given a fragment such as
>
> 10 SUM = A + B
> 20 D = SUM + C
>
>does the standard allow the processor the freedom to replace this two
>statement
>fragment with any of the following single statements:
>
> 100 D = (A + B) + C
>
> 130 D = (B + A) + C
>
>ANSWER
>[snip]
>
>A common optimization for this fragment is to replace it by statements
>such as
>100, 130, etc. where the calculation of A + B appears in parenthesis.
>This
>replacement corresponds to the calculation of A + B in a temporary
>location
>(i.e., a register) and then accessing that temporary location instead of
>storing
>the result in SUM and then accessing that stored value.
Shouldn't the interpretation be revisited though? The "correct"
answer appears to be that the following would be valid, rather than
the above:
100 D = REAL(A + B, KIND(SUM)) + C
...
130 D = REAL(B + A, KIND(SUM)) + C
That is, the assignment to SUM might have been deliberately done
to force the intermediate to the same precision as the variable SUM.
One would think it undesirable for the implementation to override
this intent arbitrarily.
Not that this calls into question the quality of the original interpretation.
They presumably began the discussion with the assumption (implicit
or explicit) that all the variables were the same type and precision.
And, they were working at a time when there were no implementations
for which carrying *more* precision was more efficient than chopping
an intermediate back. The times have changed and the standard
needs to clarify in ways that were impossible to forsee.
--
J. Giles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|