Created
February 17, 2022 19:29
-
-
Save pnkfelix/a2755c48ae1476c02f7b9f8a7d76ec62 to your computer and use it in GitHub Desktop.
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
// 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