Skip to content

Commit

Permalink
float: Add f16 to test-float-parse
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Mar 2, 2025
1 parent 31f6552 commit c1f042b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3677,7 +3677,7 @@ impl Step for TestFloatParse {
builder.ensure(tool::TestFloatParse { host: self.host });

// Run any unit tests in the crate
let cargo_test = tool::prepare_tool_cargo(
let mut cargo_test = tool::prepare_tool_cargo(
builder,
compiler,
Mode::ToolStd,
Expand All @@ -3687,6 +3687,7 @@ impl Step for TestFloatParse {
SourceType::InTree,
&[],
);
cargo_test.allow_features("f16");

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

Expand All @@ -3701,6 +3702,7 @@ impl Step for TestFloatParse {
SourceType::InTree,
&[],
);
cargo_run.allow_features("f16");

if !matches!(env::var("FLOAT_PARSE_TESTS_NO_SKIP_HUGE").as_deref(), Ok("1") | Ok("true")) {
cargo_run.args(["--", "--skip-huge"]);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ impl Step for TestFloatParse {
path: "src/etc/test-float-parse",
source_type: SourceType::InTree,
extra_features: Vec::new(),
allow_features: "",
allow_features: "f16",
cargo_args: Vec::new(),
})
}
Expand Down
9 changes: 7 additions & 2 deletions src/etc/test-float-parse/src/gen/subnorm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cmp::min;
use std::fmt::Write;
use std::ops::RangeInclusive;

Expand Down Expand Up @@ -83,7 +82,13 @@ where
}

fn new() -> Self {
Self { iter: F::Int::ZERO..=min(F::Int::ONE << 22, F::MAN_BITS.try_into().unwrap()) }
let upper_lim = if F::MAN_BITS < 22 {
F::Int::ONE << 22
} else {
(F::Int::ONE << F::MAN_BITS) - F::Int::ONE
};

Self { iter: F::Int::ZERO..=upper_lim }
}

fn write_string(s: &mut String, ctx: Self::WriteCtx) {
Expand Down
3 changes: 3 additions & 0 deletions src/etc/test-float-parse/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(f16)]

mod traits;
mod ui;
mod validate;
Expand Down Expand Up @@ -114,6 +116,7 @@ pub fn register_tests(cfg: &Config) -> Vec<TestInfo> {
let mut tests = Vec::new();

// Register normal generators for all floats.
register_float::<f16>(&mut tests, cfg);
register_float::<f32>(&mut tests, cfg);
register_float::<f64>(&mut tests, cfg);

Expand Down
6 changes: 3 additions & 3 deletions src/etc/test-float-parse/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ macro_rules! impl_int {
}
}

impl_int!(u32, i32; u64, i64);
impl_int!(u16, i16; u32, i32; u64, i64);

/// Floating point types.
pub trait Float:
Expand Down Expand Up @@ -147,12 +147,12 @@ pub trait Float:
}

macro_rules! impl_float {
($($fty:ty, $ity:ty, $bits:literal);+) => {
($($fty:ty, $ity:ty);+) => {
$(
impl Float for $fty {
type Int = $ity;
type SInt = <Self::Int as Int>::Signed;
const BITS: u32 = $bits;
const BITS: u32 = <$ity>::BITS;
const MAN_BITS: u32 = Self::MANTISSA_DIGITS - 1;
const MAN_MASK: Self::Int = (Self::Int::ONE << Self::MAN_BITS) - Self::Int::ONE;
const SIGN_MASK: Self::Int = Self::Int::ONE << (Self::BITS-1);
Expand Down

0 comments on commit c1f042b

Please sign in to comment.