mccalpin@vax1.acs.udel.EDU (John D Mccalpin) (03/15/90)
Comment: On most computers using FORTRAN the array bounds checking
option utterly destroys program performance. I presume that
this is because the checking is not done very cleverly!
Example: A typical function might be (in a language almost like Turing):
function dot_vv ( x, y : array 1..* of real) : real
if upper(x) <> upper(y)
exit ("inconsistent vector lengths in dot_vv")
end if
var sum:=0.0 % declare and initialize
for i : 1 .. upper(x)
sum := sum + x(i)*y(i)
end for
result sum % specify return value
end dot_vv
Comment: Array bounds checking does not need to be done on the
preceeding function! The combination of the intrinsic
function `upper' with the `if' test guarantees that
all the references are going to be legal (assuming
one-based arrays - minor detail).
Question: Does anyone know of any compilers that have at least this
level of intelligence about array bounds checking?
Since >>99% of the array references in my codes are in
loops of this sort, smart array bounds checking should
require a negligible overhead.
Comment: The FORTRAN version of this is obvious, though the FORTRAN
semantics cannot guarantee that the thing passed is really
an array of the correct size and type. The principle is
the same -- since the vast majority of array references are
in loops, it suffices to check the start and stop indices
of the loops (with corrections for any offsets).
Based on the performance of array-bounds checking on the
FORTRAN compilers that I know well, this does not seem to be
the way it is done in the real world.
--
John D. McCalpin mccalpin@vax1.acs.udel.edu
Assistant Professor mccalpin@delocn.udel.edu
College of Marine Studies, U. Del. mccalpin@scri1.scri.fsu.edu