Skip to content

Commit 2ba0a6e

Browse files
committed
move print_result_c into the trait
1 parent 9d9ca01 commit 2ba0a6e

File tree

5 files changed

+75
-83
lines changed

5 files changed

+75
-83
lines changed
Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::common::argument::ArgumentList;
2-
use crate::common::indentation::Indentation;
32
use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition};
4-
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
3+
use crate::common::intrinsic_helpers::IntrinsicType;
54
use std::ops::{Deref, DerefMut};
65

76
#[derive(Debug, Clone, PartialEq)]
@@ -36,78 +35,4 @@ impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> {
3635
fn name(&self) -> String {
3736
self.name.clone()
3837
}
39-
40-
/// Generates a std::cout for the intrinsics results that will match the
41-
/// rust debug output format for the return type. The generated line assumes
42-
/// there is an int i in scope which is the current pass number.
43-
fn print_result_c(&self, indentation: Indentation, additional: &str) -> String {
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())
55-
.map(|vector| {
56-
format!(
57-
r#""{ty}(" << {lanes} << ")""#,
58-
ty = self.c_single_vector_type(),
59-
lanes = (0..self.num_lanes())
60-
.map(move |idx| -> std::string::String {
61-
format!(
62-
"{cast}{lane_fn}(__return_value.val[{vector}], {lane})",
63-
cast = self.c_promotion(),
64-
lane_fn = self.get_lane_function(),
65-
lane = idx,
66-
vector = vector,
67-
)
68-
})
69-
.collect::<Vec<_>>()
70-
.join(r#" << ", " << "#)
71-
)
72-
})
73-
.collect::<Vec<_>>()
74-
.join(r#" << ", " << "#)
75-
} else if self.num_lanes() > 1 {
76-
(0..self.num_lanes())
77-
.map(|idx| -> std::string::String {
78-
format!(
79-
"{cast}{lane_fn}(__return_value, {lane})",
80-
cast = self.c_promotion(),
81-
lane_fn = self.get_lane_function(),
82-
lane = idx
83-
)
84-
})
85-
.collect::<Vec<_>>()
86-
.join(r#" << ", " << "#)
87-
} else {
88-
format!(
89-
"{promote}cast<{cast}>(__return_value)",
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()),
97-
ty => todo!("print_result_c - Unknown type: {:#?}", ty),
98-
},
99-
promote = self.c_promotion(),
100-
)
101-
};
102-
103-
format!(
104-
r#"{indentation}std::cout << "Result {additional}-" << i+1 << ": {ty}" << std::fixed << std::setprecision(150) << {lanes} << "{close}" << std::endl;"#,
105-
ty = if self.is_simd() {
106-
format!("{}(", self.c_type())
107-
} else {
108-
String::from("")
109-
},
110-
close = if self.is_simd() { ")" } else { "" },
111-
)
112-
}
11338
}

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::intrinsic::ArmIntrinsicType;
22
use crate::common::cli::Language;
3+
use crate::common::indentation::Indentation;
34
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
45

