|Simple bounds check hack engler@AMSTERDAM.LCS.MIT.EDU (1994-03-10)|
|From:||engler@AMSTERDAM.LCS.MIT.EDU (Dawson R. Engler)|
|Organization:||MIT Laboratory for Computer Science|
|Date:||Thu, 10 Mar 1994 23:36:47 GMT|
Many languages provide array bounds checking, typically through
an expression of the form:
(index >= 0 && index < size)
On a 2's complement machine where 'size' is non-negative this can be
easily replaced by
((unsigned)index < (unsigned)size)
saving a comparision and branch in the common case.
This optimization is simple enough that I'm embarassed to post
it, but the compilers I have looked at get it wrong ;-)
Return to the
Search the comp.compilers archives again.