1 /// 2 /// @file EratMedium.hpp 3 /// 4 /// Copyright (C) 2020 Kim Walisch, <kim.walisch@gmail.com> 5 /// 6 /// This file is distributed under the BSD License. See the COPYING 7 /// file in the top level directory. 8 /// 9 10 #ifndef ERATMEDIUM_HPP 11 #define ERATMEDIUM_HPP 12 13 #include "Bucket.hpp" 14 #include "macros.hpp" 15 #include "MemoryPool.hpp" 16 #include "Wheel.hpp" 17 18 #include <stdint.h> 19 #include <array> 20 21 namespace primesieve { 22 23 /// EratMedium is an implementation of the segmented sieve of 24 /// Eratosthenes optimized for medium sieving primes 25 /// that have a few multiples per segment. 26 /// 27 class EratMedium : public Wheel30_t 28 { 29 public: 30 void init(uint64_t, uint64_t, uint64_t); enabled() const31 bool enabled() const { return enabled_; } 32 NOINLINE void crossOff(uint8_t*, uint64_t); 33 private: 34 bool enabled_ = false; 35 uint64_t maxPrime_ = 0; 36 MemoryPool memoryPool_; 37 std::array<SievingPrime*, 64> buckets_; 38 void storeSievingPrime(uint64_t, uint64_t, uint64_t); 39 NOINLINE void crossOff_7(uint8_t*, uint8_t*, Bucket*); 40 NOINLINE void crossOff_11(uint8_t*, uint8_t*, Bucket*); 41 NOINLINE void crossOff_13(uint8_t*, uint8_t*, Bucket*); 42 NOINLINE void crossOff_17(uint8_t*, uint8_t*, Bucket*); 43 NOINLINE void crossOff_19(uint8_t*, uint8_t*, Bucket*); 44 NOINLINE void crossOff_23(uint8_t*, uint8_t*, Bucket*); 45 NOINLINE void crossOff_29(uint8_t*, uint8_t*, Bucket*); 46 NOINLINE void crossOff_31(uint8_t*, uint8_t*, Bucket*); 47 }; 48 49 } // namespace 50 51 #endif 52