Skip to content

Commit 9d9ca01

Browse files
committed
move print_result_c into the inner intrinsic type
1 parent 916424f commit 9d9ca01

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

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

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,27 @@ impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> {
4141
/// rust debug output format for the return type. The generated line assumes
4242
/// there is an int i in scope which is the current pass number.
4343
fn print_result_c(&self, indentation: Indentation, additional: &str) -> String {
44-
let lanes = if self.results().num_vectors() > 1 {
45-
(0..self.results().num_vectors())
44+
self.results().print_result_c(indentation, additional)
45+
}
46+
}
47+
48+
impl ArmIntrinsicType {
49+
/// Generates a std::cout for the intrinsics results that will match the
50+
/// rust debug output format for the return type. The generated line assumes
51+
/// there is an int i in scope which is the current pass number.
52+
fn print_result_c(&self, indentation: Indentation, additional: &str) -> String {
53+
let lanes = if self.num_vectors() > 1 {
54+
(0..self.num_vectors())
4655
.map(|vector| {
4756
format!(
4857
r#""{ty}(" << {lanes} << ")""#,
49-
ty = self.results().c_single_vector_type(),
50-
lanes = (0..self.results().num_lanes())
58+
ty = self.c_single_vector_type(),
59+
lanes = (0..self.num_lanes())
5160
.map(move |idx| -> std::string::String {
5261
format!(
5362
"{cast}{lane_fn}(__return_value.val[{vector}], {lane})",
54-
cast = self.results().c_promotion(),
55-
lane_fn = self.results().get_lane_function(),
63+
cast = self.c_promotion(),
64+
lane_fn = self.get_lane_function(),
5665
lane = idx,
5766
vector = vector,
5867
)
@@ -63,13 +72,13 @@ impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> {
6372
})
6473
.collect::<Vec<_>>()
6574
.join(r#" << ", " << "#)
66-
} else if self.results().num_lanes() > 1 {
67-
(0..self.results().num_lanes())
75+
} else if self.num_lanes() > 1 {
76+
(0..self.num_lanes())
6877
.map(|idx| -> std::string::String {
6978
format!(
7079
"{cast}{lane_fn}(__return_value, {lane})",
71-
cast = self.results().c_promotion(),
72-
lane_fn = self.results().get_lane_function(),
80+
cast = self.c_promotion(),
81+
lane_fn = self.get_lane_function(),
7382
lane = idx
7483
)
7584
})
@@ -78,28 +87,27 @@ impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> {
7887
} else {
7988
format!(
8089
"{promote}cast<{cast}>(__return_value)",
81-
cast = match self.results.kind() {
82-
TypeKind::Float if self.results().inner_size() == 16 => "float16_t".to_string(),
83-
TypeKind::Float if self.results().inner_size() == 32 => "float".to_string(),
84-
TypeKind::Float if self.results().inner_size() == 64 => "double".to_string(),
85-
TypeKind::Int(Sign::Signed) => format!("int{}_t", self.results().inner_size()),
86-
TypeKind::Int(Sign::Unsigned) =>
87-
format!("uint{}_t", self.results().inner_size()),
88-
TypeKind::Poly => format!("poly{}_t", self.results().inner_size()),
90+
cast = match self.kind() {
91+
TypeKind::Float if self.inner_size() == 16 => "float16_t".to_string(),
92+
TypeKind::Float if self.inner_size() == 32 => "float".to_string(),
93+
TypeKind::Float if self.inner_size() == 64 => "double".to_string(),
94+
TypeKind::Int(Sign::Signed) => format!("int{}_t", self.inner_size()),
95+
TypeKind::Int(Sign::Unsigned) => format!("uint{}_t", self.inner_size()),
96+
TypeKind::Poly => format!("poly{}_t", self.inner_size()),
8997
ty => todo!("print_result_c - Unknown type: {:#?}", ty),
9098
},
91-
promote = self.results().c_promotion(),
99+
promote = self.c_promotion(),
92100
)
93101
};
94102

95103
format!(
96104
r#"{indentation}std::cout << "Result {additional}-" << i+1 << ": {ty}" << std::fixed << std::setprecision(150) << {lanes} << "{close}" << std::endl;"#,
97-
ty = if self.results().is_simd() {
98-
format!("{}(", self.results().c_type())
105+
ty = if self.is_simd() {
106+
format!("{}(", self.c_type())
99107
} else {
100108
String::from("")
101109
},
102-
close = if self.results.is_simd() { ")" } else { "" },
110+
close = if self.is_simd() { ")" } else { "" },
103111
)
104112
}
105113
}

0 commit comments

Comments
 (0)