Skip to content

Commit

Permalink
Update to latest libprimesieve
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Sep 13, 2023
1 parent 63c4706 commit 66c71bd
Show file tree
Hide file tree
Showing 34 changed files with 178 additions and 172 deletions.
6 changes: 3 additions & 3 deletions lib/primesieve/include/primesieve/CountPrintPrimes.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///
/// @file CountPrintPrimes.hpp
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -13,7 +13,7 @@
#include "Erat.hpp"
#include "MemoryPool.hpp"
#include "macros.hpp"
#include "pod_vector.hpp"
#include "Vector.hpp"
#include "PrimeSieve.hpp"

#include <stdint.h>
Expand All @@ -34,7 +34,7 @@ class CountPrintPrimes : public Erat
private:
uint64_t low_ = 0;
/// Count lookup tables for prime k-tuplets
pod_vector<uint8_t> kCounts_[6];
Vector<uint8_t> kCounts_[6];
counts_t& counts_;
/// Reference to the associated PrimeSieve object
PrimeSieve& ps_;
Expand Down
8 changes: 4 additions & 4 deletions lib/primesieve/include/primesieve/CpuInfo.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///
/// @file CpuInfo.hpp
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -10,7 +10,7 @@
#ifndef CPUINFO_HPP
#define CPUINFO_HPP

#include "pod_vector.hpp"
#include "Vector.hpp"

#include <cstddef>
#include <string>
Expand Down Expand Up @@ -43,8 +43,8 @@ class CpuInfo
private:
void init();
std::size_t logicalCpuCores_;
pod_array<std::size_t, 4> cacheSizes_;
pod_array<std::size_t, 4> cacheSharing_;
Array<std::size_t, 4> cacheSizes_;
Array<std::size_t, 4> cacheSharing_;
std::string error_;
};

Expand Down
6 changes: 3 additions & 3 deletions lib/primesieve/include/primesieve/Erat.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///
/// @file Erat.hpp
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -16,7 +16,7 @@
#include "EratBig.hpp"
#include "macros.hpp"
#include "intrinsics.hpp"
#include "pod_vector.hpp"
#include "Vector.hpp"

#include <stdint.h>

Expand Down Expand Up @@ -46,7 +46,7 @@ class Erat
/// Upper bound of the current segment
uint64_t segmentHigh_ = 0;
/// Sieve of Eratosthenes array
pod_vector<uint8_t> sieve_;
Vector<uint8_t> sieve_;
Erat() = default;
Erat(uint64_t, uint64_t);
void init(uint64_t, uint64_t, uint64_t, PreSieve&, MemoryPool& memoryPool);
Expand Down
8 changes: 4 additions & 4 deletions lib/primesieve/include/primesieve/EratBig.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///
/// @file EratBig.hpp
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -12,7 +12,7 @@

#include "Bucket.hpp"
#include "macros.hpp"
#include "pod_vector.hpp"
#include "Vector.hpp"
#include "Wheel.hpp"

#include <stdint.h>
Expand All @@ -29,14 +29,14 @@ class EratBig : public Wheel210_t
{
public:
void init(uint64_t, uint64_t, uint64_t, MemoryPool&);
NOINLINE void crossOff(pod_vector<uint8_t>& sieve);
NOINLINE void crossOff(Vector<uint8_t>& sieve);
bool hasSievingPrimes() const { return !buckets_.empty(); }
private:
uint64_t maxPrime_ = 0;
uint64_t log2SieveSize_ = 0;
uint64_t moduloSieveSize_ = 0;
MemoryPool* memoryPool_ = nullptr;
pod_vector<SievingPrime*> buckets_;
Vector<SievingPrime*> buckets_;
void storeSievingPrime(uint64_t, uint64_t, uint64_t);
NOINLINE void crossOff(uint8_t* sieve, SievingPrime* prime, SievingPrime* end);
};
Expand Down
10 changes: 5 additions & 5 deletions lib/primesieve/include/primesieve/EratMedium.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///
/// @file EratMedium.hpp
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -12,7 +12,7 @@

#include "Bucket.hpp"
#include "macros.hpp"
#include "pod_vector.hpp"
#include "Vector.hpp"
#include "Wheel.hpp"

