Skip to content

Commit db05f28

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 defd31e commit db05f28

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

Diff for: src/bootstrap/src/core/build_steps/test.rs

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

35693569
// Run any unit tests in the crate
3570-
let cargo_test = tool::prepare_tool_cargo(
3570+
let mut cargo_test = tool::prepare_tool_cargo(
35713571
builder,
35723572
compiler,
35733573
Mode::ToolStd,
@@ -3577,6 +3577,7 @@ impl Step for TestFloatParse {
35773577
SourceType::InTree,
35783578
&[],
35793579
);
3580+
cargo_test.allow_features("f16");
35803581

35813582
run_cargo_test(cargo_test, &[], &[], crate_name, bootstrap_host, builder);
35823583

@@ -3591,6 +3592,7 @@ impl Step for TestFloatParse {
35913592
SourceType::InTree,
35923593
&[],
35933594
);
3595+
cargo_run.allow_features("f16");
35943596

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

Diff for: src/bootstrap/src/core/build_steps/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ impl Step for TestFloatParse {
12731273
path: "src/etc/test-float-parse",
12741274
source_type: SourceType::InTree,
12751275
extra_features: Vec::new(),
1276-
allow_features: "",
1276+
allow_features: "f16",
12771277
cargo_args: Vec::new(),
12781278
artifact_kind: ToolArtifactKind::Binary,
12791279
})

Diff for: 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) {

Diff for: 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

Diff for: 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)