Skip to content

Commit 3bb0af3

Browse files
committedMar 8, 2025
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 f55bff2 commit 3bb0af3

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed
 

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

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

35673567
// Run any unit tests in the crate
3568-
let cargo_test = tool::prepare_tool_cargo(
3568+
let mut cargo_test = tool::prepare_tool_cargo(
35693569
builder,
35703570
compiler,
35713571
Mode::ToolStd,
@@ -3575,6 +3575,7 @@ impl Step for TestFloatParse {
35753575
SourceType::InTree,
35763576
&[],
35773577
);
3578+
cargo_test.allow_features("f16");
35783579

35793580
run_cargo_test(cargo_test, &[], &[], crate_name, bootstrap_host, builder);
35803581

@@ -3589,6 +3590,7 @@ impl Step for TestFloatParse {
35893590
SourceType::InTree,
35903591
&[],
35913592
);
3593+
cargo_run.allow_features("f16");
35923594

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ impl Step for TestFloatParse {
12451245
path: "src/etc/test-float-parse",
12461246
source_type: SourceType::InTree,
12471247
extra_features: Vec::new(),
1248-
allow_features: "",
1248+
allow_features: "f16",
12491249
cargo_args: Vec::new(),
12501250
artifact_kind: ToolArtifactKind::Binary,
12511251
})

‎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

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(f16)]
2+
13
mod traits;
24
mod ui;
35
mod validate;
@@ -114,6 +116,7 @@ pub fn register_tests(cfg: &Config) -> Vec<TestInfo> {
114116
let mut tests = Vec::new();
115117

116118
// Register normal generators for all floats.
119+
register_float::<f16>(&mut tests, cfg);
117120
register_float::<f32>(&mut tests, cfg);
118121
register_float::<f64>(&mut tests, cfg);
119122

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

+2-2
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:
@@ -168,7 +168,7 @@ macro_rules! impl_float {
168168
}
169169
}
170170

171-
impl_float!(f32, u32; f64, u64);
171+
impl_float!(f16, u16; f32, u32; f64, u64);
172172

173173
/// A test generator. Should provide an iterator that produces unique patterns to parse.
174174
///

0 commit comments

Comments
 (0)