diff --git a/src/main.rs b/src/main.rs index f9c406b..14d2339 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,8 @@ async fn main() -> Result<(), Box> { env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); let args = Args::parse(); + breakwater::parser::check_cpu_support(); + let fb = Arc::new(FrameBuffer::new(args.width, args.height)); // If we make the channel to big, stats will start to lag behind diff --git a/src/parser.rs b/src/parser.rs index 6899d79..f7f4044 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,5 +1,6 @@ use crate::framebuffer::FrameBuffer; use const_format::formatcp; +use log::{info, warn}; use std::simd::{u32x8, Simd, SimdUint}; use std::sync::Arc; use tokio::io::AsyncWriteExt; @@ -356,6 +357,25 @@ fn simd_unhex(value: &[u8]) -> u32 { shifted.reduce_or() } +pub fn check_cpu_support() { + #[cfg(target_arch = "x86_64")] + { + if !is_x86_feature_detected!("avx2") { + warn!("Your CPU does not support AVX2. Consider using a CPU supporting AVX2 for best performance"); + } else if !is_x86_feature_detected!("avx") { + warn!("Your CPU does not support AVX. Consider using a CPU supporting AVX2 (or at least AVX) for best performance"); + } else { + // At this point the CPU should support AVX und AVX2 + // Warn the user when he has compiled breakwater without the needed target features + if cfg!(all(target_feature = "avx", target_feature = "avx2")) { + info!("Using AVX and AVX2 support"); + } else { + warn!("Your CPU does support AVX and AVX2, but you have not enabled avx and avx2 support. Please re-compile using RUSTFLAGS='-C target-cpu=native' cargo build --release`"); + } + } + } +} + #[cfg(test)] mod test { use super::*;