Skip to content

Commit 9eb5e44

Browse files
madhav-madhusoodananAmanieu
authored andcommitted
fix: moved f16 formatting code to common module
1 parent ad654af commit 9eb5e44

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

crates/intrinsic-test/src/arm/intrinsic.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,7 @@ impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> {
127127
constraints
128128
};
129129

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

crates/intrinsic-test/src/common/intrinsic.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use itertools::Itertools;
66
use super::argument::Argument;
77
use super::gen_c::generate_c_program;
88
use super::gen_rust::generate_rust_program;
9+
use super::intrinsic_helpers::TypeKind;
910

1011
// The number of times each intrinsic will be called.
1112
const PASSES: u32 = 20;
@@ -41,6 +42,20 @@ where
4142
/// there is an int i in scope which is the current pass number.
4243
fn print_result_c(&self, _indentation: Indentation, _additional: &str) -> String;
4344

45+
fn format_f16_return_value(&self) -> String {
46+
// the `intrinsic-test` crate compares the output of C and Rust intrinsics. Currently, It uses
47+
// a string representation of the output value to compare. In C, f16 values are currently printed
48+
// as hexadecimal integers. Since https://github.com/rust-lang/rust/pull/127013, rust does print
49+
// them as decimal floating point values. To keep the intrinsics tests working, for now, format
50+
// vectors containing f16 values like C prints them.
51+
let return_value = match self.results().kind() {
52+
TypeKind::Float if self.results().inner_size() == 16 => "debug_f16(__return_value)",
53+
_ => "format_args!(\"{__return_value:.150?}\")",
54+
};
55+
56+
String::from(return_value)
57+
}
58+
4459
fn generate_loop_c(
4560
&self,
4661
indentation: Indentation,

0 commit comments

Comments
 (0)