1
1
#[ cfg_attr( not( feature="master" ) , allow( unused_imports) ) ]
2
2
use gccjit:: { ToRValue , ComparisonOp , UnaryOp } ;
3
3
use gccjit:: { BinaryOp , RValue , Type } ;
4
+
4
5
use rustc_codegen_ssa:: base:: compare_simd_types;
5
6
use rustc_codegen_ssa:: common:: { IntPredicate , TypeKind } ;
6
7
use rustc_codegen_ssa:: mir:: operand:: OperandRef ;
@@ -10,52 +11,58 @@ use rustc_hir as hir;
10
11
use rustc_middle:: span_bug;
11
12
use rustc_middle:: ty:: layout:: HasTyCtxt ;
12
13
use rustc_middle:: ty:: { self , Ty } ;
13
- use rustc_span:: { Span , Symbol , sym } ;
14
+ use rustc_span:: { sym , Span , Symbol } ;
14
15
use rustc_target:: abi:: Align ;
15
16
16
17
use crate :: builder:: Builder ;
17
18
#[ cfg( feature="master" ) ]
18
19
use crate :: context:: CodegenCx ;
19
20
use crate :: errors:: {
20
- InvalidMonomorphizationInvalidFloatVector ,
21
- InvalidMonomorphizationNotFloat ,
22
- InvalidMonomorphizationUnrecognized ,
23
- InvalidMonomorphizationExpectedSignedUnsigned ,
24
- InvalidMonomorphizationUnsupportedElement ,
25
- InvalidMonomorphizationInvalidBitmask ,
26
- InvalidMonomorphizationSimdShuffle ,
27
- InvalidMonomorphizationExpectedSimd ,
28
- InvalidMonomorphizationMaskType ,
29
- InvalidMonomorphizationReturnLength ,
30
- InvalidMonomorphizationReturnLengthInputType ,
31
- InvalidMonomorphizationReturnElement ,
32
- InvalidMonomorphizationReturnType ,
33
- InvalidMonomorphizationInsertedType ,
34
- InvalidMonomorphizationReturnIntegerType ,
35
- InvalidMonomorphizationMismatchedLengths ,
36
- InvalidMonomorphizationUnsupportedOperation
21
+ InvalidMonomorphizationExpectedSignedUnsigned , InvalidMonomorphizationExpectedSimd ,
22
+ InvalidMonomorphizationInsertedType , InvalidMonomorphizationInvalidBitmask ,
23
+ InvalidMonomorphizationInvalidFloatVector , InvalidMonomorphizationMaskType ,
24
+ InvalidMonomorphizationMismatchedLengths , InvalidMonomorphizationNotFloat ,
25
+ InvalidMonomorphizationReturnElement , InvalidMonomorphizationReturnIntegerType ,
26
+ InvalidMonomorphizationReturnLength , InvalidMonomorphizationReturnLengthInputType ,
27
+ InvalidMonomorphizationReturnType , InvalidMonomorphizationSimdShuffle ,
28
+ InvalidMonomorphizationUnrecognized , InvalidMonomorphizationUnsupportedElement ,
29
+ InvalidMonomorphizationUnsupportedOperation ,
37
30
} ;
38
31
39
- pub fn generic_simd_intrinsic < ' a , ' gcc , ' tcx > ( bx : & mut Builder < ' a , ' gcc , ' tcx > , name : Symbol , callee_ty : Ty < ' tcx > , args : & [ OperandRef < ' tcx , RValue < ' gcc > > ] , ret_ty : Ty < ' tcx > , llret_ty : Type < ' gcc > , span : Span ) -> Result < RValue < ' gcc > , ( ) > {
32
+ pub fn generic_simd_intrinsic < ' a , ' gcc , ' tcx > (
33
+ bx : & mut Builder < ' a , ' gcc , ' tcx > ,
34
+ name : Symbol ,
35
+ callee_ty : Ty < ' tcx > ,
36
+ args : & [ OperandRef < ' tcx , RValue < ' gcc > > ] ,
37
+ ret_ty : Ty < ' tcx > ,
38
+ llret_ty : Type < ' gcc > ,
39
+ span : Span ,
40
+ ) -> Result < RValue < ' gcc > , ( ) > {
40
41
// macros for error handling:
41
42
macro_rules! return_error {
42
- ( $err: expr) => {
43
- {
44
- bx. sess( ) . emit_err( $err) ;
45
- return Err ( ( ) ) ;
46
- }
47
- }
43
+ ( $err: expr) => { {
44
+ bx. sess( ) . emit_err( $err) ;
45
+ return Err ( ( ) ) ;
46
+ } } ;
48
47
}
49
48
macro_rules! require {
50
49
( $cond: expr, $err: expr) => {
51
50
if !$cond {
52
51
return_error!( $err) ;
53
52
}
54
- }
53
+ } ;
55
54
}
56
55
macro_rules! require_simd {
57
56
( $ty: expr, $position: expr) => {
58
- require!( $ty. is_simd( ) , InvalidMonomorphizationExpectedSimd { span, name, position: $position, found_ty: $ty } )
57
+ require!(
58
+ $ty. is_simd( ) ,
59
+ InvalidMonomorphizationExpectedSimd {
60
+ span,
61
+ name,
62
+ position: $position,
63
+ found_ty: $ty
64
+ }
65
+ )
59
66
} ;
60
67
}
61
68
@@ -77,7 +84,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
77
84
ty:: Uint ( i) if i. bit_width ( ) == Some ( expected_int_bits) => args[ 0 ] . immediate ( ) ,
78
85
ty:: Array ( elem, len)
79
86
if matches ! ( elem. kind( ) , ty:: Uint ( ty:: UintTy :: U8 ) )
80
- && len. try_eval_usize ( bx. tcx , ty:: ParamEnv :: reveal_all ( ) )
87
+ && len. try_eval_target_usize ( bx. tcx , ty:: ParamEnv :: reveal_all ( ) )
81
88
== Some ( expected_bytes) =>
82
89
{
83
90
let place = PlaceRef :: alloca ( bx, args[ 0 ] . layout ) ;
@@ -86,9 +93,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
86
93
let ptr = bx. pointercast ( place. llval , bx. cx . type_ptr_to ( int_ty) ) ;
87
94
bx. load ( int_ty, ptr, Align :: ONE )
88
95
}
89
- _ => return_error ! (
90
- InvalidMonomorphizationInvalidBitmask { span, name, ty: mask_ty, expected_int_bits, expected_bytes }
91
- ) ,
96
+ _ => return_error ! ( InvalidMonomorphizationInvalidBitmask {
97
+ span,
98
+ name,
99
+ ty: mask_ty,
100
+ expected_int_bits,
101
+ expected_bytes
102
+ } ) ,
92
103
} ;
93
104
94
105
let arg1 = args[ 1 ] . immediate ( ) ;
@@ -134,11 +145,18 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
134
145
let ( out_len, out_ty) = ret_ty. simd_size_and_type ( bx. tcx ( ) ) ;
135
146
require ! (
136
147
in_len == out_len,
137
- InvalidMonomorphizationReturnLengthInputType { span, name, in_len, in_ty, ret_ty, out_len }
148
+ InvalidMonomorphizationReturnLengthInputType {
149
+ span,
150
+ name,
151
+ in_len,
152
+ in_ty,
153
+ ret_ty,
154
+ out_len
155
+ }
138
156
) ;
139
157
require ! (
140
158
bx. type_kind( bx. element_type( llret_ty) ) == TypeKind :: Integer ,
141
- InvalidMonomorphizationReturnIntegerType { span, name, ret_ty, out_ty}
159
+ InvalidMonomorphizationReturnIntegerType { span, name, ret_ty, out_ty }
142
160
) ;
143
161
144
162
return Ok ( compare_simd_types (
@@ -152,26 +170,26 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
152
170
}
153
171
154
172
if let Some ( stripped) = name. as_str ( ) . strip_prefix ( "simd_shuffle" ) {
155
- let n: u64 =
156
- if stripped. is_empty ( ) {
157
- // Make sure this is actually an array, since typeck only checks the length-suffixed
158
- // version of this intrinsic.
159
- match args[ 2 ] . layout . ty . kind ( ) {
160
- ty:: Array ( ty, len) if matches ! ( ty. kind( ) , ty:: Uint ( ty:: UintTy :: U32 ) ) => {
161
- len. try_eval_usize ( bx. cx . tcx , ty:: ParamEnv :: reveal_all ( ) ) . unwrap_or_else ( || {
162
- span_bug ! ( span, "could not evaluate shuffle index array length" )
163
- } )
164
- }
165
- _ => return_error ! (
166
- InvalidMonomorphizationSimdShuffle { span, name, ty: args[ 2 ] . layout. ty }
167
- ) ,
173
+ let n: u64 = if stripped. is_empty ( ) {
174
+ // Make sure this is actually an array, since typeck only checks the length-suffixed
175
+ // version of this intrinsic.
176
+ match args[ 2 ] . layout . ty . kind ( ) {
177
+ ty:: Array ( ty, len) if matches ! ( ty. kind( ) , ty:: Uint ( ty:: UintTy :: U32 ) ) => {
178
+ len. try_eval_target_usize ( bx. cx . tcx , ty:: ParamEnv :: reveal_all ( ) ) . unwrap_or_else (
179
+ || span_bug ! ( span, "could not evaluate shuffle index array length" ) ,
180
+ )
168
181
}
182
+ _ => return_error ! ( InvalidMonomorphizationSimdShuffle {
183
+ span,
184
+ name,
185
+ ty: args[ 2 ] . layout. ty
186
+ } ) ,
169
187
}
170
- else {
171
- stripped. parse ( ) . unwrap_or_else ( |_| {
172
- span_bug ! ( span, "bad `simd_shuffle` instruction only caught in codegen?" )
173
- } )
174
- } ;
188
+ } else {
189
+ stripped. parse ( ) . unwrap_or_else ( |_| {
190
+ span_bug ! ( span, "bad `simd_shuffle` instruction only caught in codegen?" )
191
+ } )
192
+ } ;
175
193
176
194
require_simd ! ( ret_ty, "return" ) ;
177
195
@@ -187,14 +205,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
187
205
188
206
let vector = args[ 2 ] . immediate ( ) ;
189
207
190
- return Ok ( bx. shuffle_vector (
191
- args[ 0 ] . immediate ( ) ,
192
- args[ 1 ] . immediate ( ) ,
193
- vector,
194
- ) ) ;
208
+ return Ok ( bx. shuffle_vector ( args[ 0 ] . immediate ( ) , args[ 1 ] . immediate ( ) , vector) ) ;
195
209
}
196
210
197
- #[ cfg( feature= "master" ) ]
211
+ #[ cfg( feature = "master" ) ]
198
212
if name == sym:: simd_insert {
199
213
require ! (
200
214
in_elem == arg_tys[ 2 ] ,
@@ -211,7 +225,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
211
225
return Ok ( variable. to_rvalue ( ) ) ;
212
226
}
213
227
214
- #[ cfg( feature= "master" ) ]
228
+ #[ cfg( feature = "master" ) ]
215
229
if name == sym:: simd_extract {
216
230
require ! (
217
231
ret_ty == in_elem,
@@ -243,7 +257,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
243
257
let ( out_len, out_elem) = ret_ty. simd_size_and_type ( bx. tcx ( ) ) ;
244
258
require ! (
245
259
in_len == out_len,
246
- InvalidMonomorphizationReturnLengthInputType { span, name, in_len, in_ty, ret_ty, out_len }
260
+ InvalidMonomorphizationReturnLengthInputType {
261
+ span,
262
+ name,
263
+ in_len,
264
+ in_ty,
265
+ ret_ty,
266
+ out_len
267
+ }
247
268
) ;
248
269
// casting cares about nominal type, not just structural type
249
270
if in_elem == out_elem {
@@ -373,12 +394,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
373
394
args : & [ OperandRef < ' tcx , RValue < ' gcc > > ] ,
374
395
) -> Result < RValue < ' gcc > , ( ) > {
375
396
macro_rules! return_error {
376
- ( $err: expr) => {
377
- {
378
- bx. sess( ) . emit_err( $err) ;
379
- return Err ( ( ) ) ;
380
- }
381
- }
397
+ ( $err: expr) => { {
398
+ bx. sess( ) . emit_err( $err) ;
399
+ return Err ( ( ) ) ;
400
+ } } ;
382
401
}
383
402
let ( elem_ty_str, elem_ty) =
384
403
if let ty:: Float ( f) = in_elem. kind ( ) {
@@ -391,9 +410,9 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
391
410
}
392
411
}
393
412
}
394
- else {
395
- return_error ! ( InvalidMonomorphizationNotFloat { span, name, ty: in_ty } ) ;
396
- } ;
413
+ } else {
414
+ return_error ! ( InvalidMonomorphizationNotFloat { span, name, ty: in_ty } ) ;
415
+ } ;
397
416
398
417
let vec_ty = bx. cx . type_vector ( elem_ty, in_len) ;
399
418
@@ -778,7 +797,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
778
797
simd_neg: Int => neg, Float => fneg;
779
798
}
780
799
781
- #[ cfg( feature= "master" ) ]
800
+ #[ cfg( feature = "master" ) ]
782
801
if name == sym:: simd_saturating_add || name == sym:: simd_saturating_sub {
783
802
let lhs = args[ 0 ] . immediate ( ) ;
784
803
let rhs = args[ 1 ] . immediate ( ) ;
@@ -898,8 +917,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
898
917
// if overflow occurs, the result is the
899
918
// mathematical result modulo 2^n:
900
919
Ok ( bx. $op( args[ 1 ] . immediate( ) , r) )
901
- }
902
- else {
920
+ } else {
903
921
Ok ( bx. vector_reduce_op( args[ 0 ] . immediate( ) , $vec_op) )
904
922
}
905
923
}
@@ -908,12 +926,17 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
908
926
// ordered arithmetic reductions take an accumulator
909
927
let acc = args[ 1 ] . immediate( ) ;
910
928
Ok ( bx. $float_reduce( acc, args[ 0 ] . immediate( ) ) )
911
- }
912
- else {
929
+ } else {
913
930
Ok ( bx. vector_reduce_op( args[ 0 ] . immediate( ) , $vec_op) )
914
931
}
915
932
}
916
- _ => return_error!( InvalidMonomorphizationUnsupportedElement { span, name, in_ty, elem_ty: in_elem, ret_ty } ) ,
933
+ _ => return_error!( InvalidMonomorphizationUnsupportedElement {
934
+ span,
935
+ name,
936
+ in_ty,
937
+ elem_ty: in_elem,
938
+ ret_ty
939
+ } ) ,
917
940
} ;
918
941
}
919
942
} ;
@@ -983,7 +1006,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
983
1006
} else {
984
1007
match in_elem. kind( ) {
985
1008
ty:: Int ( _) | ty:: Uint ( _) => { }
986
- _ => return_error!( InvalidMonomorphizationUnsupportedElement { span, name, in_ty, elem_ty: in_elem, ret_ty } ) ,
1009
+ _ => return_error!( InvalidMonomorphizationUnsupportedElement {
1010
+ span,
1011
+ name,
1012
+ in_ty,
1013
+ elem_ty: in_elem,
1014
+ ret_ty
1015
+ } ) ,
987
1016
}
988
1017
989
1018
args[ 0 ] . immediate( )
@@ -993,9 +1022,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
993
1022
let r = bx. vector_reduce_op( input, $op) ;
994
1023
Ok ( if !$boolean { r } else { bx. icmp( IntPredicate :: IntNE , r, bx. context. new_rvalue_zero( r. get_type( ) ) ) } )
995
1024
}
996
- _ => return_error!(
997
- InvalidMonomorphizationUnsupportedElement { span, name, in_ty, elem_ty: in_elem, ret_ty }
998
- ) ,
1025
+ _ => return_error!( InvalidMonomorphizationUnsupportedElement {
1026
+ span,
1027
+ name,
1028
+ in_ty,
1029
+ elem_ty: in_elem,
1030
+ ret_ty
1031
+ } ) ,
999
1032
} ;
1000
1033
}
1001
1034
} ;
0 commit comments