Related articles |
---|
eliminating array bounds checking overhead mayur_naik@my-deja.com (2000-04-26) |
Re: eliminating array bounds checking overhead stephan@pcrm.win.tue.nl (2000-04-27) |
Re: eliminating array bounds checking overhead vugluskr@unicorn.math.spbu.ru (2000-04-27) |
Re: eliminating array bounds checking overhead jprice@scdt.intel.com (2000-04-27) |
Re: eliminating array bounds checking overhead blaak@infomatch.com (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 rhyde@shoe-size.com (Randall Hyde) (2000-04-27) |
Re: eliminating array bounds checking overhead nr@labrador.eecs.harvard.edu (2000-04-27) |
[15 later articles] |
From: | stephan@pcrm.win.tue.nl (Stephan Houben) |
Newsgroups: | comp.compilers |
Date: | 27 Apr 2000 10:44:31 -0400 |
Organization: | Eindhoven University of Technology, The Netherlands |
References: | 00-04-194 |
Keywords: | optimize |
On 26 Apr 2000 02:44:19 -0400, mayur_naik@my-deja.com <mayur_naik@my-deja.com>
wrote:
>I wish to perform an array lookup of the form:
>
>if (i > lo && i < hi)
> printf("%d", A[i]);
>else
> 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.
Stephan
[The BOUND instruction is pretty useless, it's slower than the equivalent
subtract/compare/jump sequence. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.