56
impl IntrinsicTypeDefinition for ArmIntrinsicType {
@@ -98,6 +99,71 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
9899
todo!("get_lane_function IntrinsicType: {:#?}", self)
99100
}
100101
}
102+
103+
/// Generates a std::cout for the intrinsics results that will match the
104+
/// rust debug output format for the return type. The generated line assumes
105+
/// there is an int i in scope which is the current pass number.
106+
fn print_result_c(&self, indentation: Indentation, additional: &str) -> String {
107+
let lanes = if self.num_vectors() > 1 {
108+
(0..self.num_vectors())
109+
.map(|vector| {
110+
format!(
111+
r#""{ty}(" << {lanes} << ")""#,
112+
ty = self.c_single_vector_type(),
113+
lanes = (0..self.num_lanes())
114+
.map(move |idx| -> std::string::String {
115+
format!(
116+
"{cast}{lane_fn}(__return_value.val[{vector}], {lane})",
117+
cast = self.c_promotion(),
118+
lane_fn = self.get_lane_function(),
119+
lane = idx,
120+
vector = vector,
121+
)
122+
})
123+
.collect::<Vec<_>>()
124+
.join(r#" << ", " << "#)
125+
)
126+
})
127+
.collect::<Vec<_>>()
128+
.join(r#" << ", " << "#)
129+
} else if self.num_lanes() > 1 {
130+
(0..self.num_lanes())
131+
.map(|idx| -> std::string::String {
132+
format!(
133+
"{cast}{lane_fn}(__return_value, {lane})",
134+
cast = self.c_promotion(),
135+
lane_fn = self.get_lane_function(),
136+
lane = idx
137+
)
138+
})
139+
.collect::<Vec<_>>()
140+
.join(r#" << ", " << "#)
141+
} else {
142+
format!(
143+
"{promote}cast<{cast}>(__return_value)",
144+
cast = match self.kind() {
145+
TypeKind::Float if self.inner_size() == 16 => "float16_t".to_string(),
146+
TypeKind::Float if self.inner_size() == 32 => "float".to_string(),
147+
TypeKind::Float if self.inner_size() == 64 => "double".to_string(),
148+
TypeKind::Int(Sign::Signed) => format!("int{}_t", self.inner_size()),
149+
TypeKind::Int(Sign::Unsigned) => format!("uint{}_t", self.inner_size()),
150+
TypeKind::Poly => format!("poly{}_t", self.inner_size()),
151+
ty => todo!("print_result_c - Unknown type: {:#?}", ty),
152+
},
153+
promote = self.c_promotion(),
154+
)
155+
};
156+
157+
format!(
158+
r#"{indentation}std::cout << "Result {additional}-" << i+1 << ": {ty}" << std::fixed << std::setprecision(150) << {lanes} << "{close}" << std::endl;"#,
159+
ty = if self.is_simd() {
160+
format!("{}(", self.c_type())
161+
} else {
162+
String::from("")
163+
},
164+
close = if self.is_simd() { ")" } else { "" },
165+
)
166+
}
101167
}
102168

103169
impl ArmIntrinsicType {

library/stdarch/crates/intrinsic-test/src/common/gen_c.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ pub fn generate_c_test_loop<T: IntrinsicTypeDefinition + Sized>(
2424
loaded_args = intrinsic.arguments().load_values_c(body_indentation),
2525
intrinsic_call = intrinsic.name(),
2626
args = intrinsic.arguments().as_call_param_c(),
27-
print_result = intrinsic.print_result_c(body_indentation, additional)
27+
print_result = intrinsic
28+
.results()
29+
.print_result_c(body_indentation, additional)
2830
)
2931
}
3032

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::argument::ArgumentList;
2-
use super::indentation::Indentation;
32
use super::intrinsic_helpers::{IntrinsicTypeDefinition, TypeKind};
43

54
/// An intrinsic
@@ -27,11 +26,6 @@ where
2726
fn results(&self) -> T;
2827

2928
fn name(&self) -> String;
30-
31-
/// Generates a std::cout for the intrinsics results that will match the
32-
/// rust debug output format for the return type. The generated line assumes
33-
/// there is an int i in scope which is the current pass number.
34-
fn print_result_c(&self, _indentation: Indentation, _additional: &str) -> String;
3529
}
3630

3731
pub fn format_f16_return_value<T: IntrinsicTypeDefinition>(

library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,9 @@ pub trait IntrinsicTypeDefinition: Deref<Target = IntrinsicType> {
325325

326326
/// can be directly defined in `impl` blocks
327327
fn c_single_vector_type(&self) -> String;
328+
329+
/// Generates a std::cout for the intrinsics results that will match the
330+
/// rust debug output format for the return type. The generated line assumes
331+
/// there is an int i in scope which is the current pass number.
332+
fn print_result_c(&self, indentation: Indentation, additional: &str) -> String;
328333
}

0 commit comments

Comments
 (0)