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 Aug 25, 2024
1 parent 10af806 commit 2098f01
Show file tree
Hide file tree
Showing 4 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 @@ -3538,7 +3538,7 @@ impl Step for TestFloatParse {
builder.ensure(compile::Std::new(compiler, 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 @@ -3548,6 +3548,7 @@ impl Step for TestFloatParse {
SourceType::InTree,
&[],
);
cargo_test.allow_features("f16");

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

cargo_run.arg("--");
if builder.config.args().is_empty() {
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
8 changes: 4 additions & 4 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 All @@ -168,7 +168,7 @@ macro_rules! impl_float {
}
}

impl_float!(f32, u32, 32; f64, u64, 64);
impl_float!(f16, u16; f32, u32; f64, u64);

/// A test generator. Should provide an iterator that produces unique patterns to parse.
///
Expand Down

0 comments on commit 2098f01

Please sign in to comment.