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

Commit 0492f2e

Browse files
authored
Merge pull request #489 from tgross35/sort-everything
Add checks via annotation that lists are sorted or exhaustive
2 parents 3109ebe + ad83c9a commit 0492f2e

File tree

8 files changed

+209
-85
lines changed

8 files changed

+209
-85
lines changed

crates/libm-macros/src/shared.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
1818
None,
1919
&[
2020
"acosf", "acoshf", "asinf", "asinhf", "atanf", "atanhf", "cbrtf", "ceilf", "cosf",
21-
"coshf", "erff", "erfcf", "exp10f", "exp2f", "expf", "expm1f", "fabsf", "floorf",
21+
"coshf", "erfcf", "erff", "exp10f", "exp2f", "expf", "expm1f", "fabsf", "floorf",
2222
"j0f", "j1f", "lgammaf", "log10f", "log1pf", "log2f", "logf", "rintf", "roundf",
2323
"sinf", "sinhf", "sqrtf", "tanf", "tanhf", "tgammaf", "truncf", "y0f", "y1f",
2424
],
@@ -30,8 +30,8 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
3030
None,
3131
&[
3232
"acos", "acosh", "asin", "asinh", "atan", "atanh", "cbrt", "ceil", "cos", "cosh",
33-
"erf", "erfc", "exp10", "exp2", "exp", "expm1", "fabs", "floor", "j0", "j1", "lgamma",
34-
"log10", "log1p", "log2", "log", "rint", "round", "sin", "sinh", "sqrt", "tan", "tanh",
33+
"erf", "erfc", "exp", "exp10", "exp2", "expm1", "fabs", "floor", "j0", "j1", "lgamma",
34+
"log", "log10", "log1p", "log2", "rint", "round", "sin", "sinh", "sqrt", "tan", "tanh",
3535
"tgamma", "trunc", "y0", "y1",
3636
],
3737
),
@@ -139,28 +139,28 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
139139
FloatTy::F16,
140140
Signature { args: &[Ty::F16, Ty::I32], returns: &[Ty::F16] },
141141
None,
142-
&["scalbnf16", "ldexpf16"],
142+
&["ldexpf16", "scalbnf16"],
143143
),
144144
(
145145
// `(f32, i32) -> f32`
146146
FloatTy::F32,
147147
Signature { args: &[Ty::F32, Ty::I32], returns: &[Ty::F32] },
148148
None,
149-
&["scalbnf", "ldexpf"],
149+
&["ldexpf", "scalbnf"],
150150
),
151151
(
152152
// `(f64, i64) -> f64`
153153
FloatTy::F64,
154154
Signature { args: &[Ty::F64, Ty::I32], returns: &[Ty::F64] },
155155
None,
156-
&["scalbn", "ldexp"],
156+
&["ldexp", "scalbn"],
157157
),
158158
(
159159
// `(f128, i32) -> f128`
160160
FloatTy::F128,
161161
Signature { args: &[Ty::F128, Ty::I32], returns: &[Ty::F128] },
162162
None,
163-
&["scalbnf128", "ldexpf128"],
163+
&["ldexpf128", "scalbnf128"],
164164
),
165165
(
166166
// `(f32, &mut f32) -> f32` as `(f32) -> (f32, f32)`
@@ -312,6 +312,12 @@ pub static ALL_OPERATIONS: LazyLock<Vec<MathOpInfo>> = LazyLock::new(|| {
312312
};
313313
ret.push(api);
314314
}
315+
316+
if !names.is_sorted() {
317+
let mut sorted = (*names).to_owned();
318+
sorted.sort_unstable();
319+
panic!("names list is not sorted: {names:?}\nExpected: {sorted:?}");
320+
}
315321
}
316322

317323
ret.sort_by_key(|item| item.name);

crates/libm-test/benches/icount.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ libm_macros::for_each_function! {
5252
}
5353

5454
main!(
55-
library_benchmark_groups = icount_bench_acos_group,
55+
library_benchmark_groups =
56+
// verify-apilist-start
57+
// verify-sorted-start
58+
icount_bench_acos_group,
5659
icount_bench_acosf_group,
5760
icount_bench_acosh_group,
5861
icount_bench_acoshf_group,
@@ -169,6 +172,8 @@ main!(
169172
icount_bench_scalbnf16_group,
170173
icount_bench_scalbnf_group,
171174
icount_bench_sin_group,
175+
icount_bench_sincos_group,
176+
icount_bench_sincosf_group,
172177
icount_bench_sinf_group,
173178
icount_bench_sinh_group,
174179
icount_bench_sinhf_group,
@@ -192,4 +197,6 @@ main!(
192197
icount_bench_y1f_group,
193198
icount_bench_yn_group,
194199
icount_bench_ynf_group,
200+
// verify-sorted-end
201+
// verify-apilist-end
195202
);

crates/libm-test/src/mpfloat.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ libm_macros::for_each_function! {
132132
emit_types: [RustFn],
133133
skip: [
134134
// Most of these need a manual implementation
135+
// verify-sorted-start
135136
ceil,
136137
ceilf,
137138
ceilf128,
@@ -188,6 +189,7 @@ libm_macros::for_each_function! {
188189
truncf128,
189190
truncf16,yn,
190191
ynf,
192+
// verify-sorted-end
191193
],
192194
fn_extra: match MACRO_FN_NAME {
193195
// Remap function names that are different between mpfr and libm

crates/libm-test/tests/compare_built_musl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ libm_macros::for_each_function! {
7979
ynf,
8080

8181
// Not provided by musl
82+
// verify-sorted-start
8283
ceilf128,
8384
ceilf16,
8485
copysignf128,
@@ -107,5 +108,6 @@ libm_macros::for_each_function! {
107108
sqrtf16,
108109
truncf128,
109110
truncf16,
111+
// verify-sorted-end
110112
],
111113
}

0 commit comments

Comments
 (0)