Skip to content

Commit 40b6e2e

Browse files
feat: implement print_result_c for Intrinsic<X86IntrinsicType>
1 parent 5d97c0d commit 40b6e2e

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

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

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::common::argument::ArgumentList;
22
use crate::common::indentation::Indentation;
33
use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition};
4-
use crate::common::intrinsic_helpers::IntrinsicType;
4+
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, TypeKind};
55
use crate::x86::xml_parser::Parameter;
66
use std::ops::{Deref, DerefMut};
77

@@ -41,7 +41,69 @@ impl IntrinsicDefinition<X86IntrinsicType> for Intrinsic<X86IntrinsicType> {
4141
/// Generates a std::cout for the intrinsics results that will match the
4242
/// rust debug output format for the return type. The generated line assumes
4343
/// there is an int i in scope which is the current pass number.
44-
fn print_result_c(&self, _indentation: Indentation, _additional: &str) -> String {
45-
todo!("print_result_c in Intrinsic<X86IntrinsicType> needs to be implemented!");
44+
fn print_result_c(&self, indentation: Indentation, additional: &str) -> String {
45+
let lanes = if self.results().num_vectors() > 1 {
46+
(0..self.results().num_vectors())
47+
.map(|vector| {
48+
format!(
49+
r#""{ty}(" << {lanes} << ")""#,
50+
ty = self.results().c_single_vector_type(),
51+
lanes = (0..self.results().num_lanes())
52+
.map(move |idx| -> std::string::String {
53+
format!(
54+
"{cast}{lane_fn}(__return_value.val[{vector}], {lane})",
55+
cast = self.results().c_promotion(),
56+
lane_fn = self.results().get_lane_function(),
57+
lane = idx,
58+
vector = vector,
59+
)
60+
})
61+
.collect::<Vec<_>>()
62+
.join(r#" << ", " << "#)
63+
)
64+
})
65+
.collect::<Vec<_>>()
66+
.join(r#" << ", " << "#)
67+
} else if self.results().num_lanes() > 1 {
68+
(0..self.results().num_lanes())
69+
.map(|idx| -> std::string::String {
70+
format!(
71+
"{cast}{lane_fn}(__return_value, {lane})",
72+
cast = self.results().c_promotion(),
73+
lane_fn = self.results().get_lane_function(),
74+
lane = idx
75+
)
76+
})
77+
.collect::<Vec<_>>()
78+
.join(r#" << ", " << "#)
79+
} else {
80+
format!(
81+
"{promote}cast<{cast}>(__return_value)",
82+
cast = match self.results.kind() {
83+
TypeKind::Void => "void".to_string(),
84+
TypeKind::Float if self.results().inner_size() == 64 => "double".to_string(),
85+
TypeKind::Float if self.results().inner_size() == 32 => "float".to_string(),
86+
// TypeKind::Float if self.results().inner_size() == 16 => "float16_t".to_string(),
87+
// TypeKind::Int(true) if self.results().inner_size() == 64 => "long".to_string(),
88+
// TypeKind::Int(false) if self.results().inner_size() == 64 => "unsigned long".to_string(),
89+
// TypeKind::Int(true) if self.results().inner_size() == 32 => "int".to_string(),
90+
// TypeKind::Int(false) if self.results().inner_size() == 32 => "unsigned int".to_string(),
91+
// TypeKind::Int(true) if self.results().inner_size() == 16 => "short".to_string(),
92+
// TypeKind::Int(false) if self.results().inner_size() == 16 => "unsigned short".to_string(),
93+
_ => self.results.c_scalar_type(),
94+
},
95+
promote = self.results().c_promotion(),
96+
)
97+
};
98+
99+
format!(
100+
r#"{indentation}std::cout << "Result {additional}-" << i+1 << ": {ty}" << std::fixed << std::setprecision(150) << {lanes} << "{close}" << std::endl;"#,
101+
ty = if self.results().is_simd() {
102+
format!("{}(", self.results().c_type())
103+
} else {
104+
String::from("")
105+
},
106+
close = if self.results.is_simd() { ")" } else { "" },
107+
)
46108
}
47109
}

0 commit comments

Comments
 (0)