Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions etc/function-definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@
"sqrt": {
"sources": [
"libm/src/math/arch/aarch64/sqrt.rs",
"libm/src/math/arch/arm/sqrt.rs",
"libm/src/math/arch/loongarch/sqrt.rs",
"libm/src/math/arch/wasm32/sqrt.rs",
"libm/src/math/arch/x86/sqrt.rs",
Expand All @@ -996,6 +997,7 @@
"sqrtf": {
"sources": [
"libm/src/math/arch/aarch64/sqrt.rs",
"libm/src/math/arch/arm/sqrt.rs",
"libm/src/math/arch/loongarch/sqrt.rs",
"libm/src/math/arch/wasm32/sqrt.rs",
"libm/src/math/arch/x86/sqrt.rs",
Expand Down
9 changes: 9 additions & 0 deletions libm/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Config {
pub target_triple: String,
pub target_triple_split: Vec<String>,
pub target_arch: String,
pub target_abi: Option<String>,
pub target_env: String,
pub target_families: Vec<String>,
pub target_os: String,
Expand Down Expand Up @@ -63,6 +64,8 @@ impl Config {
opt_level: env::var("OPT_LEVEL").unwrap(),
cargo_features,
target_arch: env::var("CARGO_CFG_TARGET_ARCH").unwrap(),
// FIXME(msrv): defined since 1.78.
target_abi: env::var("CARGO_CFG_TARGET_ABI").ok(),
target_env: env::var("CARGO_CFG_TARGET_ENV").unwrap(),
target_families,
target_os: env::var("CARGO_CFG_TARGET_OS").unwrap(),
Expand Down Expand Up @@ -114,6 +117,9 @@ pub fn emit(cfg: &Config) {
// We have to cfg our code accordingly.
let thumb_1 = split[0] == "thumbv6m" || split[0] == "thumbv8m.base";

// FIXME(msrv): `cfg(target_abi)` is usable since 1.78.
let target_abi_eabihf = cfg.target_abi.as_deref() == Some("eabihf");

// Shorthand to detect i586 targets
let x86_no_sse2 = cfg.target_arch == "x86" && !cfg.target_features.iter().any(|f| f == "sse2");

Expand All @@ -123,7 +129,10 @@ pub fn emit(cfg: &Config) {
// Arch shorthand config is used in most crates.
set_cfg("thumb", thumb);
set_cfg("thumb_1", thumb_1);
set_cfg("target_abi_eabihf", target_abi_eabihf);
set_cfg("x86_no_sse2", x86_no_sse2);
Comment thread
silverstillisntgold marked this conversation as resolved.
// FIXME(arm_target_feature): the exact target features are not yet stable.
println!("cargo:rustc-check-cfg=cfg(target_feature, values(\"vfp2sp\", \"vfp2\"))");

match cfg.library {
Library::CompilerBuiltins => {
Expand Down
8 changes: 8 additions & 0 deletions libm/src/math/arch/arm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Architecture-specific support for Arm32/Thumb with hard float ABI.
mod sqrt;

#[cfg(target_feature = "vfp2")]
pub use sqrt::sqrt;
#[cfg(target_feature = "vfp2sp")]
pub use sqrt::sqrtf;
29 changes: 29 additions & 0 deletions libm/src/math/arch/arm/sqrt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[cfg(target_feature = "vfp2sp")]
pub fn sqrtf(mut x: f32) -> f32 {
Comment thread
silverstillisntgold marked this conversation as resolved.
// SAFETY: vsqrt.f32 is available with `vfp2sp`.
unsafe {
core::arch::asm!(
"vsqrt.f32 {x}, {x}",
x = inout(sreg) x,
options(nostack, nomem, pure),
);
}
x
}

#[cfg(target_feature = "vfp2")]
pub fn sqrt(mut x: f64) -> f64 {
// SAFETY: vsqrt.f64 is available with `vfp2`.
// Can't just use plain old `dreg` because `vfp2` only provides a base
// level of FPU support with a non-specified amount of fp64 registers.
// It's fine to use `dreg_low16` here, but use `dreg_low8` instead to
// keep the requirements as minimal as possible.
unsafe {
core::arch::asm!(
"vsqrt.f64 {x}, {x}",
x = inout(dreg_low8) x,
options(nostack, nomem, pure),
);
}
x
}
8 changes: 8 additions & 0 deletions libm/src/math/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ cfg_select_nofmt! {
sqrtf16,
};
}
all(target_arch = "arm", target_abi_eabihf) => {
mod arm;

#[cfg(target_feature = "vfp2sp")]
pub use arm::sqrtf;
#[cfg(target_feature = "vfp2")]
pub use arm::sqrt;
}
any(target_arch = "loongarch32", target_arch = "loongarch64") => {
mod loongarch;

Expand Down
2 changes: 2 additions & 0 deletions libm/src/math/sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn sqrtf(x: f32) -> f32 {
name: sqrtf,
use_arch: any(
all(target_arch = "aarch64", target_feature = "neon"),
all(target_arch = "arm", target_abi_eabihf, target_feature = "vfp2sp"),
all(target_arch = "wasm32", intrinsics_enabled),
all(any(target_arch = "loongarch32", target_arch = "loongarch64"), target_feature = "f"),
target_feature = "sse2"
Expand All @@ -38,6 +39,7 @@ pub fn sqrt(x: f64) -> f64 {
name: sqrt,
use_arch: any(
all(target_arch = "aarch64", target_feature = "neon"),
all(target_arch = "arm", target_abi_eabihf, target_feature = "vfp2"),
all(target_arch = "wasm32", intrinsics_enabled),
all(any(target_arch = "loongarch32", target_arch = "loongarch64"), target_feature = "d"),
target_feature = "sse2"
Expand Down
Loading