|
| 1 | +/// Function multiversioning attribute macros for `pgvecto.rs`. |
| 2 | +/// |
| 3 | +/// ```rust |
| 4 | +/// #![feature(doc_cfg)] |
| 5 | +/// |
| 6 | +/// #[cfg(any(target_arch = "x86_64", doc))] |
| 7 | +/// #[doc(cfg(target_arch = "x86_64"))] |
| 8 | +/// #[detect::target_cpu(enable = "v3")] |
| 9 | +/// unsafe fn g_v3(x: &[u32]) -> u32 { |
| 10 | +/// todo!() |
| 11 | +/// } |
| 12 | +/// |
| 13 | +/// #[cfg(all(target_arch = "x86_64", test))] |
| 14 | +/// #[test] |
| 15 | +/// fn g_v3_test() { |
| 16 | +/// const EPSILON: F32 = F32(1e-5); |
| 17 | +/// detect::init(); |
| 18 | +/// if !detect::v3::detect() { |
| 19 | +/// println!("test {} ... skipped (v3)", module_path!()); |
| 20 | +/// return; |
| 21 | +/// } |
| 22 | +/// let x = vec![0u32; 400]; |
| 23 | +/// x.fill_with(|| rand::random()); |
| 24 | +/// let specialized = unsafe { g_v3(&x) }; |
| 25 | +/// let fallback = unsafe { g_fallback(&x) }; |
| 26 | +/// assert!( |
| 27 | +/// (specialized - fallback).abs() < EPSILON, |
| 28 | +/// "specialized = {specialized}, fallback = {fallback}." |
| 29 | +/// ); |
| 30 | +/// } |
| 31 | +/// |
| 32 | +/// // It generates x86_64/v3, x86_64/v2, aarch64/neon and fallback versions of this function. |
| 33 | +/// // It takes advantage of `g_v4` as x86_64/v4 version of this function. |
| 34 | +/// // It exposes the fallback version with the name "g_fallback". |
| 35 | +/// #[detect::multiversion(v3 = import, v2, neon, fallback = export)] |
| 36 | +/// fn g(x: &[u32]) -> u32 { |
| 37 | +/// let mut result = 0_u32; |
| 38 | +/// for v in x { |
| 39 | +/// result = result.wrapping_add(*v); |
| 40 | +/// } |
| 41 | +/// result |
| 42 | +/// } |
| 43 | +/// ``` |
| 44 | +pub use detect_macros::multiversion; |
| 45 | + |
| 46 | +/// This macros allows you to enable a set of features by target cpu names. |
| 47 | +pub use detect_macros::target_cpu; |
| 48 | + |
1 | 49 | detect_macros::main!();
|
0 commit comments