Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
calebzulawski committed Dec 9, 2022
1 parent 5ed7a3c commit 3c682fc
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions multiversion/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(clippy::needless_doctest_main)]
//! This crate provides the [`target`] and [`multiversion`] attributes for implementing
//! function multiversioning.
//! This crate provides the [`multiversion`] attribute for implementing function multiversioning.
//!
//! Many CPU architectures have a variety of instruction set extensions that provide additional
//! functionality. Common examples are single instruction, multiple data (SIMD) extensions such as
Expand All @@ -27,8 +26,9 @@
//! If any other functions do not work please file an issue on GitHub.
//!
//! # Target specification strings
//! Targets for the [`target`] and [`multiversion`] attributes are specified as a combination of
//! architecture (as specified in [`target_arch`]) and feature (as specified in [`target_feature`]).
//! Targets are specified as a combination of architecture (as specified in [`target_arch`]) and
//! feature (as specified in [`target_feature`]).
//!
//! A target can be specified as:
//! * `"arch"`
//! * `"arch+feature"`
Expand All @@ -47,6 +47,9 @@
//! feature)
//! * `"arm+neon"` (matches the `arm` architecture with the `"neon"` feature
//!
//! A complete list of available target features and CPUs is available in the [`target-features`
//! crate documentation](target_features::docs).
//!
//! [`target`]: attr.target.html
//! [`multiversion`]: attr.multiversion.html
//! [`target_arch`]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch
Expand Down Expand Up @@ -103,7 +106,9 @@
/// }
/// ```
///
/// # Implementation details
/// # Notes on dispatcher performance
///
/// ### Feature detection is performed only once
/// The `direct` and `indirect` function version dispatcher performs function selection on the
/// first invocation. This is implemented with a static atomic variable containing the selected
/// function.
Expand All @@ -114,6 +119,12 @@
/// * If called in multiple threads, there is no contention. Both threads may perform feature
/// detection, but the atomic ensures these are synchronized correctly.
///
/// ### Dispatcher elision
/// If the optimal set of features is already known to exist at compile time, the entire dispatcher
/// is elided. For example, if the highest priority target requires `avx512f` and the function is
/// compiled with `RUSTFLAGS=-Ctarget-cpu=skylake-avx512`, the function is not multiversioned and
/// the highest priority target is used.
///
/// [`target`]: attr.target.html
/// [`multiversion`]: attr.multiversion.html
pub use multiversion_macros::multiversion;
Expand Down Expand Up @@ -156,8 +167,9 @@ pub mod target {

/// Get the selected target in a multiversioned function.
///
/// Returns the selected target as a [`Target`]. This macro only works in a
/// function marked with [`multiversion`].
/// Returns the selected target as a [`Target`].
///
/// This macro only works in a function marked with [`multiversion`].
///
/// # Example
/// ```
Expand All @@ -174,9 +186,13 @@ pub mod target {
pub use multiversion_macros::selected_target;

/// Equivalent to `#[cfg]`, but considers `target_feature`s detected at runtime.
///
/// This macro only works in a function marked with [`multiversion`].
pub use multiversion_macros::target_cfg;

/// Equivalent to `#[cfg_attr]`, but considers `target_feature`s detected at runtime.
///
/// This macro only works in a function marked with [`multiversion`].
pub use multiversion_macros::target_cfg_attr;

/// Match the selected target.
Expand All @@ -185,6 +201,8 @@ pub mod target {
/// detected features and statically-enabled features. Arms that do not match are not
/// compiled.
///
/// This macro only works in a function marked with [`multiversion`].
///
/// # Example
/// ```
/// use multiversion::{multiversion, target::match_target};
Expand Down

0 comments on commit 3c682fc

Please sign in to comment.