| Related articles |
|---|
| Simple bounds check hack engler@AMSTERDAM.LCS.MIT.EDU (1994-03-10) |
| Newsgroups: | comp.compilers |
| From: | engler@AMSTERDAM.LCS.MIT.EDU (Dawson R. Engler) |
| Keywords: | debug |
| 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 ;-)
Regards,
Dawson Engler
engler@amsterdam.lcs.mit.edu
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.