Skip to content

Commit d71c375

Browse files
committed
float: Add f16 to test-float-parse
1 parent 704730c commit d71c375

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,7 @@ impl Step for TestFloatParse {
35383538
builder.ensure(compile::Std::new(compiler, self.host));
35393539

35403540
// Run any unit tests in the crate
3541-
let cargo_test = tool::prepare_tool_cargo(
3541+
let mut cargo_test = tool::prepare_tool_cargo(
35423542
builder,
35433543
compiler,
35443544
Mode::ToolStd,
@@ -3548,6 +3548,7 @@ impl Step for TestFloatParse {
35483548
SourceType::InTree,
35493549
&[],
35503550
);
3551+
cargo_test.allow_features("f16");
35513552

35523553
run_cargo_test(
35533554
cargo_test,
@@ -3571,6 +3572,7 @@ impl Step for TestFloatParse {
35713572
SourceType::InTree,
35723573
&[],
35733574
);
3575+
cargo_run.allow_features("f16");
35743576

35753577
cargo_run.arg("--");
35763578
if builder.config.args().is_empty() {

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

+4-4
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)