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

Commit 856e314

Browse files
committed
Add fmodf16 using the generic implementation
1 parent 566e8e1 commit 856e314

File tree

10 files changed

+37
-1
lines changed

10 files changed

+37
-1
lines changed

crates/libm-macros/src/shared.rs

+1-1
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", "fmaxf16", "fminf16"],
50+
&["copysignf16", "fdimf16", "fmaxf16", "fminf16", "fmodf16"],
5151
),
5252
(
5353
// `(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_fmodf16_group,
114115
icount_bench_fmodf_group,
115116
icount_bench_frexp_group,
116117
icount_bench_frexpf_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+
| fmodf16
134135
| rintf128
135136
| rintf16
136137
| roundf128

crates/libm-test/src/mpfloat.rs

+17
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ libm_macros::for_each_function! {
152152
floorf16,
153153
fmod,
154154
fmodf,
155+
fmodf16,
155156
frexp,
156157
frexpf,
157158
ilogb,
@@ -525,6 +526,22 @@ impl MpOp for crate::op::lgammaf_r::Routine {
525526
}
526527
}
527528

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+
528545
/* stub implementations so we don't need to special case them */
529546

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

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+
fmodf16,
9697
rintf128,
9798
rintf16,
9899
roundf128,

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+
| fmodf16
103104
| rintf128
104105
| rintf16
105106
| roundf128

etc/function-definitions.json

+7
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,13 @@
449449
],
450450
"type": "f32"
451451
},
452+
"fmodf16": {
453+
"sources": [
454+
"src/math/fmodf16.rs",
455+
"src/math/generic/fmod.rs"
456+
],
457+
"type": "f16"
458+
},
452459
"frexp": {
453460
"sources": [
454461
"src/libm_helper.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+
fmodf16
6667
frexp
6768
frexpf
6869
hypot

src/math/fmodf16.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 fmodf16(x: f16, y: f16) -> f16 {
4+
super::generic::fmod(x, y)
5+
}

src/math/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ cfg_if! {
348348
mod floorf16;
349349
mod fmaxf16;
350350
mod fminf16;
351+
mod fmodf16;
351352
mod rintf16;
352353
mod roundf16;
353354
mod sqrtf16;
@@ -360,6 +361,7 @@ cfg_if! {
360361
pub use self::floorf16::floorf16;
361362
pub use self::fmaxf16::fmaxf16;
362363
pub use self::fminf16::fminf16;
364+
pub use self::fmodf16::fmodf16;
363365
pub use self::rintf16::rintf16;
364366
pub use self::roundf16::roundf16;
365367
pub use self::sqrtf16::sqrtf16;

0 commit comments

Comments
 (0)