Skip to content

Commit 04a25f8

Browse files
committed
float: Add f16 to test-float-parse
1 parent a0778ea commit 04a25f8

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3656,7 +3656,7 @@ impl Step for TestFloatParse {
36563656
builder.ensure(tool::TestFloatParse { host: self.host });
36573657

36583658
// Run any unit tests in the crate
3659-
let cargo_test = tool::prepare_tool_cargo(
3659+
let mut cargo_test = tool::prepare_tool_cargo(
36603660
builder,
36613661
compiler,
36623662
Mode::ToolStd,
@@ -3666,6 +3666,7 @@ impl Step for TestFloatParse {
36663666
SourceType::InTree,
36673667
&[],
36683668
);
3669+
cargo_test.allow_features("f16");
36693670

36703671
run_cargo_test(
36713672
cargo_test,
@@ -3689,6 +3690,7 @@ impl Step for TestFloatParse {
36893690
SourceType::InTree,
36903691
&[],
36913692
);
3693+
cargo_run.allow_features("f16");
36923694

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

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

Lines changed: 7 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
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:
@@ -147,12 +147,12 @@ pub trait Float:
147147
}
148148

149149
macro_rules! impl_float {
150-
($($fty:ty, $ity:ty, $bits:literal);+) => {
150+
($($fty:ty, $ity:ty);+) => {
151151
$(
152152
impl Float for $fty {
153153
type Int = $ity;
154154
type SInt = <Self::Int as Int>::Signed;
155-
const BITS: u32 = $bits;
155+
const BITS: u32 = <$ity>::BITS;
156156
const MAN_BITS: u32 = Self::MANTISSA_DIGITS - 1;
157157
const MAN_MASK: Self::Int = (Self::Int::ONE << Self::MAN_BITS) - Self::Int::ONE;
158158
const SIGN_MASK: Self::Int = Self::Int::ONE << (Self::BITS-1);
@@ -168,7 +168,7 @@ macro_rules! impl_float {
168168
}
169169
}
170170

171-
impl_float!(f32, u32, 32; f64, u64, 64);
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)