1
- use super :: argument:: ArgumentList ;
2
- use super :: format:: Indentation ;
3
- use super :: types:: { IntrinsicType , TypeKind } ;
1
+ use super :: constraint:: Constraint ;
2
+ use crate :: common:: argument:: ArgumentList ;
3
+ use crate :: common:: format:: Indentation ;
4
+ use crate :: common:: intrinsic:: { Intrinsic , IntrinsicDefinition } ;
5
+ use crate :: common:: intrinsic_types:: {
6
+ BaseIntrinsicTypeDefinition , IntrinsicType , IntrinsicTypeDefinition , TypeKind
7
+ } ;
8
+ use crate :: common:: types:: Language ;
4
9
5
- /// An intrinsic
6
- #[ derive( Debug , PartialEq , Clone ) ]
7
- pub struct Intrinsic {
8
- /// The function name of this intrinsic.
9
- pub name : String ,
10
+ #[ derive( Debug , Clone , PartialEq ) ]
11
+ pub struct ArmIntrinsicType ( pub IntrinsicType ) ;
10
12
11
- /// Any arguments for this intrinsic.
12
- pub arguments : ArgumentList ,
13
+ impl BaseIntrinsicTypeDefinition for ArmIntrinsicType {
14
+ fn kind ( & self ) -> TypeKind {
15
+ self . 0 . kind ( )
16
+ }
17
+ fn inner_size ( & self ) -> u32 {
18
+ self . 0 . inner_size ( )
19
+ }
20
+ fn num_lanes ( & self ) -> u32 {
21
+ self . 0 . num_lanes ( )
22
+ }
23
+ fn num_vectors ( & self ) -> u32 {
24
+ self . 0 . num_vectors ( )
25
+ }
26
+ fn is_simd ( & self ) -> bool {
27
+ self . 0 . is_simd ( )
28
+ }
29
+ fn is_ptr ( & self ) -> bool {
30
+ self . 0 . is_ptr ( )
31
+ }
32
+ fn c_scalar_type ( & self ) -> String {
33
+ self . 0 . c_scalar_type ( )
34
+ }
35
+ fn rust_scalar_type ( & self ) -> String {
36
+ self . 0 . rust_scalar_type ( )
37
+ }
38
+ fn c_promotion ( & self ) -> & str {
39
+ self . 0 . c_promotion ( )
40
+ }
41
+ fn populate_random ( & self , indentation : Indentation , loads : u32 , language : & Language ) -> String {
42
+ self . 0 . populate_random ( indentation, loads, language)
43
+ }
44
+ fn is_rust_vals_array_const ( & self ) -> bool {
45
+ self . 0 . is_rust_vals_array_const ( )
46
+ }
47
+ fn as_call_param_c ( & self , name : & String ) -> String {
48
+ self . 0 . as_call_param_c ( name)
49
+ }
50
+ }
13
51
14
- /// The return type of this intrinsic.
15
- pub results : IntrinsicType ,
52
+ impl IntrinsicDefinition < ArmIntrinsicType , Constraint > for Intrinsic < ArmIntrinsicType , Constraint > {
53
+ fn arguments ( & self ) -> ArgumentList < ArmIntrinsicType , Constraint > {
54
+ self . arguments . clone ( )
55
+ }
16
56
17
- /// Whether this intrinsic is only available on A64.
18
- pub a64_only : bool ,
19
- }
57
+ fn results ( & self ) -> ArmIntrinsicType {
58
+ self . results . clone ( )
59
+ }
60
+
61
+ fn name ( & self ) -> String {
62
+ self . name . clone ( )
63
+ }
20
64
21
- impl Intrinsic {
22
65
/// Generates a std::cout for the intrinsics results that will match the
23
66
/// rust debug output format for the return type. The generated line assumes
24
67
/// there is an int i in scope which is the current pass number.
25
- pub fn print_result_c ( & self , indentation : Indentation , additional : & str ) -> String {
26
- let lanes = if self . results . num_vectors ( ) > 1 {
27
- ( 0 ..self . results . num_vectors ( ) )
68
+ fn print_result_c ( & self , indentation : Indentation , additional : & str ) -> String {
69
+ let lanes = if self . results ( ) . num_vectors ( ) > 1 {
70
+ ( 0 ..self . results ( ) . num_vectors ( ) )
28
71
. map ( |vector| {
29
72
format ! (
30
73
r#""{ty}(" << {lanes} << ")""# ,
31
- ty = self . results. c_single_vector_type( ) ,
32
- lanes = ( 0 ..self . results. num_lanes( ) )
74
+ ty = self . results( ) . c_single_vector_type( ) ,
75
+ lanes = ( 0 ..self . results( ) . num_lanes( ) )
33
76
. map( move |idx| -> std:: string:: String {
34
77
format!(
35
78
"{cast}{lane_fn}(__return_value.val[{vector}], {lane})" ,
36
- cast = self . results. c_promotion( ) ,
37
- lane_fn = self . results. get_lane_function( ) ,
79
+ cast = self . results( ) . c_promotion( ) ,
80
+ lane_fn = self . results( ) . get_lane_function( ) ,
38
81
lane = idx,
39
82
vector = vector,
40
83
)
@@ -45,13 +88,13 @@ impl Intrinsic {
45
88
} )
46
89
. collect :: < Vec < _ > > ( )
47
90
. join ( r#" << ", " << "# )
48
- } else if self . results . num_lanes ( ) > 1 {
49
- ( 0 ..self . results . num_lanes ( ) )
91
+ } else if self . results ( ) . num_lanes ( ) > 1 {
92
+ ( 0 ..self . results ( ) . num_lanes ( ) )
50
93
. map ( |idx| -> std:: string:: String {
51
94
format ! (
52
95
"{cast}{lane_fn}(__return_value, {lane})" ,
53
- cast = self . results. c_promotion( ) ,
54
- lane_fn = self . results. get_lane_function( ) ,
96
+ cast = self . results( ) . c_promotion( ) ,
97
+ lane_fn = self . results( ) . get_lane_function( ) ,
55
98
lane = idx
56
99
)
57
100
} )
@@ -61,77 +104,26 @@ impl Intrinsic {
61
104
format ! (
62
105
"{promote}cast<{cast}>(__return_value)" ,
63
106
cast = match self . results. kind( ) {
64
- TypeKind :: Float if self . results. inner_size( ) == 16 => "float16_t" . to_string( ) ,
65
- TypeKind :: Float if self . results. inner_size( ) == 32 => "float" . to_string( ) ,
66
- TypeKind :: Float if self . results. inner_size( ) == 64 => "double" . to_string( ) ,
67
- TypeKind :: Int => format!( "int{}_t" , self . results. inner_size( ) ) ,
68
- TypeKind :: UInt => format!( "uint{}_t" , self . results. inner_size( ) ) ,
69
- TypeKind :: Poly => format!( "poly{}_t" , self . results. inner_size( ) ) ,
107
+ TypeKind :: Float if self . results( ) . inner_size( ) == 16 => "float16_t" . to_string( ) ,
108
+ TypeKind :: Float if self . results( ) . inner_size( ) == 32 => "float" . to_string( ) ,
109
+ TypeKind :: Float if self . results( ) . inner_size( ) == 64 => "double" . to_string( ) ,
110
+ TypeKind :: Int => format!( "int{}_t" , self . results( ) . inner_size( ) ) ,
111
+ TypeKind :: UInt => format!( "uint{}_t" , self . results( ) . inner_size( ) ) ,
112
+ TypeKind :: Poly => format!( "poly{}_t" , self . results( ) . inner_size( ) ) ,
70
113
ty => todo!( "print_result_c - Unknown type: {:#?}" , ty) ,
71
114
} ,
72
- promote = self . results. c_promotion( ) ,
115
+ promote = self . results( ) . c_promotion( ) ,
73
116
)
74
117
} ;
75
118
76
119
format ! (
77
120
r#"{indentation}std::cout << "Result {additional}-" << i+1 << ": {ty}" << std::fixed << std::setprecision(150) << {lanes} << "{close}" << std::endl;"# ,
78
- ty = if self . results. is_simd( ) {
79
- format!( "{}(" , self . results. c_type( ) )
121
+ ty = if self . results( ) . is_simd( ) {
122
+ format!( "{}(" , self . results( ) . c_type( ) )
80
123
} else {
81
124
String :: from( "" )
82
125
} ,
83
- close = if self . results. is_simd( ) { ")" } else { "" } ,
84
- )
85
- }
86
-
87
- pub fn generate_loop_c (
88
- & self ,
89
- indentation : Indentation ,
90
- additional : & str ,
91
- passes : u32 ,
92
- _target : & str ,
93
- ) -> String {
94
- let body_indentation = indentation. nested ( ) ;
95
- format ! (
96
- "{indentation}for (int i=0; i<{passes}; i++) {{\n \
97
- {loaded_args}\
98
- {body_indentation}auto __return_value = {intrinsic_call}({args});\n \
99
- {print_result}\n \
100
- {indentation}}}",
101
- loaded_args = self . arguments. load_values_c( body_indentation) ,
102
- intrinsic_call = self . name,
103
- args = self . arguments. as_call_param_c( ) ,
104
- print_result = self . print_result_c( body_indentation, additional)
105
- )
106
- }
107
-
108
- pub fn generate_loop_rust (
109
- & self ,
110
- indentation : Indentation ,
111
- additional : & str ,
112
- passes : u32 ,
113
- ) -> String {
114
- let constraints = self . arguments . as_constraint_parameters_rust ( ) ;
115
- let constraints = if !constraints. is_empty ( ) {
116
- format ! ( "::<{constraints}>" )
117
- } else {
118
- constraints
119
- } ;
120
-
121
- let indentation2 = indentation. nested ( ) ;
122
- let indentation3 = indentation2. nested ( ) ;
123
- format ! (
124
- "{indentation}for i in 0..{passes} {{\n \
125
- {indentation2}unsafe {{\n \
126
- {loaded_args}\
127
- {indentation3}let __return_value = {intrinsic_call}{const}({args});\n \
128
- {indentation3}println!(\" Result {additional}-{{}}: {{:.150?}}\" , i + 1, __return_value);\n \
129
- {indentation2}}}\n \
130
- {indentation}}}",
131
- loaded_args = self . arguments. load_values_rust( indentation3) ,
132
- intrinsic_call = self . name,
133
- const = constraints,
134
- args = self . arguments. as_call_param_rust( ) ,
126
+ close = if self . results( ) . is_simd( ) { ")" } else { "" } ,
135
127
)
136
128
}
137
129
}
0 commit comments