|eliminating array bounds checking overhead firstname.lastname@example.org (2000-04-26)|
|Re: eliminating array bounds checking overhead email@example.com (2000-04-27)|
|Re: eliminating array bounds checking overhead firstname.lastname@example.org (2000-04-27)|
|Re: eliminating array bounds checking overhead email@example.com (2000-04-27)|
|Re: eliminating array bounds checking overhead firstname.lastname@example.org (Ray Blaak) (2000-04-27)|
|Re: eliminating array bounds checking overhead Sid-Ahmed-Ali.TOUATI@inria.fr (Sid Ahmed Ali TOUATI) (2000-04-27)|
|Re: eliminating array bounds checking overhead email@example.com (Randall Hyde) (2000-04-27)|
|Re: eliminating array bounds checking overhead firstname.lastname@example.org (2000-04-27)|
|[15 later articles]|
|From:||email@example.com (Stephan Houben)|
|Date:||27 Apr 2000 10:44:31 -0400|
|Organization:||Eindhoven University of Technology, The Netherlands|
On 26 Apr 2000 02:44:19 -0400, firstname.lastname@example.org <email@example.com>
>I wish to perform an array lookup of the form:
>if (i > lo && i < hi)
> printf("%d", A[i]);
> printf("index out of bounds");
>The above code is executed several times. The probability that 'i' is
>between 'lo' and 'hi' is VERY high and I want to eliminate the
>overhead of the 2 less-than tests. Does any language or any machine
>provide some mechanism to:
>1. index an array without checking its bounds
Most C compilers never do array boundary checks. For other compiled
languages (e.g. Pascal, ML) it is often enabled by default but you can
turn it off with a compiler switch.
>2. throw an exception if the index was actually out of range
Most languages which exception support AND boundary checks respond to
a out-of-bound indexing with an exception. Languages that do this
include Java, ML, Eiffel. Probably much more.
>3. allow the programmer to catch and handle the exception rather than
> terminate the program
Well, this is possible for the languages I mentioned above.
Be advised that the boundary check still has to be performed, even
though you don't have to write the code manually. Although sometimes a
smart compiler might be able to remove it. But apparently, in your
case out-of-bound indexing *can* happen, so unless the compiler is
buggy it cannot optimize away the checks.
The ix86 has a BOUNDS instruction which can be used to check array
boundaries. IIRC, if the check fails an interrupt is raised.
[The BOUND instruction is pretty useless, it's slower than the equivalent
subtract/compare/jump sequence. -John]
Return to the
Search the comp.compilers archives again.