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

Commit 44bf8aa

Browse files
committed
more fixes
1 parent c230a7a commit 44bf8aa

File tree

6 files changed

+72
-60
lines changed

6 files changed

+72
-60
lines changed

ci/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ if [ "$(uname -a)" = "Linux" ]; then
6666
extra_flags="$extra_flags --features libm-test/test-musl-serialized"
6767
fi
6868

69-
# Make sure we can build with overriding features. We test the indibidual
69+
# Make sure we can build with overriding features. We test the individual
7070
# features it controls separately.
7171
cargo check --no-default-features
72-
cargo check --features "force-soft-floats"
72+
cargo check --all --target "$target" $extra_flags --features "force-soft-floats"
7373

7474
if [ "${BUILD_ONLY:-}" = "1" ]; then
7575
cmd="cargo build --target $target --package libm"

crates/libm-macros/tests/basic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ macro_rules! specified_types {
8888
fn_name: $fn_name:ident,
8989
RustFn: $RustFn:ty,
9090
RustArgs: $RustArgs:ty,
91+
attrs: [$($meta:meta),*],
9192
) => {
9293
mod $fn_name {
9394
#[allow(unused)]

crates/libm-test/benches/random.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ struct MuslExtra<F> {
1818
macro_rules! musl_rand_benches {
1919
(
2020
fn_name: $fn_name:ident,
21-
fn_extra: $skip_on_i586:expr,
21+
attrs: [$($meta:meta)*],
22+
fn_extra: ($skip_on_i586:expr, $musl_fn:expr),
2223
) => {
2324
paste::paste! {
2425
fn [< musl_bench_ $fn_name >](c: &mut Criterion) {
2526
type Op = libm_test::op::$fn_name::Routine;
2627

2728
#[cfg(feature = "build-musl")]
2829
let musl_extra = MuslExtra {
29-
musl_fn: Some(musl_math_sys::$fn_name as <Op as MathOp>::CFn),
30+
musl_fn: $musl_fn,
3031
skip_on_i586: $skip_on_i586
3132
};
3233

@@ -64,7 +65,10 @@ where
6465
break;
6566
}
6667

67-
let musl_res = input.call(musl_extra.musl_fn.unwrap());
68+
let Some(musl_fn) = musl_extra.musl_fn else {
69+
continue;
70+
};
71+
let musl_res = input.call(musl_fn);
6872
let crate_res = input.call(Op::ROUTINE);
6973

7074
crate_res.validate(musl_res, input, &ctx).context(name).unwrap();
@@ -88,31 +92,39 @@ where
8892
// Don't test against musl if it is not available
8993
#[cfg(feature = "build-musl")]
9094
{
91-
let musl_fn = musl_extra.musl_fn.unwrap();
92-
group.bench_function("musl", |b| {
93-
b.iter(|| {
94-
let f = black_box(musl_fn);
95-
for input in benchvec.iter().copied() {
96-
input.call(f);
97-
}
98-
})
99-
});
95+
if let Some(musl_fn) = musl_extra.musl_fn {
96+
group.bench_function("musl", |b| {
97+
b.iter(|| {
98+
let f = black_box(musl_fn);
99+
for input in benchvec.iter().copied() {
100+
input.call(f);
101+
}
102+
})
103+
});
104+
}
100105
}
101106
}
102107

103108
libm_macros::for_each_function! {
104109
callback: musl_rand_benches,
105110
skip: [],
106111
fn_extra: match MACRO_FN_NAME {
107-
// FIXME(correctness): wrong result on i586
108-
exp10 | exp10f | exp2 | exp2f => true,
109-
_ => false
112+
// We pass a tuple of `(skip_on_i586, musl_fn)`. By default we never skip (false) and
113+
// we do pass a function, but there are a couple exceptions.
114+
// FIXME(correctness): exp functions have the wrong result on i586
115+
exp10 | exp10f | exp2 | exp2f => (
116+
true, Some(musl_math_sys::MACRO_FN_NAME as <Op as MathOp>::CFn)
117+
),
118+
// Musl does not provide `f16` and `f128` functions
119+
copysignf16 | copysignf128 | fabsf16 | fabsf128 => (false, None),
120+
_ => (false, Some(musl_math_sys::MACRO_FN_NAME as <Op as MathOp>::CFn))
110121
}
111122
}
112123

113124
macro_rules! run_callback {
114125
(
115126
fn_name: $fn_name:ident,
127+
attrs: [$($meta:meta)*],
116128
extra: [$criterion:ident],
117129
) => {
118130
paste::paste! {

crates/libm-test/src/mpfloat.rs

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,23 @@ libm_macros::for_each_function! {
157157

158158
/// Implement unary functions that don't have a `_round` version
159159
macro_rules! impl_no_round {
160-
// Unary matcher
161-
($($fn_name:ident, $rug_name:ident;)*) => {
160+
($($fn_name:ident, $rug_name:ident $(, @include $f16_ty:ty, $f128_ty:ty )?;)*) => {
162161
paste::paste! {
163162
// Implement for both f32 and f64
164163
$(
165-
#[cfg(f16_enabled)]
166-
impl_no_round!{ @inner_unary [< $fn_name f16 >], $rug_name }
167-
)*
168-
$( impl_no_round!{ @inner_unary [< $fn_name f >], $rug_name } )*
169-
$( impl_no_round!{ @inner_unary $fn_name, $rug_name } )*
170-
$(
171-
#[cfg(f128_enabled)]
172-
impl_no_round!{ @inner_unary [< $fn_name f128 >], $rug_name }
164+
165+
impl_no_round!{ @inner_unary [< $fn_name f >], $rug_name }
166+
impl_no_round!{ @inner_unary $fn_name, $rug_name }
167+
168+
$(
169+
// Possibly implement for `f16` and `f128`. We shouldn't need to match
170+
// `f16_ty` and `f128_ty` (we know what they are...) but this gets us around
171+
// the "repeat an expression containing no syntax variables" error.
172+
#[cfg(f16_enabled)]
173+
impl_no_round!{ @inner_unary [< $fn_name $f16_ty >], $rug_name }
174+
#[cfg(f128_enabled)]
175+
impl_no_round!{ @inner_unary [< $fn_name $f128_ty >], $rug_name }
176+
)?
173177
)*
174178
}
175179
};
@@ -192,7 +196,7 @@ macro_rules! impl_no_round {
192196
}
193197

194198
impl_no_round! {
195-
fabs, abs_mut;
199+
fabs, abs_mut, @include f16, f128;
196200
ceil, ceil_mut;
197201
floor, floor_mut;
198202
rint, round_even_mut; // FIXME: respect rounding mode
@@ -322,45 +326,33 @@ impl MpOp for crate::op::lgammaf_r::Routine {
322326
// Not all `f16` and `f128` functions exist yet so we can't easily use the macros.
323327

324328
#[cfg(f16_enabled)]
325-
pub mod copysignf16 {
326-
use super::*;
327-
pub struct Operation(MpFloat, MpFloat);
328-
329-
impl MpOp for Operation {
330-
type Input = (f16, f16);
331-
type Output = f16;
329+
impl MpOp for crate::op::copysignf16::Routine {
330+
type MpTy = (MpFloat, MpFloat);
332331

333-
fn new() -> Self {
334-
Self(new_mpfloat::<f16>(), new_mpfloat::<f16>())
335-
}
332+
fn new_mp() -> Self::MpTy {
333+
(new_mpfloat::<f16>(), new_mpfloat::<f16>())
334+
}
336335

337-
fn run(&mut self, input: Self::Input) -> Self::Output {
338-
self.0.assign(input.0);
339-
self.1.assign(input.1);
340-
self.0.copysign_mut(&self.1);
341-
prep_retval::<Self::Output>(&mut self.0, Ordering::Equal)
342-
}
336+
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
337+
this.0.assign(input.0);
338+
this.1.assign(input.1);
339+
this.0.copysign_mut(&this.1);
340+
prep_retval::<Self::RustRet>(&mut this.0, Ordering::Equal)
343341
}
344342
}
345343

346344
#[cfg(f128_enabled)]
347-
pub mod copysignf128 {
348-
use super::*;
349-
pub struct Operation(MpFloat, MpFloat);
350-
351-
impl MpOp for Operation {
352-
type Input = (f128, f128);
353-
type Output = f128;
345+
impl MpOp for crate::op::copysignf128::Routine {
346+
type MpTy = (MpFloat, MpFloat);
354347

355-
fn new() -> Self {
356-
Self(new_mpfloat::<f128>(), new_mpfloat::<f128>())
357-
}
348+
fn new_mp() -> Self::MpTy {
349+
(new_mpfloat::<f128>(), new_mpfloat::<f128>())
350+
}
358351

359-
fn run(&mut self, input: Self::Input) -> Self::Output {
360-
self.0.assign(input.0);
361-
self.1.assign(input.1);
362-
self.0.copysign_mut(&self.1);
363-
prep_retval::<Self::Output>(&mut self.0, Ordering::Equal)
364-
}
352+
fn run(this: &mut Self::MpTy, input: Self::RustArgs) -> Self::RustRet {
353+
this.0.assign(input.0);
354+
this.1.assign(input.1);
355+
this.0.copysign_mut(&this.1);
356+
prep_retval::<Self::RustRet>(&mut this.0, Ordering::Equal)
365357
}
366358
}

crates/libm-test/src/op.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ macro_rules! do_thing {
8181
RustFn: $RustFn:ty,
8282
RustArgs: $RustArgs:ty,
8383
RustRet: $RustRet:ty,
84+
attrs: [$($meta:meta)*],
8485
) => {
8586
paste::paste! {
8687
pub mod $fn_name {

crates/libm-test/src/test_traits.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ where
349349

350350
impl_float!(f32, f64);
351351

352+
#[cfg(f16_enabled)]
353+
impl_float!(f16);
354+
355+
#[cfg(f128_enabled)]
356+
impl_float!(f128);
357+
352358
/* trait implementations for compound types */
353359

354360
/// Implement `CheckOutput` for combinations of types.

0 commit comments

Comments
 (0)