Skip to content

Commit

Permalink
Merge pull request #479 from tgross35/cargo-profile-updates
Browse files Browse the repository at this point in the history
Rework the available Cargo profiles
  • Loading branch information
tgross35 authored Jan 28, 2025
2 parents 46a3bce + f5f789a commit 8660ace
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,20 @@ exclude = [
[dev-dependencies]
no-panic = "0.1.33"

[profile.release]
# Options for no-panic to correctly detect the lack of panics
codegen-units = 1
lto = "fat"
# The default release profile is unchanged.

# Release mode with debug assertions
[profile.release-checked]
codegen-units = 1
inherits = "release"
debug-assertions = true
overflow-checks = true

# Release with maximum optimizations, which is very slow to build. This is also
# what is needed to check `no-panic`.
[profile.release-opt]
inherits = "release"
codegen-units = 1
lto = "fat"
overflow-checks = true

[profile.bench]
# Required for iai-callgrind
Expand Down
15 changes: 3 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@ fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-check-cfg=cfg(assert_no_panic)");

println!("cargo:rustc-check-cfg=cfg(feature, values(\"checked\"))");

#[allow(unexpected_cfgs)]
if !cfg!(feature = "checked") {
let lvl = env::var("OPT_LEVEL").unwrap();
if lvl != "0" && !cfg!(debug_assertions) {
println!("cargo:rustc-cfg=assert_no_panic");
} else if env::var("ENSURE_NO_PANIC").is_ok() {
// Give us a defensive way of ensureing that no-panic is checked when we
// expect it to be.
panic!("`assert_no_panic `was not enabled");
}
// If set, enable `no-panic`. Requires LTO (`release-opt` profile).
if env::var("ENSURE_NO_PANIC").is_ok() {
println!("cargo:rustc-cfg=assert_no_panic");
}

configure::emit_libm_config(&cfg);
Expand Down
12 changes: 11 additions & 1 deletion ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,14 @@ $cmd "$profile" release-checked --features unstable-intrinsics
$cmd "$profile" release-checked --features unstable-intrinsics --benches

# Ensure that the routines do not panic.
ENSURE_NO_PANIC=1 cargo build -p libm --target "$target" --no-default-features --release
#
# `--tests` must be passed because no-panic is only enabled as a dev
# dependency. The `release-opt` profile must be used to enable LTO and a
# single CGU.
ENSURE_NO_PANIC=1 cargo build \
-p libm \
--target "$target" \
--no-default-features \
--features unstable-float \
--tests \
--profile release-opt
1 change: 0 additions & 1 deletion crates/compiler-builtins-smoke-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ unexpected_cfgs = { level = "warn", check-cfg = [
"cfg(arch_enabled)",
"cfg(assert_no_panic)",
"cfg(intrinsics_enabled)",
'cfg(feature, values("checked"))',
'cfg(feature, values("force-soft-floats"))',
'cfg(feature, values("unstable"))',
'cfg(feature, values("unstable-intrinsics"))',
Expand Down
22 changes: 14 additions & 8 deletions src/math/atan2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,18 @@ pub fn atan2(y: f64, x: f64) -> f64 {
}
}

#[test]
fn sanity_check() {
assert_eq!(atan2(0.0, 1.0), 0.0);
assert_eq!(atan2(0.0, -1.0), PI);
assert_eq!(atan2(-0.0, -1.0), -PI);
assert_eq!(atan2(3.0, 2.0), atan(3.0 / 2.0));
assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);
assert_eq!(atan2(-2.0, -1.0), atan(-2.0 / -1.0) - PI);
#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg_attr(x86_no_sse, ignore = "FIXME(i586): possible incorrect rounding")]
fn sanity_check() {
assert_eq!(atan2(0.0, 1.0), 0.0);
assert_eq!(atan2(0.0, -1.0), PI);
assert_eq!(atan2(-0.0, -1.0), -PI);
assert_eq!(atan2(3.0, 2.0), atan(3.0 / 2.0));
assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);
assert_eq!(atan2(-2.0, -1.0), atan(-2.0 / -1.0) - PI);
}
}
5 changes: 3 additions & 2 deletions src/math/rem_pio2_large.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ pub(crate) fn rem_pio2_large(x: &[f64], y: &mut [f64], e0: i32, prec: usize) ->
let x1p24 = f64::from_bits(0x4170000000000000); // 0x1p24 === 2 ^ 24
let x1p_24 = f64::from_bits(0x3e70000000000000); // 0x1p_24 === 2 ^ (-24)

#[cfg(all(target_pointer_width = "64", feature = "checked"))]
assert!(e0 <= 16360);
if cfg!(target_pointer_width = "64") {
debug_assert!(e0 <= 16360);
}

let nx = x.len();

Expand Down
19 changes: 11 additions & 8 deletions src/math/sin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ pub fn sin(x: f64) -> f64 {
}
}

#[test]
fn test_near_pi() {
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
let result = sin(x);
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let result = force_eval!(result);
assert_eq!(result, sx);
#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg_attr(x86_no_sse, ignore = "FIXME(i586): possible incorrect rounding")]
fn test_near_pi() {
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
assert_eq!(sin(x), sx);
}
}

0 comments on commit 8660ace

Please sign in to comment.