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

Commit 23d616b

Browse files
committed
Add floorf16 and floorf128
Use the generic algorithms to provide implementations for these routines.
1 parent 42647c6 commit 23d616b

File tree

12 files changed

+51
-3
lines changed

12 files changed

+51
-3
lines changed

crates/compiler-builtins-smoke-test/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ no_mangle! {
9797
fdimf16(x: f16, y: f16) -> f16;
9898
floor(x: f64) -> f64;
9999
floorf(x: f32) -> f32;
100+
floorf128(x: f128) -> f128;
101+
floorf16(x: f16) -> f16;
100102
fma(x: f64, y: f64, z: f64) -> f64;
101103
fmaf(x: f32, y: f32, z: f32) -> f32;
102104
fmax(x: f64, y: f64) -> f64;

crates/libm-macros/src/shared.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
99
FloatTy::F16,
1010
Signature { args: &[Ty::F16], returns: &[Ty::F16] },
1111
None,
12-
&["ceilf16", "fabsf16", "sqrtf16", "truncf16"],
12+
&["ceilf16", "fabsf16", "floorf16", "sqrtf16", "truncf16"],
1313
),
1414
(
1515
// `fn(f32) -> f32`
@@ -40,7 +40,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
4040
FloatTy::F128,
4141
Signature { args: &[Ty::F128], returns: &[Ty::F128] },
4242
None,
43-
&["ceilf128", "fabsf128", "sqrtf128", "truncf128"],
43+
&["ceilf128", "fabsf128", "floorf128", "sqrtf128", "truncf128"],
4444
),
4545
(
4646
// `(f16, f16) -> f16`

crates/libm-test/benches/icount.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ main!(
101101
icount_bench_fdimf16_group,
102102
icount_bench_fdimf_group,
103103
icount_bench_floor_group,
104+
icount_bench_floorf128_group,
105+
icount_bench_floorf16_group,
104106
icount_bench_floorf_group,
105107
icount_bench_fma_group,
106108
icount_bench_fmaf_group,

crates/libm-test/benches/random.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ libm_macros::for_each_function! {
125125
| fabsf16
126126
| fdimf128
127127
| fdimf16
128-
| sqrtf16
128+
| floorf128
129+
| floorf16
129130
| sqrtf128
131+
| sqrtf16
130132
| truncf128
131133
| truncf16 => (false, None),
132134

crates/libm-test/src/mpfloat.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ libm_macros::for_each_function! {
148148
fabsf128,
149149
fabsf16,floor,
150150
floorf,
151+
floorf128,
152+
floorf16,
151153
fmod,
152154
fmodf,
153155
frexp,
@@ -240,13 +242,15 @@ impl_no_round! {
240242
impl_no_round! {
241243
fabsf16 => abs_mut;
242244
ceilf16 => ceil_mut;
245+
floorf16 => floor_mut;
243246
truncf16 => trunc_mut;
244247
}
245248

246249
#[cfg(f128_enabled)]
247250
impl_no_round! {
248251
fabsf128 => abs_mut;
249252
ceilf128 => ceil_mut;
253+
floorf128 => floor_mut;
250254
truncf128 => trunc_mut;
251255
}
252256

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ libm_macros::for_each_function! {
8787
fabsf16,
8888
fdimf128,
8989
fdimf16,
90+
floorf128,
91+
floorf16,
9092
truncf128,
9193
truncf16,
9294
sqrtf16,

crates/util/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
9292
| fabsf16
9393
| fdimf128
9494
| fdimf16
95+
| floorf128
96+
| floorf16
9597
| sqrtf128
9698
| sqrtf16
9799
| truncf128

etc/function-definitions.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,20 @@
349349
],
350350
"type": "f32"
351351
},
352+
"floorf128": {
353+
"sources": [
354+
"src/math/floorf128.rs",
355+
"src/math/generic/floor.rs"
356+
],
357+
"type": "f128"
358+
},
359+
"floorf16": {
360+
"sources": [
361+
"src/math/floorf16.rs",
362+
"src/math/generic/floor.rs"
363+
],
364+
"type": "f16"
365+
},
352366
"fma": {
353367
"sources": [
354368
"src/libm_helper.rs",

etc/function-list.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ fdimf128
4949
fdimf16
5050
floor
5151
floorf
52+
floorf128
53+
floorf16
5254
fma
5355
fmaf
5456
fmax

src/math/floorf128.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// Floor (f128)
2+
///
3+
/// Finds the nearest integer less than or equal to `x`.
4+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
5+
pub fn floorf128(x: f128) -> f128 {
6+
return super::generic::floor(x);
7+
}

0 commit comments

Comments
 (0)