Skip to content

Instantly share code, notes, and snippets.

@pnkfelix
Created February 17, 2022 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pnkfelix/a2755c48ae1476c02f7b9f8a7d76ec62 to your computer and use it in GitHub Desktop.
Save pnkfelix/a2755c48ae1476c02f7b9f8a7d76ec62 to your computer and use it in GitHub Desktop.
// black boxes for pointers; LLVM isn't so happy without
// them. Unfortunately only usable with 1.59+ asm!, but the code isn't
// *too* much slower without them.
#[cfg(feature = "unstable")]
#[inline(always)]
fn b<T>(mut p: *mut T) -> *mut T { unsafe { core::arch::asm!("/* {0} */", inout(reg) p) } p }
#[cfg(not(feature = "unstable"))]
#[inline(always)]
fn b<T>(p: *mut T) -> *mut T { p }
#[cfg(feature = "safe")]
macro_rules! safe_assert { ($x: expr) => { assert!($x); } }
#[cfg(not(feature = "safe"))]
macro_rules! safe_assert { ($x: expr) => { () } }
mod streaming;
mod wheel;
mod sieve;
pub(crate) use crate::sieve::{Sieve};
fn main() {
let primes = Sieve::new(2_000_000);
let mut manual_sum = 0u64;
for p in primes.primes_from(0) { manual_sum += p as u64; }
dbg!(manual_sum);
let folded_sum = primes.primes_from(0).fold(0u64, |acc, p| acc + p as u64);
assert_eq!(manual_sum, folded_sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment