3 ms·
> If you are accessing the content of an array, many languages will add “bound checking”: before accessing the array value, there will be a hidden check to see
by saagarjha 7y ago
> If you are accessing the content of an array, many languages will add “bound checking”: before accessing the array value, there will be a hidden check to see whether the index is valid. If the index is not valid, then an error is generated, otherwise the code proceeds normally. Bound checks are predictable since all accesses should (normally) be valid. Consequently, most processors should be able to predict the outcome nearly perfectly.
Warning! This is just a stone's throw from the kind of thing that got us Spectre, so keep in mind this sort of optimization can occasionally come back to bite you…
- rdc12 7y agoAt the software level, you don't get a choice about this thou, the CPU is going to speculate about a bounds check regardless, the optimization is it a different abstraction layer. Pretty much any thing on the market with the compute power of a cellphone, is going to have a feature like this too