From 86ee1f99c9d361338017282810966efc33901c3d Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 10 Feb 2025 19:56:52 +0000 Subject: [PATCH] Combine `fmin{,f,f16,f128}` and `fmax{,f,f16,128}` into a single file These don't have much content since they now use the generic implementation. There will be more similar functions in the near future (fminimum, fmaximum, fminimum_num, fmaximum_num); start the pattern of combining similar functions now so we don't have to eventually maintain similar docs across 24 different files. --- .../libm/etc/function-definitions.json | 16 +++--- .../compiler-builtins/libm/src/math/fmax.rs | 5 -- .../compiler-builtins/libm/src/math/fmaxf.rs | 5 -- .../libm/src/math/fmaxf128.rs | 5 -- .../libm/src/math/fmaxf16.rs | 5 -- .../compiler-builtins/libm/src/math/fmin.rs | 5 -- .../libm/src/math/fmin_fmax.rs | 51 +++++++++++++++++++ .../compiler-builtins/libm/src/math/fminf.rs | 5 -- .../libm/src/math/fminf128.rs | 5 -- .../libm/src/math/fminf16.rs | 5 -- .../compiler-builtins/libm/src/math/mod.rs | 22 +++----- 11 files changed, 65 insertions(+), 64 deletions(-) delete mode 100644 library/compiler-builtins/libm/src/math/fmax.rs delete mode 100644 library/compiler-builtins/libm/src/math/fmaxf.rs delete mode 100644 library/compiler-builtins/libm/src/math/fmaxf128.rs delete mode 100644 library/compiler-builtins/libm/src/math/fmaxf16.rs delete mode 100644 library/compiler-builtins/libm/src/math/fmin.rs create mode 100644 library/compiler-builtins/libm/src/math/fmin_fmax.rs delete mode 100644 library/compiler-builtins/libm/src/math/fminf.rs delete mode 100644 library/compiler-builtins/libm/src/math/fminf128.rs delete mode 100644 library/compiler-builtins/libm/src/math/fminf16.rs diff --git a/library/compiler-builtins/libm/etc/function-definitions.json b/library/compiler-builtins/libm/etc/function-definitions.json index 5742ed585f58..d3e51f29a07c 100644 --- a/library/compiler-builtins/libm/etc/function-definitions.json +++ b/library/compiler-builtins/libm/etc/function-definitions.json @@ -365,56 +365,56 @@ }, "fmax": { "sources": [ - "src/math/fmax.rs", + "src/math/fmin_fmax.rs", "src/math/generic/fmax.rs" ], "type": "f64" }, "fmaxf": { "sources": [ - "src/math/fmaxf.rs", + "src/math/fmin_fmax.rs", "src/math/generic/fmax.rs" ], "type": "f32" }, "fmaxf128": { "sources": [ - "src/math/fmaxf128.rs", + "src/math/fmin_fmax.rs", "src/math/generic/fmax.rs" ], "type": "f128" }, "fmaxf16": { "sources": [ - "src/math/fmaxf16.rs", + "src/math/fmin_fmax.rs", "src/math/generic/fmax.rs" ], "type": "f16" }, "fmin": { "sources": [ - "src/math/fmin.rs", + "src/math/fmin_fmax.rs", "src/math/generic/fmin.rs" ], "type": "f64" }, "fminf": { "sources": [ - "src/math/fminf.rs", + "src/math/fmin_fmax.rs", "src/math/generic/fmin.rs" ], "type": "f32" }, "fminf128": { "sources": [ - "src/math/fminf128.rs", + "src/math/fmin_fmax.rs", "src/math/generic/fmin.rs" ], "type": "f128" }, "fminf16": { "sources": [ - "src/math/fminf16.rs", + "src/math/fmin_fmax.rs", "src/math/generic/fmin.rs" ], "type": "f16" diff --git a/library/compiler-builtins/libm/src/math/fmax.rs b/library/compiler-builtins/libm/src/math/fmax.rs deleted file mode 100644 index d5d9b513b849..000000000000 --- a/library/compiler-builtins/libm/src/math/fmax.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// Return the greater of two arguments or, if either argument is NaN, the other argument. -#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn fmax(x: f64, y: f64) -> f64 { - super::generic::fmax(x, y) -} diff --git a/library/compiler-builtins/libm/src/math/fmaxf.rs b/library/compiler-builtins/libm/src/math/fmaxf.rs deleted file mode 100644 index 3197d5cf2ca1..000000000000 --- a/library/compiler-builtins/libm/src/math/fmaxf.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// Return the greater of two arguments or, if either argument is NaN, the other argument. -#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn fmaxf(x: f32, y: f32) -> f32 { - super::generic::fmax(x, y) -} diff --git a/library/compiler-builtins/libm/src/math/fmaxf128.rs b/library/compiler-builtins/libm/src/math/fmaxf128.rs deleted file mode 100644 index bace9ab53f2a..000000000000 --- a/library/compiler-builtins/libm/src/math/fmaxf128.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// Return the greater of two arguments or, if either argument is NaN, the other argument. -#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn fmaxf128(x: f128, y: f128) -> f128 { - super::generic::fmax(x, y) -} diff --git a/library/compiler-builtins/libm/src/math/fmaxf16.rs b/library/compiler-builtins/libm/src/math/fmaxf16.rs deleted file mode 100644 index fea15be8f147..000000000000 --- a/library/compiler-builtins/libm/src/math/fmaxf16.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// Return the greater of two arguments or, if either argument is NaN, the other argument. -#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn fmaxf16(x: f16, y: f16) -> f16 { - super::generic::fmax(x, y) -} diff --git a/library/compiler-builtins/libm/src/math/fmin.rs b/library/compiler-builtins/libm/src/math/fmin.rs deleted file mode 100644 index df8ff7c32e3b..000000000000 --- a/library/compiler-builtins/libm/src/math/fmin.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// Return the lesser of two arguments or, if either argument is NaN, the other argument. -#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn fmin(x: f64, y: f64) -> f64 { - super::generic::fmin(x, y) -} diff --git a/library/compiler-builtins/libm/src/math/fmin_fmax.rs b/library/compiler-builtins/libm/src/math/fmin_fmax.rs new file mode 100644 index 000000000000..97912e758266 --- /dev/null +++ b/library/compiler-builtins/libm/src/math/fmin_fmax.rs @@ -0,0 +1,51 @@ +/// Return the lesser of two arguments or, if either argument is NaN, the other argument. +#[cfg(f16_enabled)] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fminf16(x: f16, y: f16) -> f16 { + super::generic::fmin(x, y) +} + +/// Return the lesser of two arguments or, if either argument is NaN, the other argument. +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fminf(x: f32, y: f32) -> f32 { + super::generic::fmin(x, y) +} + +/// Return the lesser of two arguments or, if either argument is NaN, the other argument. +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fmin(x: f64, y: f64) -> f64 { + super::generic::fmin(x, y) +} + +/// Return the lesser of two arguments or, if either argument is NaN, the other argument. +#[cfg(f128_enabled)] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fminf128(x: f128, y: f128) -> f128 { + super::generic::fmin(x, y) +} + +/// Return the greater of two arguments or, if either argument is NaN, the other argument. +#[cfg(f16_enabled)] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fmaxf16(x: f16, y: f16) -> f16 { + super::generic::fmax(x, y) +} + +/// Return the greater of two arguments or, if either argument is NaN, the other argument. +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fmaxf(x: f32, y: f32) -> f32 { + super::generic::fmax(x, y) +} + +/// Return the greater of two arguments or, if either argument is NaN, the other argument. +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fmax(x: f64, y: f64) -> f64 { + super::generic::fmax(x, y) +} + +/// Return the greater of two arguments or, if either argument is NaN, the other argument. +#[cfg(f128_enabled)] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn fmaxf128(x: f128, y: f128) -> f128 { + super::generic::fmax(x, y) +} diff --git a/library/compiler-builtins/libm/src/math/fminf.rs b/library/compiler-builtins/libm/src/math/fminf.rs deleted file mode 100644 index b2cdfe89d64d..000000000000 --- a/library/compiler-builtins/libm/src/math/fminf.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// Return the lesser of two arguments or, if either argument is NaN, the other argument. -#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn fminf(x: f32, y: f32) -> f32 { - super::generic::fmin(x, y) -} diff --git a/library/compiler-builtins/libm/src/math/fminf128.rs b/library/compiler-builtins/libm/src/math/fminf128.rs deleted file mode 100644 index a9224c22aa5d..000000000000 --- a/library/compiler-builtins/libm/src/math/fminf128.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// Return the lesser of two arguments or, if either argument is NaN, the other argument. -#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn fminf128(x: f128, y: f128) -> f128 { - super::generic::fmin(x, y) -} diff --git a/library/compiler-builtins/libm/src/math/fminf16.rs b/library/compiler-builtins/libm/src/math/fminf16.rs deleted file mode 100644 index 6d936be347a1..000000000000 --- a/library/compiler-builtins/libm/src/math/fminf16.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// Return the lesser of two arguments or, if either argument is NaN, the other argument. -#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] -pub fn fminf16(x: f16, y: f16) -> f16 { - super::generic::fmin(x, y) -} diff --git a/library/compiler-builtins/libm/src/math/mod.rs b/library/compiler-builtins/libm/src/math/mod.rs index ae4a278f287a..ba0b933f17c8 100644 --- a/library/compiler-builtins/libm/src/math/mod.rs +++ b/library/compiler-builtins/libm/src/math/mod.rs @@ -165,10 +165,7 @@ mod floor; mod floorf; mod fma; mod fmaf; -mod fmax; -mod fmaxf; -mod fmin; -mod fminf; +mod fmin_fmax; mod fmod; mod fmodf; mod frexp; @@ -273,10 +270,7 @@ pub use self::floor::floor; pub use self::floorf::floorf; pub use self::fma::fma; pub use self::fmaf::fmaf; -pub use self::fmax::fmax; -pub use self::fmaxf::fmaxf; -pub use self::fmin::fmin; -pub use self::fminf::fminf; +pub use self::fmin_fmax::{fmax, fmaxf, fmin, fminf}; pub use self::fmod::fmod; pub use self::fmodf::fmodf; pub use self::frexp::frexp; @@ -346,8 +340,6 @@ cfg_if! { mod fabsf16; mod fdimf16; mod floorf16; - mod fmaxf16; - mod fminf16; mod fmodf16; mod ldexpf16; mod rintf16; @@ -363,8 +355,8 @@ cfg_if! { pub use self::fabsf16::fabsf16; pub use self::fdimf16::fdimf16; pub use self::floorf16::floorf16; - pub use self::fmaxf16::fmaxf16; - pub use self::fminf16::fminf16; + pub use self::fmin_fmax::fmaxf16; + pub use self::fmin_fmax::fminf16; pub use self::fmodf16::fmodf16; pub use self::ldexpf16::ldexpf16; pub use self::rintf16::rintf16; @@ -385,8 +377,6 @@ cfg_if! { mod fdimf128; mod floorf128; mod fmaf128; - mod fmaxf128; - mod fminf128; mod fmodf128; mod ldexpf128; mod rintf128; @@ -403,8 +393,8 @@ cfg_if! { pub use self::fdimf128::fdimf128; pub use self::floorf128::floorf128; pub use self::fmaf128::fmaf128; - pub use self::fmaxf128::fmaxf128; - pub use self::fminf128::fminf128; + pub use self::fmin_fmax::fmaxf128; + pub use self::fmin_fmax::fminf128; pub use self::fmodf128::fmodf128; pub use self::ldexpf128::ldexpf128; pub use self::rintf128::rintf128;