4 ms·
One things that comes to mind: popcnt(x^(x>>1))==2 for all 5 numbers. Maybe the checking function could start with that condition, then fall back to the slower
by leni536 7y ago
One things that comes to mind: popcnt(x^(x>>1))==2 for all 5 numbers. Maybe the checking function could start with that condition, then fall back to the slower one-by-one check when that evaluates to two. For most numbers the popcnt check would fail.
edit: Not to mention that all 5 numbers are even, so a parity check could also help for odd number inputs (but it makes it slower for even numbers). I do not think that AVX has anything to offer here though.
- zzo38computer 7y agoIt might matter then what cases you need to optimize for, which statistics are most important, and what instruction set you are using.
- leni536 7y agoSure, my tricks are mostly aimed for improving the average performance for uniform inputs between 0 and 2^32-1. Edit: And yeah, you need a fast popcnt here.