-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a401bc
commit f412e1a
Showing
24 changed files
with
11,011 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/// | ||
/// @file IteratorHelper.hpp | ||
/// | ||
/// Copyright (C) 2023 Kim Walisch, <[email protected]> | ||
/// Copyright (C) 2024 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
|
@@ -11,7 +11,6 @@ | |
#define ITERATOR_HELPER_HPP | ||
|
||
#include "PrimeGenerator.hpp" | ||
#include "PreSieve.hpp" | ||
#include "macros.hpp" | ||
#include "Vector.hpp" | ||
|
||
|
@@ -48,22 +47,20 @@ struct IteratorData | |
} | ||
|
||
void newPrimeGenerator(uint64_t start, | ||
uint64_t stop, | ||
PreSieve& preSieve) | ||
uint64_t stop) | ||
{ | ||
// We use placement new to put the PrimeGenerator | ||
// into an existing buffer. This way we don't | ||
// need to allocate any new memory. | ||
ASSERT(primeGenerator == nullptr); | ||
primeGenerator = new (primeGeneratorBuffer) PrimeGenerator(start, stop, preSieve); | ||
primeGenerator = new (primeGeneratorBuffer) PrimeGenerator(start, stop); | ||
} | ||
|
||
uint64_t stop; | ||
uint64_t dist = 0; | ||
bool include_start_number = true; | ||
PrimeGenerator* primeGenerator = nullptr; | ||
Vector<uint64_t> primes; | ||
PreSieve preSieve; | ||
alignas(PrimeGenerator) char primeGeneratorBuffer[sizeof(PrimeGenerator)]; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,21 @@ | |
/// from them at initialization. Each buffer is assigned | ||
/// different primes, for example: | ||
/// | ||
/// Buffer 0 removes multiplies of: { 7, 67, 71 } | ||
/// Buffer 1 removes multiplies of: { 11, 41, 73 } | ||
/// Buffer 2 removes multiplies of: { 13, 43, 59 } | ||
/// Buffer 3 removes multiplies of: { 17, 37, 53 } | ||
/// Buffer 4 removes multiplies of: { 19, 29, 61 } | ||
/// Buffer 5 removes multiplies of: { 23, 31, 47 } | ||
/// Buffer 6 removes multiplies of: { 79, 97 } | ||
/// Buffer 7 removes multiplies of: { 83, 89 } | ||
/// buffer[0] removes multiplies of: { 7, 67, 71 } // 32 KiB | ||
/// buffer[1] removes multiplies of: { 11, 41, 73 } // 32 KiB | ||
/// buffer[2] removes multiplies of: { 13, 43, 59 } // 32 KiB | ||
/// buffer[3] removes multiplies of: { 17, 37, 53 } // 32 KiB | ||
/// buffer[4] removes multiplies of: { 19, 29, 61 } // 32 KiB | ||
/// buffer[5] removes multiplies of: { 23, 31, 47 } // 32 KiB | ||
/// buffer[6] removes multiplies of: { 79, 97 } // 8 KiB | ||
/// buffer[7] removes multiplies of: { 83, 89 } // 7 KiB | ||
/// | ||
/// Then whilst sieving, we perform a bitwise AND on the | ||
/// buffers_ arrays and store the result in the sieve array. | ||
/// Pre-sieving provides a speedup of up to 30% when | ||
/// sieving the primes < 10^10 using primesieve. | ||
/// | ||
/// Copyright (C) 2023 Kim Walisch, <[email protected]> | ||
/// Copyright (C) 2024 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
|
@@ -37,16 +37,8 @@ namespace primesieve { | |
class PreSieve | ||
{ | ||
public: | ||
void init(uint64_t start, uint64_t stop); | ||
void preSieve(Vector<uint8_t>& sieve, uint64_t segmentLow) const; | ||
uint64_t getMaxPrime() const { return maxPrime_; } | ||
private: | ||
uint64_t maxPrime_ = 13; | ||
uint64_t totalDist_ = 0; | ||
Array<Vector<uint8_t>, 8> buffers_; | ||
void initBuffers(); | ||
static void preSieveSmall(Vector<uint8_t>& sieve, uint64_t segmentLow); | ||
void preSieveLarge(Vector<uint8_t>& sieve, uint64_t segmentLow) const; | ||
static void preSieve(Vector<uint8_t>& sieve, uint64_t segmentLow); | ||
static uint64_t getMaxPrime() { return 97; } | ||
}; | ||
|
||
} // namespace | ||
|
Oops, something went wrong.