#include <stdint.h>
Expand All @@ -30,12 +30,12 @@ class EratMedium : public Wheel30_t
public:
void init(uint64_t, uint64_t, MemoryPool&);
bool hasSievingPrimes() const { return !buckets_.empty(); }
NOINLINE void crossOff(pod_vector<uint8_t>& sieve);
NOINLINE void crossOff(Vector<uint8_t>& sieve);
private:
uint64_t maxPrime_ = 0;
MemoryPool* memoryPool_ = nullptr;
pod_vector<SievingPrime*> buckets_;
pod_vector<SievingPrime*> currentBuckets_;
Vector<SievingPrime*> buckets_;
Vector<SievingPrime*> currentBuckets_;
void storeSievingPrime(uint64_t, uint64_t, uint64_t);
NOINLINE void crossOff_7(uint8_t*, std::size_t, Bucket*);
NOINLINE void crossOff_11(uint8_t*, std::size_t, Bucket*);
Expand Down
8 changes: 4 additions & 4 deletions lib/primesieve/include/primesieve/EratSmall.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///
/// @file EratSmall.hpp
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -12,7 +12,7 @@

#include "Bucket.hpp"
#include "macros.hpp"
#include "pod_vector.hpp"
#include "Vector.hpp"
#include "Wheel.hpp"

#include <cstddef>
Expand All @@ -28,12 +28,12 @@ class EratSmall : public Wheel30_t
{
public:
void init(uint64_t, uint64_t, uint64_t);
void crossOff(pod_vector<uint8_t>& sieve);
void crossOff(Vector<uint8_t>& sieve);
bool hasSievingPrimes() const { return !primes_.empty(); }
private:
uint64_t maxPrime_ = 0;
std::size_t l1CacheSize_ = 0;
pod_vector<SievingPrime> primes_;
Vector<SievingPrime> primes_;
void storeSievingPrime(uint64_t, uint64_t, uint64_t);
NOINLINE void crossOff(uint8_t*, std::size_t);
};
Expand Down
11 changes: 8 additions & 3 deletions lib/primesieve/include/primesieve/IteratorHelper.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///
/// @file IteratorHelper.hpp
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -13,7 +13,7 @@
#include "PrimeGenerator.hpp"
#include "PreSieve.hpp"
#include "macros.hpp"
#include "pod_vector.hpp"
#include "Vector.hpp"

#include <stdint.h>

Expand All @@ -26,11 +26,13 @@ struct IteratorData
IteratorData(uint64_t stp) :
stop(stp)
{ }

~IteratorData()
{
if (primeGenerator)
primeGenerator->~PrimeGenerator();
}

void deletePrimeGenerator()
{
if (primeGenerator)
Expand All @@ -39,10 +41,12 @@ struct IteratorData
primeGenerator = nullptr;
}
}

void deletePrimes()
{
primes.deallocate();
}

void newPrimeGenerator(uint64_t start,
uint64_t stop,
PreSieve& preSieve)
Expand All @@ -53,11 +57,12 @@ struct IteratorData
ASSERT(primeGenerator == nullptr);
primeGenerator = new (primeGeneratorBuffer) PrimeGenerator(start, stop, preSieve);
}

uint64_t stop;
uint64_t dist = 0;
bool include_start_number = true;
PrimeGenerator* primeGenerator = nullptr;
pod_vector<uint64_t> primes;
Vector<uint64_t> primes;
PreSieve preSieve;
alignas(PrimeGenerator) char primeGeneratorBuffer[sizeof(PrimeGenerator)];
};
Expand Down
6 changes: 3 additions & 3 deletions lib/primesieve/include/primesieve/MemoryPool.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///
/// @file MemoryPool.hpp
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -12,7 +12,7 @@

#include "Bucket.hpp"
#include "macros.hpp"
#include "pod_vector.hpp"
#include "Vector.hpp"

namespace primesieve {

Expand All @@ -31,7 +31,7 @@ class MemoryPool
/// Number of buckets to allocate
std::size_t count_ = 0;
/// Pointers of allocated buckets
pod_vector<pod_vector<char>> memory_;
Vector<Vector<char>> memory_;
};

} // namespace
Expand Down
12 changes: 6 additions & 6 deletions lib/primesieve/include/primesieve/PreSieve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/// Pre-sieving provides a speedup of up to 30% when
/// sieving the primes < 10^10 using primesieve.
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -29,7 +29,7 @@
#ifndef PRESIEVE_HPP
#define PRESIEVE_HPP

