Optimizations used in primesieve
masterprimesieve is highly optimized for modern CPU architectures using the following techniques:
- Bit Array: Uses a bit array with 8 flags for every 30 numbers.
- SIMD Vectorization: Pre-sieves multiples of small primes ($\le 163$) using SIMD instructions.
- Cache Management:
- Uses L1 cache for small sieving primes.
- Uses L2 cache for medium and big sieving primes.
- Compresses sieve and wheel indexes to improve cache efficiency.
- Branch Optimization: Sorts medium sieving primes to reduce branch misprediction rates.
- Parallelism: Multi-threaded execution using C++11
std::async. - Memory Management: Uses a custom memory pool for medium and big sieving primes.
- Loop Optimization: Employs extreme loop unrolling in the inner sieving loop.