3 ms·
> When that trick can't be used, I think the most efficient method would be to clamp the top of the address so that the max would land on a single guard page.
by BeeOnRope 2y ago
> When that trick can't be used, I think the most efficient method would be to clamp the top of the address so that the max would land on a single guard page.
If you are already doing a cmp + cmov, wouldn't you be better off just doing a cmp + jmp (to OOB handler)? The cmp + jmp can fuse, so it's probably strictly better in an execution cost sense, plus it doesn't add to the critical data-dependent chain of the load address, which would otherwise add a couple of cycles to the address data chain.
Of course, it does require you have these landing pads for the jmp.
- lossolo 2y agoCMP + JMP have a branch, which can be mispredicted and then you may pay 5-10x more than for cmp + cmov.
- BeeOnRope 2y agoThey won't be mispredicted nor take predictor resources since the default prediction is "not taken" and these branches are never taken (except perhaps once immediately before an OOB crash if that occurs). So they are free in that sense.