Skip to content

Commit c1f042b

Browse files
committed
float: Add f16 to test-float-parse
1 parent 31f6552 commit c1f042b

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

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

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

36793679
// Run any unit tests in the crate
3680-
let cargo_test = tool::prepare_tool_cargo(
3680+
let mut cargo_test = tool::prepare_tool_cargo(
36813681
builder,
36823682
compiler,
36833683
Mode::ToolStd,
@@ -3687,6 +3687,7 @@ impl Step for TestFloatParse {
36873687
SourceType::InTree,
36883688
&[],
36893689
);
3690+
cargo_test.allow_features("f16");
36903691

36913692
run_cargo_test(cargo_test, &[], &[], crate_name, crate_name, bootstrap_host, builder);
36923693

@@ -3701,6 +3702,7 @@ impl Step for TestFloatParse {
37013702
SourceType::InTree,
37023703
&[],
37033704
);
3705+
cargo_run.allow_features("f16");
37043706

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ impl Step for TestFloatParse {
12401240
path: "src/etc/test-float-parse",
12411241
source_type: SourceType::InTree,
12421242
extra_features: Vec::new(),
1243-
allow_features: "",
1243+
allow_features: "f16",
12441244
cargo_args: Vec::new(),
12451245
})
12461246
}

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

+3-3
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);

0 commit comments

Comments
 (0)