Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 42a8dfb

Browse files
authored
Merge pull request #466 from tgross35/generic-fmin-fmax
Add `fminf16`, `fmaxf16`, `fminf128`, and `fmaxf128`
2 parents 933d9b0 + f65487b commit 42a8dfb

File tree

19 files changed

+123
-44
lines changed

19 files changed

+123
-44
lines changed

crates/libm-macros/src/shared.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
4747
FloatTy::F16,
4848
Signature { args: &[Ty::F16, Ty::F16], returns: &[Ty::F16] },
4949
None,
50-
&["copysignf16", "fdimf16"],
50+
&["copysignf16", "fdimf16", "fmaxf16", "fminf16"],
5151
),
5252
(
5353
// `(f32, f32) -> f32`
@@ -90,7 +90,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
9090
FloatTy::F128,
9191
Signature { args: &[Ty::F128, Ty::F128], returns: &[Ty::F128] },
9292
None,
93-
&["copysignf128", "fdimf128"],
93+
&["copysignf128", "fdimf128", "fmaxf128", "fminf128"],
9494
),
9595
(
9696
// `(f32, f32, f32) -> f32`

crates/libm-test/benches/random.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ libm_macros::for_each_function! {
127127
| fdimf16
128128
| floorf128
129129
| floorf16
130+
| fmaxf128
131+
| fmaxf16
132+
| fminf128
133+
| fminf16
130134
| rintf128
131135
| rintf16
132136
| roundf128

crates/libm-test/src/mpfloat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ libm_macros::for_each_function! {
192192
fabs | fabsf => abs,
193193
fdim | fdimf | fdimf16 | fdimf128 => positive_diff,
194194
fma | fmaf => mul_add,
195-
fmax | fmaxf => max,
196-
fmin | fminf => min,
195+
fmax | fmaxf | fmaxf16 | fmaxf128 => max,
196+
fmin | fminf | fminf16 | fminf128 => min,
197197
lgamma | lgammaf => ln_gamma,
198198
log | logf => ln,
199199
log1p | log1pf => ln_1p,

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ libm_macros::for_each_function! {
8989
fdimf16,
9090
floorf128,
9191
floorf16,
92+
fmaxf128,
93+
fmaxf16,
94+
fminf128,
95+
fminf16,
9296
rintf128,
9397
rintf16,
9498
roundf128,

crates/util/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
9696
| fdimf16
9797
| floorf128
9898
| floorf16
99+
| fmaxf128
100+
| fmaxf16
101+
| fminf128
102+
| fminf16
99103
| rintf128
100104
| rintf16
101105
| roundf128

etc/function-definitions.json

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,29 +379,61 @@
379379
"fmax": {
380380
"sources": [
381381
"src/libm_helper.rs",
382-
"src/math/fmax.rs"
382+
"src/math/fmax.rs",
383+
"src/math/generic/fmax.rs"
383384
],
384385
"type": "f64"
385386
},
386387
"fmaxf": {
387388
"sources": [
388-
"src/math/fmaxf.rs"
389+
"src/math/fmaxf.rs",
390+
"src/math/generic/fmax.rs"
389391
],
390392
"type": "f32"
391393
},
394+
"fmaxf128": {
395+
"sources": [
396+
"src/math/fmaxf128.rs",
397+
"src/math/generic/fmax.rs"
398+
],
399+
"type": "f128"
400+
},
401+
"fmaxf16": {
402+
"sources": [
403+
"src/math/fmaxf16.rs",
404+
"src/math/generic/fmax.rs"
405+
],
406+
"type": "f16"
407+
},
392408
"fmin": {
393409
"sources": [
394410
"src/libm_helper.rs",
395-
"src/math/fmin.rs"
411+
"src/math/fmin.rs",
412+
"src/math/generic/fmin.rs"
396413
],
397414
"type": "f64"
398415
},
399416
"fminf": {
400417
"sources": [
401-
"src/math/fminf.rs"
418+
"src/math/fminf.rs",
419+
"src/math/generic/fmin.rs"
402420
],
403421
"type": "f32"
404422
},
423+
"fminf128": {
424+
"sources": [
425+
"src/math/fminf128.rs",
426+
"src/math/generic/fmin.rs"
427+
],
428+
"type": "f128"
429+
},
430+
"fminf16": {
431+
"sources": [
432+
"src/math/fminf16.rs",
433+
"src/math/generic/fmin.rs"
434+
],
435+
"type": "f16"
436+
},
405437
"fmod": {
406438
"sources": [
407439
"src/libm_helper.rs",

etc/function-list.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ fma
5555
fmaf
5656
fmax
5757
fmaxf
58+
fmaxf128
59+
fmaxf16
5860
fmin
5961
fminf
62+
fminf128
63+
fminf16
6064
fmod
6165
fmodf
6266
frexp

src/math/fmax.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1+
/// Return the greater of two arguments or, if either argument is NaN, the other argument.
12
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
23
pub fn fmax(x: f64, y: f64) -> f64 {
3-
// IEEE754 says: maxNum(x, y) is the canonicalized number y if x < y, x if y < x, the
4-
// canonicalized number if one operand is a number and the other a quiet NaN. Otherwise it
5-
// is either x or y, canonicalized (this means results might differ among implementations).
6-
// When either x or y is a signalingNaN, then the result is according to 6.2.
7-
//
8-
// Since we do not support sNaN in Rust yet, we do not need to handle them.
9-
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
10-
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
11-
(if x.is_nan() || x < y { y } else { x }) * 1.0
4+
super::generic::fmax(x, y)
125
}

src/math/fmaxf.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1+
/// Return the greater of two arguments or, if either argument is NaN, the other argument.
12
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
23
pub fn fmaxf(x: f32, y: f32) -> f32 {
3-
// IEEE754 says: maxNum(x, y) is the canonicalized number y if x < y, x if y < x, the
4-
// canonicalized number if one operand is a number and the other a quiet NaN. Otherwise it
5-
// is either x or y, canonicalized (this means results might differ among implementations).
6-
// When either x or y is a signalingNaN, then the result is according to 6.2.
7-
//
8-
// Since we do not support sNaN in Rust yet, we do not need to handle them.
9-
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
10-
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
11-
(if x.is_nan() || x < y { y } else { x }) * 1.0
4+
super::generic::fmax(x, y)
125
}

src/math/fmaxf128.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Return the greater of two arguments or, if either argument is NaN, the other argument.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fmaxf128(x: f128, y: f128) -> f128 {
4+
super::generic::fmax(x, y)
5+
}

0 commit comments

Comments
 (0)