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

Commit 514d2f0

Browse files
committed
Make the compiler-builtins test more accurately mirror compiler-builtins
In `compiler-builtins`, `libm` is contained within a `math` module. The smoke test in this repo has a slightly different layout so some things were passing that shouldn't be. Change module layouts in `compiler-builtins-smoke-test` to match `compiler-builtins` and update a few instances of broken paths.
1 parent 36a9f98 commit 514d2f0

File tree

4 files changed

+186
-185
lines changed

4 files changed

+186
-185
lines changed

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

Lines changed: 2 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -10,187 +10,6 @@
1010
#![allow(internal_features)]
1111
#![no_std]
1212

13-
#[allow(dead_code)]
14-
#[allow(clippy::all)] // We don't get `libm`'s list of `allow`s, so just ignore Clippy.
15-
#[path = "../../../src/math/mod.rs"]
16-
pub mod libm;
17-
18-
use core::ffi::c_int;
19-
13+
mod math;
2014
// Required for macro paths.
21-
use libm::support;
22-
23-
/// Mark functions `#[no_mangle]` and with the C ABI.
24-
macro_rules! no_mangle {
25-
($( $name:ident( $($tt:tt)+ ) -> $ret:ty; )+) => {
26-
$( no_mangle!(@inner $name( $($tt)+ ) -> $ret); )+
27-
};
28-
29-
// Handle simple functions with single return types
30-
(@inner $name:ident( $($arg:ident: $aty:ty),+ ) -> $ret:ty) => {
31-
#[no_mangle]
32-
extern "C" fn $name($($arg: $aty),+) -> $ret {
33-
libm::$name($($arg),+)
34-
}
35-
};
36-
37-
38-
// Functions with `&mut` return values need to be handled differently, use `|` to
39-
// separate inputs vs. outputs.
40-
(
41-
@inner $name:ident( $($arg:ident: $aty:ty),+ | $($rarg:ident: $rty:ty),+) -> $ret:ty
42-
) => {
43-
#[no_mangle]
44-
extern "C" fn $name($($arg: $aty,)+ $($rarg: $rty),+) -> $ret {
45-
let ret;
46-
(ret, $(*$rarg),+) = libm::$name($($arg),+);
47-
ret
48-
}
49-
};
50-
}
51-
52-
no_mangle! {
53-
frexp(x: f64 | y: &mut c_int) -> f64;
54-
frexpf(x: f32 | y: &mut c_int) -> f32;
55-
acos(x: f64) -> f64;
56-
acosf(x: f32) -> f32;
57-
acosh(x: f64) -> f64;
58-
acoshf(x: f32) -> f32;
59-
asin(x: f64) -> f64;
60-
asinf(x: f32) -> f32;
61-
asinh(x: f64) -> f64;
62-
asinhf(x: f32) -> f32;
63-
atan(x: f64) -> f64;
64-
atan2(x: f64, y: f64) -> f64;
65-
atan2f(x: f32, y: f32) -> f32;
66-
atanf(x: f32) -> f32;
67-
atanh(x: f64) -> f64;
68-
atanhf(x: f32) -> f32;
69-
cbrt(x: f64) -> f64;
70-
cbrtf(x: f32) -> f32;
71-
ceil(x: f64) -> f64;
72-
ceilf(x: f32) -> f32;
73-
ceilf128(x: f128) -> f128;
74-
ceilf16(x: f16) -> f16;
75-
copysign(x: f64, y: f64) -> f64;
76-
copysignf(x: f32, y: f32) -> f32;
77-
copysignf128(x: f128, y: f128) -> f128;
78-
copysignf16(x: f16, y: f16) -> f16;
79-
cos(x: f64) -> f64;
80-
cosf(x: f32) -> f32;
81-
cosh(x: f64) -> f64;
82-
coshf(x: f32) -> f32;
83-
erf(x: f64) -> f64;
84-
erfc(x: f64) -> f64;
85-
erfcf(x: f32) -> f32;
86-
erff(x: f32) -> f32;
87-
exp(x: f64) -> f64;
88-
exp10(x: f64) -> f64;
89-
exp10f(x: f32) -> f32;
90-
exp2(x: f64) -> f64;
91-
exp2f(x: f32) -> f32;
92-
expf(x: f32) -> f32;
93-
expm1(x: f64) -> f64;
94-
expm1f(x: f32) -> f32;
95-
fabs(x: f64) -> f64;
96-
fabsf(x: f32) -> f32;
97-
fabsf128(x: f128) -> f128;
98-
fabsf16(x: f16) -> f16;
99-
fdim(x: f64, y: f64) -> f64;
100-
fdimf(x: f32, y: f32) -> f32;
101-
fdimf128(x: f128, y: f128) -> f128;
102-
fdimf16(x: f16, y: f16) -> f16;
103-
floor(x: f64) -> f64;
104-
floorf(x: f32) -> f32;
105-
floorf128(x: f128) -> f128;
106-
floorf16(x: f16) -> f16;
107-
fma(x: f64, y: f64, z: f64) -> f64;
108-
fmaf(x: f32, y: f32, z: f32) -> f32;
109-
fmax(x: f64, y: f64) -> f64;
110-
fmaxf(x: f32, y: f32) -> f32;
111-
fmin(x: f64, y: f64) -> f64;
112-
fminf(x: f32, y: f32) -> f32;
113-
fmod(x: f64, y: f64) -> f64;
114-
fmodf(x: f32, y: f32) -> f32;
115-
hypot(x: f64, y: f64) -> f64;
116-
hypotf(x: f32, y: f32) -> f32;
117-
ilogb(x: f64) -> c_int;
118-
ilogbf(x: f32) -> c_int;
119-
j0(x: f64) -> f64;
120-
j0f(x: f32) -> f32;
121-
j1(x: f64) -> f64;
122-
j1f(x: f32) -> f32;
123-
jn(x: c_int, y: f64) -> f64;
124-
jnf(x: c_int, y: f32) -> f32;
125-
ldexp(x: f64, y: c_int) -> f64;
126-
ldexpf(x: f32, y: c_int) -> f32;
127-
lgamma(x: f64) -> f64;
128-
lgamma_r(x: f64 | r: &mut c_int) -> f64;
129-
lgammaf(x: f32) -> f32;
130-
lgammaf_r(x: f32 | r: &mut c_int) -> f32;
131-
log(x: f64) -> f64;
132-
log10(x: f64) -> f64;
133-
log10f(x: f32) -> f32;
134-
log1p(x: f64) -> f64;
135-
log1pf(x: f32) -> f32;
136-
log2(x: f64) -> f64;
137-
log2f(x: f32) -> f32;
138-
logf(x: f32) -> f32;
139-
modf(x: f64 | r: &mut f64) -> f64;
140-
modff(x: f32 | r: &mut f32) -> f32;
141-
nextafter(x: f64, y: f64) -> f64;
142-
nextafterf(x: f32, y: f32) -> f32;
143-
pow(x: f64, y: f64) -> f64;
144-
powf(x: f32, y: f32) -> f32;
145-
remainder(x: f64, y: f64) -> f64;
146-
remainderf(x: f32, y: f32) -> f32;
147-
remquo(x: f64, y: f64 | q: &mut c_int) -> f64;
148-
remquof(x: f32, y: f32 | q: &mut c_int) -> f32;
149-
rint(x: f64) -> f64;
150-
rintf(x: f32) -> f32;
151-
rintf128(x: f128) -> f128;
152-
rintf16(x: f16) -> f16;
153-
round(x: f64) -> f64;
154-
roundf(x: f32) -> f32;
155-
scalbn(x: f64, y: c_int) -> f64;
156-
scalbnf(x: f32, y: c_int) -> f32;
157-
sin(x: f64) -> f64;
158-
sinf(x: f32) -> f32;
159-
sinh(x: f64) -> f64;
160-
sinhf(x: f32) -> f32;
161-
sqrt(x: f64) -> f64;
162-
sqrtf(x: f32) -> f32;
163-
tan(x: f64) -> f64;
164-
tanf(x: f32) -> f32;
165-
tanh(x: f64) -> f64;
166-
tanhf(x: f32) -> f32;
167-
tgamma(x: f64) -> f64;
168-
tgammaf(x: f32) -> f32;
169-
trunc(x: f64) -> f64;
170-
truncf(x: f32) -> f32;
171-
truncf128(x: f128) -> f128;
172-
truncf16(x: f16) -> f16;
173-
y0(x: f64) -> f64;
174-
y0f(x: f32) -> f32;
175-
y1(x: f64) -> f64;
176-
y1f(x: f32) -> f32;
177-
yn(x: c_int, y: f64) -> f64;
178-
ynf(x: c_int, y: f32) -> f32;
179-
}
180-
181-
/* sincos has no direct return type, not worth handling in the macro */
182-
183-
#[no_mangle]
184-
extern "C" fn sincos(x: f64, s: &mut f64, c: &mut f64) {
185-
(*s, *c) = libm::sincos(x);
186-
}
187-
188-
#[no_mangle]
189-
extern "C" fn sincosf(x: f32, s: &mut f32, c: &mut f32) {
190-
(*s, *c) = libm::sincosf(x);
191-
}
192-
193-
#[panic_handler]
194-
fn panic(_info: &core::panic::PanicInfo) -> ! {
195-
loop {}
196-
}
15+
use math::libm::support;
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
use core::ffi::c_int;
2+
3+
#[allow(dead_code)]
4+
#[allow(clippy::all)] // We don't get `libm`'s list of `allow`s, so just ignore Clippy.
5+
#[allow(unused_imports)]
6+
#[path = "../../../src/math/mod.rs"]
7+
pub mod libm;
8+
9+
/// Mark functions `#[no_mangle]` and with the C ABI.
10+
macro_rules! no_mangle {
11+
($( $name:ident( $($tt:tt)+ ) -> $ret:ty; )+) => {
12+
$( no_mangle!(@inner $name( $($tt)+ ) -> $ret); )+
13+
};
14+
15+
// Handle simple functions with single return types
16+
(@inner $name:ident( $($arg:ident: $aty:ty),+ ) -> $ret:ty) => {
17+
#[no_mangle]
18+
extern "C" fn $name($($arg: $aty),+) -> $ret {
19+
libm::$name($($arg),+)
20+
}
21+
};
22+
23+
24+
// Functions with `&mut` return values need to be handled differently, use `|` to
25+
// separate inputs vs. outputs.
26+
(
27+
@inner $name:ident( $($arg:ident: $aty:ty),+ | $($rarg:ident: $rty:ty),+) -> $ret:ty
28+
) => {
29+
#[no_mangle]
30+
extern "C" fn $name($($arg: $aty,)+ $($rarg: $rty),+) -> $ret {
31+
let ret;
32+
(ret, $(*$rarg),+) = libm::$name($($arg),+);
33+
ret
34+
}
35+
};
36+
}
37+
38+
no_mangle! {
39+
frexp(x: f64 | y: &mut c_int) -> f64;
40+
frexpf(x: f32 | y: &mut c_int) -> f32;
41+
acos(x: f64) -> f64;
42+
acosf(x: f32) -> f32;
43+
acosh(x: f64) -> f64;
44+
acoshf(x: f32) -> f32;
45+
asin(x: f64) -> f64;
46+
asinf(x: f32) -> f32;
47+
asinh(x: f64) -> f64;
48+
asinhf(x: f32) -> f32;
49+
atan(x: f64) -> f64;
50+
atan2(x: f64, y: f64) -> f64;
51+
atan2f(x: f32, y: f32) -> f32;
52+
atanf(x: f32) -> f32;
53+
atanh(x: f64) -> f64;
54+
atanhf(x: f32) -> f32;
55+
cbrt(x: f64) -> f64;
56+
cbrtf(x: f32) -> f32;
57+
ceil(x: f64) -> f64;
58+
ceilf(x: f32) -> f32;
59+
ceilf128(x: f128) -> f128;
60+
ceilf16(x: f16) -> f16;
61+
copysign(x: f64, y: f64) -> f64;
62+
copysignf(x: f32, y: f32) -> f32;
63+
copysignf128(x: f128, y: f128) -> f128;
64+
copysignf16(x: f16, y: f16) -> f16;
65+
cos(x: f64) -> f64;
66+
cosf(x: f32) -> f32;
67+
cosh(x: f64) -> f64;
68+
coshf(x: f32) -> f32;
69+
erf(x: f64) -> f64;
70+
erfc(x: f64) -> f64;
71+
erfcf(x: f32) -> f32;
72+
erff(x: f32) -> f32;
73+
exp(x: f64) -> f64;
74+
exp10(x: f64) -> f64;
75+
exp10f(x: f32) -> f32;
76+
exp2(x: f64) -> f64;
77+
exp2f(x: f32) -> f32;
78+
expf(x: f32) -> f32;
79+
expm1(x: f64) -> f64;
80+
expm1f(x: f32) -> f32;
81+
fabs(x: f64) -> f64;
82+
fabsf(x: f32) -> f32;
83+
fabsf128(x: f128) -> f128;
84+
fabsf16(x: f16) -> f16;
85+
fdim(x: f64, y: f64) -> f64;
86+
fdimf(x: f32, y: f32) -> f32;
87+
fdimf128(x: f128, y: f128) -> f128;
88+
fdimf16(x: f16, y: f16) -> f16;
89+
floor(x: f64) -> f64;
90+
floorf(x: f32) -> f32;
91+
floorf128(x: f128) -> f128;
92+
floorf16(x: f16) -> f16;
93+
fma(x: f64, y: f64, z: f64) -> f64;
94+
fmaf(x: f32, y: f32, z: f32) -> f32;
95+
fmax(x: f64, y: f64) -> f64;
96+
fmaxf(x: f32, y: f32) -> f32;
97+
fmin(x: f64, y: f64) -> f64;
98+
fminf(x: f32, y: f32) -> f32;
99+
fmod(x: f64, y: f64) -> f64;
100+
fmodf(x: f32, y: f32) -> f32;
101+
hypot(x: f64, y: f64) -> f64;
102+
hypotf(x: f32, y: f32) -> f32;
103+
ilogb(x: f64) -> c_int;
104+
ilogbf(x: f32) -> c_int;
105+
j0(x: f64) -> f64;
106+
j0f(x: f32) -> f32;
107+
j1(x: f64) -> f64;
108+
j1f(x: f32) -> f32;
109+
jn(x: c_int, y: f64) -> f64;
110+
jnf(x: c_int, y: f32) -> f32;
111+
ldexp(x: f64, y: c_int) -> f64;
112+
ldexpf(x: f32, y: c_int) -> f32;
113+
lgamma(x: f64) -> f64;
114+
lgamma_r(x: f64 | r: &mut c_int) -> f64;
115+
lgammaf(x: f32) -> f32;
116+
lgammaf_r(x: f32 | r: &mut c_int) -> f32;
117+
log(x: f64) -> f64;
118+
log10(x: f64) -> f64;
119+
log10f(x: f32) -> f32;
120+
log1p(x: f64) -> f64;
121+
log1pf(x: f32) -> f32;
122+
log2(x: f64) -> f64;
123+
log2f(x: f32) -> f32;
124+
logf(x: f32) -> f32;
125+
modf(x: f64 | r: &mut f64) -> f64;
126+
modff(x: f32 | r: &mut f32) -> f32;
127+
nextafter(x: f64, y: f64) -> f64;
128+
nextafterf(x: f32, y: f32) -> f32;
129+
pow(x: f64, y: f64) -> f64;
130+
powf(x: f32, y: f32) -> f32;
131+
remainder(x: f64, y: f64) -> f64;
132+
remainderf(x: f32, y: f32) -> f32;
133+
remquo(x: f64, y: f64 | q: &mut c_int) -> f64;
134+
remquof(x: f32, y: f32 | q: &mut c_int) -> f32;
135+
rint(x: f64) -> f64;
136+
rintf(x: f32) -> f32;
137+
rintf128(x: f128) -> f128;
138+
rintf16(x: f16) -> f16;
139+
round(x: f64) -> f64;
140+
roundf(x: f32) -> f32;
141+
scalbn(x: f64, y: c_int) -> f64;
142+
scalbnf(x: f32, y: c_int) -> f32;
143+
sin(x: f64) -> f64;
144+
sinf(x: f32) -> f32;
145+
sinh(x: f64) -> f64;
146+
sinhf(x: f32) -> f32;
147+
sqrt(x: f64) -> f64;
148+
sqrtf(x: f32) -> f32;
149+
tan(x: f64) -> f64;
150+
tanf(x: f32) -> f32;
151+
tanh(x: f64) -> f64;
152+
tanhf(x: f32) -> f32;
153+
tgamma(x: f64) -> f64;
154+
tgammaf(x: f32) -> f32;
155+
trunc(x: f64) -> f64;
156+
truncf(x: f32) -> f32;
157+
truncf128(x: f128) -> f128;
158+
truncf16(x: f16) -> f16;
159+
y0(x: f64) -> f64;
160+
y0f(x: f32) -> f32;
161+
y1(x: f64) -> f64;
162+
y1f(x: f32) -> f32;
163+
yn(x: c_int, y: f64) -> f64;
164+
ynf(x: c_int, y: f32) -> f32;
165+
}
166+
167+
/* sincos has no direct return type, not worth handling in the macro */
168+
169+
#[no_mangle]
170+
extern "C" fn sincos(x: f64, s: &mut f64, c: &mut f64) {
171+
(*s, *c) = libm::sincos(x);
172+
}
173+
174+
#[no_mangle]
175+
extern "C" fn sincosf(x: f32, s: &mut f32, c: &mut f32) {
176+
(*s, *c) = libm::sincosf(x);
177+
}
178+
179+
#[panic_handler]
180+
fn panic(_info: &core::panic::PanicInfo) -> ! {
181+
loop {}
182+
}

libm/src/math/fma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* SPDX-License-Identifier: MIT */
22
/* origin: musl src/math/fma.c. Ported to generic Rust algorithm in 2025, TG. */
33

4-
use super::super::support::{DInt, FpResult, HInt, IntTy, Round, Status};
4+
use super::support::{DInt, FpResult, HInt, IntTy, Round, Status};
55
use super::{CastFrom, CastInto, Float, Int, MinInt};
66

77
/// Fused multiply add (f64)

libm/src/math/fma_wide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* SPDX-License-Identifier: MIT */
22
/* origin: musl src/math/fmaf.c. Ported to generic Rust algorithm in 2025, TG. */
33

4-
use super::super::support::{FpResult, IntTy, Round, Status};
4+
use super::support::{FpResult, IntTy, Round, Status};
55
use super::{CastFrom, CastInto, DFloat, Float, HFloat, MinInt};
66

77
// Placeholder so we can have `fmaf16` in the `Float` trait.

0 commit comments

Comments
 (0)