Skip to content

Commit 4638679

Browse files
committed
float: Add f16 to test-float-parse
This requires a fix to the subnormal test to cap the maximum allowed value within the maximum mantissa.
1 parent 000c92c commit 4638679

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

src/bootstrap/src/core/build_steps/test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3554,7 +3554,7 @@ impl Step for TestFloatParse {
35543554
builder.ensure(tool::TestFloatParse { host: self.host });
35553555

35563556
// Run any unit tests in the crate
3557-
let cargo_test = tool::prepare_tool_cargo(
3557+
let mut cargo_test = tool::prepare_tool_cargo(
35583558
builder,
35593559
compiler,
35603560
Mode::ToolStd,
@@ -3564,6 +3564,7 @@ impl Step for TestFloatParse {
35643564
SourceType::InTree,
35653565
&[],
35663566
);
3567+
cargo_test.allow_features(tool::TestFloatParse::ALLOW_FEATURES);
35673568

35683569
run_cargo_test(cargo_test, &[], &[], crate_name, bootstrap_host, builder);
35693570

@@ -3578,6 +3579,7 @@ impl Step for TestFloatParse {
35783579
SourceType::InTree,
35793580
&[],
35803581
);
3582+
cargo_run.allow_features(tool::TestFloatParse::ALLOW_FEATURES);
35813583

35823584
if !matches!(env::var("FLOAT_PARSE_TESTS_NO_SKIP_HUGE").as_deref(), Ok("1") | Ok("true")) {
35833585
cargo_run.args(["--", "--skip-huge"]);

src/bootstrap/src/core/build_steps/tool.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,10 @@ pub struct TestFloatParse {
12591259
pub host: TargetSelection,
12601260
}
12611261

1262+
impl TestFloatParse {
1263+
pub const ALLOW_FEATURES: &'static str = "f16,cfg_target_has_reliable_f16_f128";
1264+
}
1265+
12621266
impl Step for TestFloatParse {
12631267
type Output = ToolBuildResult;
12641268
const ONLY_HOSTS: bool = true;
@@ -1280,7 +1284,7 @@ impl Step for TestFloatParse {
12801284
path: "src/etc/test-float-parse",
12811285
source_type: SourceType::InTree,
12821286
extra_features: Vec::new(),
1283-
allow_features: "",
1287+
allow_features: Self::ALLOW_FEATURES,
12841288
cargo_args: Vec::new(),
12851289
artifact_kind: ToolArtifactKind::Binary,
12861290
})

src/etc/test-float-parse/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ rayon = "1"
1313

1414
[lib]
1515
name = "test_float_parse"
16+
17+
[lints.rust.unexpected_cfgs]
18+
level = "warn"
19+
check-cfg = [
20+
# Internal features aren't marked known config by default
21+
'cfg(target_has_reliable_f16)',
22+
]

src/etc/test-float-parse/src/gen_/subnorm.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::cmp::min;
21
use std::fmt::Write;
32
use std::ops::RangeInclusive;
43

@@ -83,7 +82,13 @@ where
8382
}
8483

8584
fn new() -> Self {
86-
Self { iter: F::Int::ZERO..=min(F::Int::ONE << 22, F::MAN_BITS.try_into().unwrap()) }
85+
let upper_lim = if F::MAN_BITS >= 22 {
86+
F::Int::ONE << 22
87+
} else {
88+
(F::Int::ONE << F::MAN_BITS) - F::Int::ONE
89+
};
90+
91+
Self { iter: F::Int::ZERO..=upper_lim }
8792
}
8893

8994
fn write_string(s: &mut String, ctx: Self::WriteCtx) {

src/etc/test-float-parse/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#![feature(f16)]
2+
#![feature(cfg_target_has_reliable_f16_f128)]
3+
#![expect(internal_features)] // reliable_f16_f128
4+
15
mod traits;
26
mod ui;
37
mod validate;
@@ -114,6 +118,9 @@ pub fn register_tests(cfg: &Config) -> Vec<TestInfo> {
114118
let mut tests = Vec::new();
115119

116120
// Register normal generators for all floats.
121+
122+
#[cfg(target_has_reliable_f16)]
123+
register_float::<f16>(&mut tests, cfg);
117124
register_float::<f32>(&mut tests, cfg);
118125
register_float::<f64>(&mut tests, cfg);
119126

src/etc/test-float-parse/src/traits.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ macro_rules! impl_int {
9898
}
9999
}
100100

101-
impl_int!(u32, i32; u64, i64);
101+
impl_int!(u16, i16; u32, i32; u64, i64);
102102

103103
/// Floating point types.
104104
pub trait Float:
@@ -170,6 +170,9 @@ macro_rules! impl_float {
170170

171171
impl_float!(f32, u32; f64, u64);
172172

173+
#[cfg(target_has_reliable_f16)]
174+
impl_float!(f16, u16);
175+
173176
/// A test generator. Should provide an iterator that produces unique patterns to parse.
174177
///
175178
/// The iterator needs to provide a `WriteCtx` (could be anything), which is then used to

0 commit comments

Comments
 (0)