4 ms·
>All this is true, but it overlooks one very important thing: on a modern processor architecture, this "optimization" will almost certainly be completely useles
by vram22 7y ago
>All this is true, but it overlooks one very important thing: on a modern processor architecture, this "optimization" will almost certainly be completely useless [1]. Almost certainly, the bounds check will be pipelined in such a way that it is essentially free on every iteration.
Interesting, that. I've been reading here on HN a few times, that assembly language is harder to write / analyze nowadays because of such features of modern processors.
Regarding the optimization being useless:
That technique is called using a sentinel, and was common in algorithms earlier, maybe before modern processors' pipelining and suchlike features existed. E.g., it (using a sentinel to avoid one comparison per iteration - the check for passing the array end - in a search) is mentioned in the classic book "Writing Efficient Programs" by Jon Bentley. (great book, BTW. I owned and read most of it.)
See Bibliography section here:
https://en.wikipedia.org/wiki/Jon_Bentley_(computer_scientist) https://en.wikipedia.org/wiki/Jon_Bentley_(computer_scientis...