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

Commit b7f0fad

Browse files
committed
Replace cfg with target_has_reliable_f16
1 parent e2a443e commit b7f0fad

File tree

10 files changed

+70
-30
lines changed

10 files changed

+70
-30
lines changed

library/coretests/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ test = true
2626
[dev-dependencies]
2727
rand = { version = "0.9.0", default-features = false }
2828
rand_xorshift = { version = "0.4.0", default-features = false }
29+
30+
[lints.rust.unexpected_cfgs]
31+
level = "warn"
32+
check-cfg = [
33+
'cfg(bootstrap)',
34+
# Internal features aren't marked known config by default, we use these to
35+
# gate tests.
36+
'cfg(target_has_reliable_f16)',
37+
]

library/coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(async_iterator)]
1313
#![feature(bigint_helper_methods)]
1414
#![feature(bstr)]
15+
#![feature(cfg_target_has_reliable_f16_f128)]
1516
#![feature(char_max_len)]
1617
#![feature(clone_to_uninit)]
1718
#![feature(const_eval_select)]

library/coretests/tests/num/dec2flt/decimal.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const FPATHS_F64: &[FPath<f64>] =
99

1010
// FIXME(f16_f128): enable on all targets once possible.
1111
#[test]
12-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
12+
#[cfg(not(bootstrap))]
13+
#[cfg(target_has_reliable_f16)]
1314
fn check_fast_path_f16() {
1415
const FPATHS_F16: &[FPath<f16>] =
1516
&[((0, 0, false, false), Some(0.0)), ((0, 0, false, false), Some(0.0))];

library/coretests/tests/num/dec2flt/float.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use core::num::dec2flt::float::RawFloat;
22

33
// FIXME(f16_f128): enable on all targets once possible.
44
#[test]
5-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
5+
#[cfg(not(bootstrap))]
6+
#[cfg(target_has_reliable_f16)]
67
fn test_f16_integer_decode() {
78
assert_eq!(3.14159265359f16.integer_decode(), (1608, -9, 1));
89
assert_eq!((-8573.5918555f16).integer_decode(), (1072, 3, -1));
@@ -54,7 +55,8 @@ fn test_f64_integer_decode() {
5455

5556
// FIXME(f16_f128): enable on all targets once possible.
5657
#[test]
57-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
58+
#[cfg(not(bootstrap))]
59+
#[cfg(target_has_reliable_f16)]
5860
fn test_f16_consts() {
5961
assert_eq!(<f16 as RawFloat>::INFINITY, f16::INFINITY);
6062
assert_eq!(<f16 as RawFloat>::NEG_INFINITY, -f16::INFINITY);

library/coretests/tests/num/dec2flt/lemire.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use core::num::dec2flt::float::RawFloat;
22
use core::num::dec2flt::lemire::compute_float;
33

4-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
4+
#[cfg(not(bootstrap))]
5+
#[cfg(target_has_reliable_f16)]
56
fn compute_float16(q: i64, w: u64) -> (i32, u64) {
67
let fp = compute_float::<f16>(q, w);
78
(fp.p_biased, fp.m)
@@ -19,7 +20,8 @@ fn compute_float64(q: i64, w: u64) -> (i32, u64) {
1920

2021
// FIXME(f16_f128): enable on all targets once possible.
2122
#[test]
22-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
23+
#[cfg(not(bootstrap))]
24+
#[cfg(target_has_reliable_f16)]
2325
fn compute_float_f16_rounding() {
2426
// The maximum integer that cna be converted to a `f16` without lost precision.
2527
let val = 1 << 11;

library/coretests/tests/num/dec2flt/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,39 +93,44 @@ fn fast_path_correct() {
9393

9494
#[test]
9595
fn lonely_dot() {
96-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
96+
#[cfg(not(bootstrap))]
97+
#[cfg(target_has_reliable_f16)]
9798
assert!(".".parse::<f16>().is_err());
9899
assert!(".".parse::<f32>().is_err());
99100
assert!(".".parse::<f64>().is_err());
100101
}
101102

102103
#[test]
103104
fn exponentiated_dot() {
104-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
105+
#[cfg(not(bootstrap))]
106+
#[cfg(target_has_reliable_f16)]
105107
assert!(".e0".parse::<f16>().is_err());
106108
assert!(".e0".parse::<f32>().is_err());
107109
assert!(".e0".parse::<f64>().is_err());
108110
}
109111

110112
#[test]
111113
fn lonely_sign() {
112-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
114+
#[cfg(not(bootstrap))]
115+
#[cfg(target_has_reliable_f16)]
113116
assert!("+".parse::<f16>().is_err());
114117
assert!("-".parse::<f32>().is_err());
115118
assert!("+".parse::<f64>().is_err());
116119
}
117120

118121
#[test]
119122
fn whitespace() {
120-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
123+
#[cfg(not(bootstrap))]
124+
#[cfg(target_has_reliable_f16)]
121125
assert!("1.0 ".parse::<f16>().is_err());
122126
assert!(" 1.0".parse::<f32>().is_err());
123127
assert!("1.0 ".parse::<f64>().is_err());
124128
}
125129

126130
#[test]
127131
fn nan() {
128-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
132+
#[cfg(not(bootstrap))]
133+
#[cfg(target_has_reliable_f16)]
129134
{
130135
assert!("NaN".parse::<f16>().unwrap().is_nan());
131136
assert!("-NaN".parse::<f16>().unwrap().is_nan());
@@ -140,7 +145,8 @@ fn nan() {
140145

141146
#[test]
142147
fn inf() {
143-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
148+
#[cfg(not(bootstrap))]
149+
#[cfg(target_has_reliable_f16)]
144150
{
145151
assert_eq!("inf".parse(), Ok(f16::INFINITY));
146152
assert_eq!("-inf".parse(), Ok(f16::NEG_INFINITY));
@@ -155,7 +161,8 @@ fn inf() {
155161

156162
#[test]
157163
fn massive_exponent() {
158-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
164+
#[cfg(not(bootstrap))]
165+
#[cfg(target_has_reliable_f16)]
159166
{
160167
let max = i16::MAX;
161168
assert_eq!(format!("1e{max}000").parse(), Ok(f16::INFINITY));

library/coretests/tests/num/flt2dec/mod.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ macro_rules! try_fixed {
7575
})
7676
}
7777

78-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
78+
#[cfg(not(bootstrap))]
79+
#[cfg(target_has_reliable_f16)]
7980
fn ldexp_f16(a: f16, b: i32) -> f16 {
8081
ldexp_f64(a as f64, b) as f16
8182
}
@@ -181,7 +182,8 @@ trait TestableFloat: DecodableFloat + fmt::Display {
181182
fn ldexpi(f: i64, exp: isize) -> Self;
182183
}
183184

184-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
185+
#[cfg(not(bootstrap))]
186+
#[cfg(target_has_reliable_f16)]
185187
impl TestableFloat for f16 {
186188
fn ldexpi(f: i64, exp: isize) -> Self {
187189
f as Self * (exp as Self).exp2()
@@ -239,7 +241,8 @@ macro_rules! check_exact_one {
239241
// ftp://ftp.ee.lbl.gov/testbase-report.ps.Z
240242
// or https://www.icir.org/vern/papers/testbase-report.pdf
241243

242-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
244+
#[cfg(not(bootstrap))]
245+
#[cfg(target_has_reliable_f16)]
243246
pub fn f16_shortest_sanity_test<F>(mut f: F)
244247
where
245248
F: for<'a> FnMut(&Decoded, &'a mut [MaybeUninit<u8>]) -> (&'a [u8], i16),
@@ -287,7 +290,8 @@ where
287290
check_shortest!(f(minf16) => b"6", -7);
288291
}
289292

290-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
293+
#[cfg(not(bootstrap))]
294+
#[cfg(target_has_reliable_f16)]
291295
pub fn f16_exact_sanity_test<F>(mut f: F)
292296
where
293297
F: for<'a> FnMut(&Decoded, &'a mut [MaybeUninit<u8>], i16) -> (&'a [u8], i16),
@@ -635,7 +639,8 @@ where
635639
assert_eq!(to_string(f, 1.9971e20, Minus, 1), "199710000000000000000.0");
636640
assert_eq!(to_string(f, 1.9971e20, Minus, 8), "199710000000000000000.00000000");
637641

638-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
642+
#[cfg(not(bootstrap))]
643+
#[cfg(target_has_reliable_f16)]
639644
{
640645
// f16
641646
assert_eq!(to_string(f, f16::MAX, Minus, 0), "65500");
@@ -759,7 +764,8 @@ where
759764
assert_eq!(to_string(f, 1.0e23, Minus, (23, 24), false), "100000000000000000000000");
760765
assert_eq!(to_string(f, 1.0e23, Minus, (24, 25), false), "1e23");
761766

762-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
767+
#[cfg(not(bootstrap))]
768+
#[cfg(target_has_reliable_f16)]
763769
{
764770
// f16
765771
assert_eq!(to_string(f, f16::MAX, Minus, (-2, 2), false), "6.55e4");
@@ -913,7 +919,8 @@ where
913919
"9.999999999999999547481118258862586856139387236908078193664550781250000e-7"
914920
);
915921

916-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
922+
#[cfg(not(bootstrap))]
923+
#[cfg(target_has_reliable_f16)]
917924
{
918925
assert_eq!(to_string(f, f16::MAX, Minus, 1, false), "7e4");
919926
assert_eq!(to_string(f, f16::MAX, Minus, 2, false), "6.6e4");
@@ -1211,7 +1218,8 @@ where
12111218
"0.000000999999999999999954748111825886258685613938723690807819366455078125000"
12121219
);
12131220

1214-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
1221+
#[cfg(not(bootstrap))]
1222+
#[cfg(target_has_reliable_f16)]
12151223
{
12161224
assert_eq!(to_string(f, f16::MAX, Minus, 0), "65504");
12171225
assert_eq!(to_string(f, f16::MAX, Minus, 1), "65504.0");
@@ -1227,7 +1235,8 @@ where
12271235
return;
12281236
}
12291237

1230-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
1238+
#[cfg(not(bootstrap))]
1239+
#[cfg(target_has_reliable_f16)]
12311240
{
12321241
let minf16 = ldexp_f16(1.0, -24);
12331242
assert_eq!(to_string(f, minf16, Minus, 0), "0");

library/coretests/tests/num/flt2dec/random.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ where
7979
(npassed, nignored)
8080
}
8181

82-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
82+
#[cfg(not(bootstrap))]
83+
#[cfg(target_has_reliable_f16)]
8384
pub fn f16_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
8485
where
8586
F: for<'a> FnMut(&Decoded, &'a mut [MaybeUninit<u8>]) -> Option<(&'a [u8], i16)>,
@@ -119,7 +120,8 @@ where
119120
});
120121
}
121122

122-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
123+
#[cfg(not(bootstrap))]
124+
#[cfg(target_has_reliable_f16)]
123125
pub fn f16_exhaustive_equivalence_test<F, G>(f: F, g: G, k: usize)
124126
where
125127
F: for<'a> FnMut(&Decoded, &'a mut [MaybeUninit<u8>]) -> Option<(&'a [u8], i16)>,
@@ -165,13 +167,15 @@ fn shortest_random_equivalence_test() {
165167

166168
f64_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, n);
167169
f32_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, n);
168-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
170+
#[cfg(not(bootstrap))]
171+
#[cfg(target_has_reliable_f16)]
169172
f16_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, n);
170173
}
171174

172175
#[test]
173176
#[cfg_attr(miri, ignore)] // Miri is to slow
174-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
177+
#[cfg(not(bootstrap))]
178+
#[cfg(target_has_reliable_f16)]
175179
fn shortest_f16_exhaustive_equivalence_test() {
176180
// see the f32 version
177181
use core::num::flt2dec::strategy::dragon::format_shortest as fallback;
@@ -202,7 +206,8 @@ fn shortest_f64_hard_random_equivalence_test() {
202206
}
203207

204208
#[test]
205-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
209+
#[cfg(not(bootstrap))]
210+
#[cfg(target_has_reliable_f16)]
206211
fn exact_f16_random_equivalence_test() {
207212
use core::num::flt2dec::strategy::dragon::format_exact as fallback;
208213
// Miri is too slow

library/coretests/tests/num/flt2dec/strategy/dragon.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ fn test_mul_pow10() {
1818
fn shortest_sanity_test() {
1919
f64_shortest_sanity_test(format_shortest);
2020
f32_shortest_sanity_test(format_shortest);
21-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
21+
#[cfg(not(bootstrap))]
22+
#[cfg(target_has_reliable_f16)]
2223
f16_shortest_sanity_test(format_shortest);
2324
more_shortest_sanity_test(format_shortest);
2425
}
@@ -44,7 +45,8 @@ fn exact_sanity_test() {
4445
}
4546
f32_exact_sanity_test(format_exact);
4647

47-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
48+
#[cfg(not(bootstrap))]
49+
#[cfg(target_has_reliable_f16)]
4850
f16_exact_sanity_test(format_exact);
4951
}
5052

library/coretests/tests/num/flt2dec/strategy/grisu.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ fn test_max_pow10_no_more_than() {
3838
fn shortest_sanity_test() {
3939
f64_shortest_sanity_test(format_shortest);
4040
f32_shortest_sanity_test(format_shortest);
41-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
41+
#[cfg(not(bootstrap))]
42+
#[cfg(target_has_reliable_f16)]
4243
f16_shortest_sanity_test(format_shortest);
4344
more_shortest_sanity_test(format_shortest);
4445
}
@@ -52,7 +53,8 @@ fn exact_sanity_test() {
5253
f64_exact_sanity_test(format_exact);
5354
}
5455
f32_exact_sanity_test(format_exact);
55-
#[cfg(any(target_arch = "x86", all(target_arch = "aarch64", target_feature = "neon")))]
56+
#[cfg(not(bootstrap))]
57+
#[cfg(target_has_reliable_f16)]
5658
f16_exact_sanity_test(format_exact);
5759
}
5860

0 commit comments

Comments
 (0)