#include "pod_vector.hpp"
#include "Vector.hpp"
#include <stdint.h>

namespace primesieve {
Expand All @@ -38,15 +38,15 @@ class PreSieve
{
public:
void init(uint64_t start, uint64_t stop);
void preSieve(pod_vector<uint8_t>& sieve, uint64_t segmentLow) const;
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;
pod_array<pod_vector<uint8_t>, 8> buffers_;
Array<Vector<uint8_t>, 8> buffers_;
void initBuffers();
static void preSieveSmall(pod_vector<uint8_t>& sieve, uint64_t segmentLow);
void preSieveLarge(pod_vector<uint8_t>& sieve, uint64_t segmentLow) const;
static void preSieveSmall(Vector<uint8_t>& sieve, uint64_t segmentLow);
void preSieveLarge(Vector<uint8_t>& sieve, uint64_t segmentLow) const;
};

} // namespace
Expand Down
20 changes: 10 additions & 10 deletions lib/primesieve/include/primesieve/PrimeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// returns the primes. When there are no more primes left in
/// the vector PrimeGenerator generates new primes.
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -18,7 +18,7 @@
#include "Erat.hpp"
#include "MemoryPool.hpp"
#include "SievingPrimes.hpp"
#include "pod_vector.hpp"
#include "Vector.hpp"

#include <stdint.h>
#include <cstddef>
Expand All @@ -31,25 +31,25 @@ class PrimeGenerator : public Erat
{
public:
PrimeGenerator(uint64_t start, uint64_t stop, PreSieve& preSieve);
void fillPrevPrimes(pod_vector<uint64_t>& primes, std::size_t* size);
void fillPrevPrimes(Vector<uint64_t>& primes, std::size_t* size);
static uint64_t maxCachedPrime();

#if defined(MULTIARCH_POPCNT_BMI)
#define MULTIARCH
__attribute__ ((target ("popcnt,bmi")))
void fillNextPrimes(pod_vector<uint64_t>& primes, std::size_t* size);
void fillNextPrimes(Vector<uint64_t>& primes, std::size_t* size);
#endif

#if defined(MULTIARCH_AVX512)
#define MULTIARCH
__attribute__ ((target ("avx512f,avx512vbmi,avx512vbmi2,popcnt")))
void fillNextPrimes(pod_vector<uint64_t>& primes, std::size_t* size);
void fillNextPrimes(Vector<uint64_t>& primes, std::size_t* size);
#endif

#if defined(MULTIARCH)
__attribute__ ((target ("default")))
#endif
void fillNextPrimes(pod_vector<uint64_t>& primes, std::size_t* size);
void fillNextPrimes(Vector<uint64_t>& primes, std::size_t* size);

private:
bool isInit_ = false;
Expand All @@ -63,10 +63,10 @@ class PrimeGenerator : public Erat
std::size_t getStopIdx() const;
void initErat();
void sieveSegment();
void initPrevPrimes(pod_vector<uint64_t>&, std::size_t*);
void initNextPrimes(pod_vector<uint64_t>&, std::size_t*);
bool sievePrevPrimes(pod_vector<uint64_t>&, std::size_t*);
bool sieveNextPrimes(pod_vector<uint64_t>&, std::size_t*);
void initPrevPrimes(Vector<uint64_t>&, std::size_t*);
void initNextPrimes(Vector<uint64_t>&, std::size_t*);
bool sievePrevPrimes(Vector<uint64_t>&, std::size_t*);
bool sieveNextPrimes(Vector<uint64_t>&, std::size_t*);
};

} // namespace
Expand Down
6 changes: 3 additions & 3 deletions lib/primesieve/include/primesieve/PrimeSieve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// sieving. It is used for printing and counting primes
/// and for computing the nth prime.
///
/// Copyright (C) 2022 Kim Walisch, <kim.walisch@gmail.com>
/// Copyright (C) 2023 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
Expand All @@ -14,13 +14,13 @@
#define PRIMESIEVE_CLASS_HPP

#include "PreSieve.hpp"
#include "pod_vector.hpp"
#include "Vector.hpp"

#include <stdint.h>

namespace primesieve {

using counts_t = pod_array<uint64_t, 6>;
using counts_t = Array<uint64_t, 6>;
class ParallelSieve;

enum
Expand Down
Loading

0 comments on commit 66c71bd

Please sign in to comment.