fix: moved f16 formatting code to common module

This commit is contained in:
Madhav Madhusoodanan 2025-05-25 21:17:31 +05:30 committed by Amanieu d'Antras
parent 57006ad521
commit 54e277cdd5
2 changed files with 16 additions and 10 deletions

View file

@ -127,16 +127,7 @@ impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> {
constraints
};
// the `intrinsic-test` crate compares the output of C and Rust intrinsics. Currently, It uses
// a string representation of the output value to compare. In C, f16 values are currently printed
// as hexadecimal integers. Since https://github.com/rust-lang/rust/pull/127013, rust does print
// them as decimal floating point values. To keep the intrinsics tests working, for now, format
// vectors containing f16 values like C prints them.
let return_value = match self.results.kind() {
TypeKind::Float if self.results.inner_size() == 16 => "debug_f16(__return_value)",
_ => "format_args!(\"{__return_value:.150?}\")",
};
let return_value = self.format_f16_return_value();
let indentation2 = indentation.nested();
let indentation3 = indentation2.nested();

View file

@ -6,6 +6,7 @@ use itertools::Itertools;
use super::argument::Argument;
use super::gen_c::generate_c_program;
use super::gen_rust::generate_rust_program;
use super::intrinsic_helpers::TypeKind;
// The number of times each intrinsic will be called.
const PASSES: u32 = 20;
@ -41,6 +42,20 @@ where
/// there is an int i in scope which is the current pass number.
fn print_result_c(&self, _indentation: Indentation, _additional: &str) -> String;
fn format_f16_return_value(&self) -> String {
// the `intrinsic-test` crate compares the output of C and Rust intrinsics. Currently, It uses
// a string representation of the output value to compare. In C, f16 values are currently printed
// as hexadecimal integers. Since https://github.com/rust-lang/rust/pull/127013, rust does print
// them as decimal floating point values. To keep the intrinsics tests working, for now, format
// vectors containing f16 values like C prints them.
let return_value = match self.results().kind() {
TypeKind::Float if self.results().inner_size() == 16 => "debug_f16(__return_value)",
_ => "format_args!(\"{__return_value:.150?}\")",
};
String::from(return_value)
}
fn generate_loop_c(
&self,
indentation: Indentation,