Sieve of Eratosthenes: Difference between revisions

→‎Unbounded Page-Segmented bit-packed odds-only version with Iterator: Rust: using unsafe to avoid array bounds check...
(→‎Odds-only bit-packed array, Iterator output: Rust: added page segmented version...)
(→‎Unbounded Page-Segmented bit-packed odds-only version with Iterator: Rust: using unsafe to avoid array bounds check...)
Line 8,604:
let r = ((lwi - s) % p) as usize;
if r == 0 { 0 } else { pc - r }
};
while cp < pbts { // inner tight loop where most time is spent:
unsafe { // avoids array bounds check, which is already done above
cmpsts[cp >> 5] |= 1u32 << (cp & 0x1F);
let cptr = cmpsts.get_unchecked_mut(cp >> 5);
*cptr |= 1u32 << (cp & 31); // about as fast as it gets...
}
// cmpsts[cp >> 5] |= 1u32 << (cp & 0x1F31);
cp += pc;
}
474

edits