Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Jul 28, 2024
1 parent 85fc036 commit f62aa4a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions include/Sieve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ class Sieve
uint64_t stop_idx = stop / 240;
uint64_t m1 = unset_smaller[start % 240];
uint64_t m2 = unset_larger[stop % 240];
const uint64_t* sieve64 = (const uint64_t*) sieve_.data();

// Branchfree bitmask calculation:
// m1 = (start_idx != stop_idx) ? m1 : m1 & m2;
m1 = (m1 * (start_idx != stop_idx)) | ((m1 & m2) * (start_idx == stop_idx));
// m2 = (start_idx != stop_idx) ? m2 : 0;
m2 *= (start_idx != stop_idx);

const uint64_t* sieve64 = (const uint64_t*) sieve_.data();
uint64_t start_bits = sieve64[start_idx] & m1;
uint64_t stop_bits = sieve64[stop_idx] & m2;
uint64_t cnt = popcnt64(start_bits);
Expand Down Expand Up @@ -199,19 +199,19 @@ class Sieve
uint64_t stop_idx = stop / 240;
uint64_t m1 = unset_smaller[start % 240];
uint64_t m2 = unset_larger[stop % 240];
const uint64_t* sieve64 = (const uint64_t*) sieve_.data();

// Branchfree bitmask calculation:
// m1 = (start_idx != stop_idx) ? m1 : m1 & m2;
m1 = (m1 * (start_idx != stop_idx)) | ((m1 & m2) * (start_idx == stop_idx));
// m2 = (start_idx != stop_idx) ? m2 : 0;
m2 *= (start_idx != stop_idx);

uint64_t i = start_idx + 1;
const uint64_t* sieve64 = (const uint64_t*) sieve_.data();
uint64_t start_bits = sieve64[start_idx] & m1;
uint64_t stop_bits = sieve64[stop_idx] & m2;
__m512i vec = _mm512_set_epi64(0, 0, 0, 0, 0, 0, stop_bits, start_bits);
__m512i vcnt = _mm512_popcnt_epi64(vec);
uint64_t i = start_idx + 1;

// Compute this for loop using AVX512.
// for (i = start_idx + 1; i < stop_idx; i++)
Expand Down Expand Up @@ -252,20 +252,20 @@ class Sieve
uint64_t stop_idx = stop / 240;
uint64_t m1 = unset_smaller[start % 240];
uint64_t m2 = unset_larger[stop % 240];
const uint64_t* sieve64 = (const uint64_t*) sieve_.data();

// Branchfree bitmask calculation:
// m1 = (start_idx != stop_idx) ? m1 : m1 & m2;
m1 = (m1 * (start_idx != stop_idx)) | ((m1 & m2) * (start_idx == stop_idx));
// m2 = (start_idx != stop_idx) ? m2 : 0;
m2 *= (start_idx != stop_idx);

uint64_t i = start_idx + 1;
const uint64_t* sieve64 = (const uint64_t*) sieve_.data();
uint64_t start_bits = sieve64[start_idx] & m1;
uint64_t stop_bits = sieve64[stop_idx] & m2;
uint64_t cnt = popcnt64(start_bits);
cnt += popcnt64(stop_bits);
svuint64_t vcnt = svdup_u64(0);
uint64_t i = start_idx + 1;

// Compute this for loop using ARM SVE.
// for (i = start_idx + 1; i < stop_idx; i++)
Expand Down

0 comments on commit f62aa4a

Please sign in to comment.