You can't always do those things. Yes, pointer length is almost always faster. But it's not always faster.
https://lemire.me/blog/2020/09/03/sentinels-can-be-faster/?a...
https://lemire.me/blog/2020/09/03/sentinels-can-be-faster/?a...
Results:
N = 10000
range 1218.1
sentinel 937.258
mine 672.227
ratio 1.29964
(ratio is range/sentinel, not mine/whatever)You can get even more crazy with SIMD. But for all that you need to know the length beforehand.
Edit: The b4 variable should actually be called b8. That's a remnant of a previous version, where I used 32-bit chunks.