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 ;
49
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 ) ;
1012
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+ }
1351
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+ }
1656
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+ }
2064
21- impl Intrinsic {
2265 /// Generates a std::cout for the intrinsics results that will match the
2366 /// rust debug output format for the return type. The generated line assumes
2467 /// 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 ( ) )
2871 . map ( |vector| {
2972 format ! (
3073 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( ) )
3376 . map( move |idx| -> std:: string:: String {
3477 format!(
3578 "{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( ) ,
3881 lane = idx,
3982 vector = vector,
4083 )
@@ -45,13 +88,13 @@ impl Intrinsic {
4588 } )
4689 . collect :: < Vec < _ > > ( )
4790 . 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 ( ) )
5093 . map ( |idx| -> std:: string:: String {
5194 format ! (
5295 "{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( ) ,
5598 lane = idx
5699 )
57100 } )
@@ -61,22 +104,22 @@ impl Intrinsic {
61104 format ! (
62105 "{promote}cast<{cast}>(__return_value)" ,
63106 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( ) ) ,
70113 ty => todo!( "print_result_c - Unknown type: {:#?}" , ty) ,
71114 } ,
72- promote = self . results. c_promotion( ) ,
115+ promote = self . results( ) . c_promotion( ) ,
73116 )
74117 } ;
75118
76119 format ! (
77120 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( ) )
80123 } else {
81124 String :: from( "" )
82125 } ,
0 commit comments