Skip to content

Commit 68b9036

Browse files
committed
Add fmodf128
This function is significantly slower than all others so includes an override in `EXTREMELY_SLOW_TESTS`. Without it, PR CI takes ~1hour and the extensive tests in CI take ~1day.
1 parent a9d3ba4 commit 68b9036

File tree

11 files changed

+40
-33
lines changed

11 files changed

+40
-33
lines changed

crates/libm-macros/src/shared.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -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", "fmaxf128", "fminf128"],
93+
&["copysignf128", "fdimf128", "fmaxf128", "fminf128", "fmodf128"],
9494
),
9595
(
9696
// `(f32, f32, f32) -> f32`

crates/libm-test/benches/icount.rs

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ main!(
111111
icount_bench_fmin_group,
112112
icount_bench_fminf_group,
113113
icount_bench_fmod_group,
114+
icount_bench_fmodf128_group,
114115
icount_bench_fmodf16_group,
115116
icount_bench_fmodf_group,
116117
icount_bench_frexp_group,

crates/libm-test/benches/random.rs

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ libm_macros::for_each_function! {
131131
| fmaxf16
132132
| fminf128
133133
| fminf16
134+
| fmodf128
134135
| fmodf16
135136
| rintf128
136137
| rintf16

crates/libm-test/src/mpfloat.rs

+16-31
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ libm_macros::for_each_function! {
152152
floorf16,
153153
fmod,
154154
fmodf,
155+
fmodf128,
155156
fmodf16,
156157
frexp,
157158
frexpf,
@@ -301,21 +302,6 @@ macro_rules! impl_op_for_ty {
301302
}
302303
}
303304

304-
impl MpOp for crate::op::[<fmod $suffix>]::Routine {
305-
type MpTy = (MpFloat, MpFloat);
306-
307-
fn new_mp() -> Self::MpTy {
308-
(new_mpfloat::<Self::FTy>(), new_mpfloat::<Self::FTy>())
309-
}
310-
311-
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
312-
this.0.assign(input.0);
313-
this.1.assign(input.1);
314-
let ord = this.0.rem_assign_round(&this.1, Nearest);
315-
prep_retval::<Self::RustRet>(&mut this.0, ord)
316-
}
317-
}
318-
319305
impl MpOp for crate::op::[<frexp $suffix>]::Routine {
320306
type MpTy = MpFloat;
321307

@@ -481,6 +467,21 @@ macro_rules! impl_op_for_ty_all {
481467
prep_retval::<Self::RustRet>(&mut this.0, Ordering::Equal)
482468
}
483469
}
470+
471+
impl MpOp for crate::op::[<fmod $suffix>]::Routine {
472+
type MpTy = (MpFloat, MpFloat);
473+
474+
fn new_mp() -> Self::MpTy {
475+
(new_mpfloat::<Self::FTy>(), new_mpfloat::<Self::FTy>())
476+
}
477+
478+
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
479+
this.0.assign(input.0);
480+
this.1.assign(input.1);
481+
let ord = this.0.rem_assign_round(&this.1, Nearest);
482+
prep_retval::<Self::RustRet>(&mut this.0, ord)
483+
}
484+
}
484485
}
485486
};
486487
}
@@ -526,22 +527,6 @@ impl MpOp for crate::op::lgammaf_r::Routine {
526527
}
527528
}
528529

529-
// No fmodf128 yet
530-
impl MpOp for crate::op::fmodf16::Routine {
531-
type MpTy = (MpFloat, MpFloat);
532-
533-
fn new_mp() -> Self::MpTy {
534-
(new_mpfloat::<Self::FTy>(), new_mpfloat::<Self::FTy>())
535-
}
536-
537-
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
538-
this.0.assign(input.0);
539-
this.1.assign(input.1);
540-
let ord = this.0.rem_assign_round(&this.1, Nearest);
541-
prep_retval::<Self::RustRet>(&mut this.0, ord)
542-
}
543-
}
544-
545530
/* stub implementations so we don't need to special case them */
546531

547532
impl MpOp for crate::op::nextafter::Routine {

crates/libm-test/src/run_cfg.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ static EXTENSIVE_ITER_OVERRIDE: LazyLock<Option<u64>> = LazyLock::new(|| {
2222
/// amount of time.
2323
///
2424
/// Contains the itentifier+generator combo to match on, plus the factor to reduce by.
25-
const EXTEMELY_SLOW_TESTS: &[(Identifier, GeneratorKind, u64)] = &[];
25+
const EXTEMELY_SLOW_TESTS: &[(Identifier, GeneratorKind, u64)] = &[
26+
(Identifier::Fmodf128, GeneratorKind::QuickSpaced, 40),
27+
(Identifier::Fmodf128, GeneratorKind::Extensive, 40),
28+
];
2629

2730
/// Maximum number of iterations to run for a single routine.
2831
///

crates/libm-test/tests/compare_built_musl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ libm_macros::for_each_function! {
9393
fmaxf16,
9494
fminf128,
9595
fminf16,
96+
fmodf128,
9697
fmodf16,
9798
rintf128,
9899
rintf16,

crates/util/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
100100
| fmaxf16
101101
| fminf128
102102
| fminf16
103+
| fmodf128
103104
| fmodf16
104105
| rintf128
105106
| rintf16

etc/function-definitions.json

+7
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,13 @@
449449
],
450450
"type": "f32"
451451
},
452+
"fmodf128": {
453+
"sources": [
454+
"src/math/fmodf128.rs",
455+
"src/math/generic/fmod.rs"
456+
],
457+
"type": "f128"
458+
},
452459
"fmodf16": {
453460
"sources": [
454461
"src/math/fmodf16.rs",

etc/function-list.txt

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fminf128
6363
fminf16
6464
fmod
6565
fmodf
66+
fmodf128
6667
fmodf16
6768
frexp
6869
frexpf

src/math/fmodf128.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Calculate the remainder of `x / y`, the precise result of `x - trunc(x / y) * y`.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fmodf128(x: f128, y: f128) -> f128 {
4+
super::generic::fmod(x, y)
5+
}

src/math/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ cfg_if! {
378378
mod floorf128;
379379
mod fmaxf128;
380380
mod fminf128;
381+
mod fmodf128;
381382
mod rintf128;
382383
mod roundf128;
383384
mod sqrtf128;
@@ -390,6 +391,7 @@ cfg_if! {
390391
pub use self::floorf128::floorf128;
391392
pub use self::fmaxf128::fmaxf128;
392393
pub use self::fminf128::fminf128;
394+
pub use self::fmodf128::fmodf128;
393395
pub use self::rintf128::rintf128;
394396
pub use self::roundf128::roundf128;
395397
pub use self::sqrtf128::sqrtf128;

0 commit comments

Comments
 (0)