@@ -4,6 +4,7 @@ use gccjit::{BinaryOp, RValue, Type};
4
4
5
5
use rustc_codegen_ssa:: base:: compare_simd_types;
6
6
use rustc_codegen_ssa:: common:: { IntPredicate , TypeKind } ;
7
+ use rustc_codegen_ssa:: errors:: { ExpectedPointerMutability , InvalidMonomorphization } ;
7
8
use rustc_codegen_ssa:: mir:: operand:: OperandRef ;
8
9
use rustc_codegen_ssa:: mir:: place:: PlaceRef ;
9
10
use rustc_codegen_ssa:: traits:: { BaseTypeMethods , BuilderMethods } ;
@@ -295,11 +296,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
295
296
( Style :: Unsupported , Style :: Unsupported ) => {
296
297
require ! (
297
298
false ,
298
- "unsupported cast from `{}` with element `{}` to `{}` with element `{}`" ,
299
- in_ty,
300
- in_elem,
301
- ret_ty,
302
- out_elem
299
+ InvalidMonomorphization :: UnsupportedCast {
300
+ span,
301
+ name,
302
+ in_ty,
303
+ in_elem,
304
+ ret_ty,
305
+ out_elem
306
+ }
303
307
) ;
304
308
} ,
305
309
_ => return Ok ( bx. context . convert_vector ( None , args[ 0 ] . immediate ( ) , llret_ty) ) ,
@@ -362,7 +366,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
362
366
}
363
367
ty:: Array ( elem, len)
364
368
if matches ! ( elem. kind( ) , ty:: Uint ( ty:: UintTy :: U8 ) )
365
- && len. try_eval_usize ( bx. tcx , ty:: ParamEnv :: reveal_all ( ) )
369
+ && len. try_eval_target_usize ( bx. tcx , ty:: ParamEnv :: reveal_all ( ) )
366
370
== Some ( expected_bytes) =>
367
371
{
368
372
// Zero-extend iN to the array length:
@@ -375,12 +379,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
375
379
let ptr = bx. pointercast ( ptr, bx. cx . type_ptr_to ( array_ty) ) ;
376
380
return Ok ( bx. load ( array_ty, ptr, Align :: ONE ) ) ;
377
381
}
378
- _ => return_error ! (
379
- "cannot return `{}`, expected `u{}` or `[u8; {}]`" ,
382
+ _ => return_error ! ( InvalidMonomorphization :: CannotReturn {
383
+ span,
384
+ name,
380
385
ret_ty,
381
386
expected_int_bits,
382
387
expected_bytes
383
- ) ,
388
+ } ) ,
384
389
}
385
390
}
386
391
@@ -410,9 +415,9 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
410
415
}
411
416
}
412
417
}
413
- } else {
414
- return_error ! ( InvalidMonomorphizationNotFloat { span, name, ty: in_ty } ) ;
415
- } ;
418
+ else {
419
+ return_error ! ( InvalidMonomorphizationNotFloat { span, name, ty: in_ty } ) ;
420
+ } ;
416
421
417
422
let vec_ty = bx. cx . type_vector ( elem_ty, in_len) ;
418
423
@@ -560,27 +565,32 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
560
565
let ( out_len2, _) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
561
566
require ! (
562
567
in_len == out_len,
563
- "expected {} argument with length {} (same as input type `{}`), \
564
- found `{}` with length {}",
565
- "second" ,
566
- in_len,
567
- in_ty,
568
- arg_tys[ 1 ] ,
569
- out_len
568
+ InvalidMonomorphization :: SecondArgumentLength {
569
+ span,
570
+ name,
571
+ in_len,
572
+ in_ty,
573
+ arg_ty: arg_tys[ 1 ] ,
574
+ out_len
575
+ }
570
576
) ;
571
577
require ! (
572
578
in_len == out_len2,
573
- "expected {} argument with length {} (same as input type `{}`), \
574
- found `{}` with length {}",
575
- "third" ,
576
- in_len,
577
- in_ty,
578
- arg_tys[ 2 ] ,
579
- out_len2
579
+ InvalidMonomorphization :: ThirdArgumentLength {
580
+ span,
581
+ name,
582
+ in_len,
583
+ in_ty,
584
+ arg_ty: arg_tys[ 2 ] ,
585
+ out_len: out_len2
586
+ }
580
587
) ;
581
588
582
589
// The return type must match the first argument type
583
- require ! ( ret_ty == in_ty, "expected return type `{}`, found `{}`" , in_ty, ret_ty) ;
590
+ require ! (
591
+ ret_ty == in_ty,
592
+ InvalidMonomorphization :: ExpectedReturnType { span, name, in_ty, ret_ty }
593
+ ) ;
584
594
585
595
// This counts how many pointers
586
596
fn ptr_count ( t : Ty < ' _ > ) -> usize {
@@ -607,15 +617,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
607
617
_ => {
608
618
require ! (
609
619
false ,
610
- "expected element type `{}` of second argument `{}` \
611
- to be a pointer to the element type `{}` of the first \
612
- argument `{}`, found `{}` != `*_ {}`" ,
613
- element_ty1,
614
- arg_tys[ 1 ] ,
620
+ InvalidMonomorphization :: ExpectedElementType {
621
+ span ,
622
+ name ,
623
+ expected_element : element_ty1,
624
+ second_arg : arg_tys[ 1 ] ,
615
625
in_elem,
616
626
in_ty,
617
- element_ty1 ,
618
- in_elem
627
+ mutability : ExpectedPointerMutability :: Not ,
628
+ }
619
629
) ;
620
630
unreachable ! ( ) ;
621
631
}
@@ -631,10 +641,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
631
641
_ => {
632
642
require ! (
633
643
false ,
634
- "expected element type `{}` of third argument `{}` \
635
- to be a signed integer type",
636
- element_ty2,
637
- arg_tys[ 2 ]
644
+ InvalidMonomorphization :: ThirdArgElementType {
645
+ span,
646
+ name,
647
+ expected_element: element_ty2,
648
+ third_arg: arg_tys[ 2 ]
649
+ }
638
650
) ;
639
651
}
640
652
}
@@ -660,23 +672,25 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
660
672
let ( element_len2, _) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
661
673
require ! (
662
674
in_len == element_len1,
663
- "expected {} argument with length {} (same as input type `{}`), \
664
- found `{}` with length {}",
665
- "second" ,
666
- in_len,
667
- in_ty,
668
- arg_tys[ 1 ] ,
669
- element_len1
675
+ InvalidMonomorphization :: SecondArgumentLength {
676
+ span,
677
+ name,
678
+ in_len,
679
+ in_ty,
680
+ arg_ty: arg_tys[ 1 ] ,
681
+ out_len: element_len1
682
+ }
670
683
) ;
671
684
require ! (
672
685
in_len == element_len2,
673
- "expected {} argument with length {} (same as input type `{}`), \
674
- found `{}` with length {}",
675
- "third" ,
676
- in_len,
677
- in_ty,
678
- arg_tys[ 2 ] ,
679
- element_len2
686
+ InvalidMonomorphization :: ThirdArgumentLength {
687
+ span,
688
+ name,
689
+ in_len,
690
+ in_ty,
691
+ arg_ty: arg_tys[ 2 ] ,
692
+ out_len: element_len2
693
+ }
680
694
) ;
681
695
682
696
// This counts how many pointers
@@ -707,15 +721,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
707
721
_ => {
708
722
require ! (
709
723
false ,
710
- "expected element type `{}` of second argument `{}` \
711
- to be a pointer to the element type `{}` of the first \
712
- argument `{}`, found `{}` != `*mut {}`" ,
713
- element_ty1,
714
- arg_tys[ 1 ] ,
724
+ InvalidMonomorphization :: ExpectedElementType {
725
+ span ,
726
+ name ,
727
+ expected_element : element_ty1,
728
+ second_arg : arg_tys[ 1 ] ,
715
729
in_elem,
716
730
in_ty,
717
- element_ty1 ,
718
- in_elem
731
+ mutability : ExpectedPointerMutability :: Mut ,
732
+ }
719
733
) ;
720
734
unreachable ! ( ) ;
721
735
}
@@ -730,10 +744,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
730
744
_ => {
731
745
require ! (
732
746
false ,
733
- "expected element type `{}` of third argument `{}` \
734
- be a signed integer type",
735
- element_ty2,
736
- arg_tys[ 2 ]
747
+ InvalidMonomorphization :: ThirdArgElementType {
748
+ span,
749
+ name,
750
+ expected_element: element_ty2,
751
+ third_arg: arg_tys[ 2 ]
752
+ }
737
753
) ;
738
754
}
739
755
}
@@ -816,18 +832,6 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
816
832
} ) ;
817
833
}
818
834
} ;
819
- let builtin_name =
820
- match ( signed, is_add, in_len, elem_width) {
821
- ( true , true , 32 , 8 ) => "__builtin_ia32_paddsb256" , // TODO(antoyo): cast arguments to unsigned.
822
- ( false , true , 32 , 8 ) => "__builtin_ia32_paddusb256" ,
823
- ( true , true , 16 , 16 ) => "__builtin_ia32_paddsw256" ,
824
- ( false , true , 16 , 16 ) => "__builtin_ia32_paddusw256" ,
825
- ( true , false , 16 , 16 ) => "__builtin_ia32_psubsw256" ,
826
- ( false , false , 16 , 16 ) => "__builtin_ia32_psubusw256" ,
827
- ( true , false , 32 , 8 ) => "__builtin_ia32_psubsb256" ,
828
- ( false , false , 32 , 8 ) => "__builtin_ia32_psubusb256" ,
829
- _ => unimplemented ! ( "signed: {}, is_add: {}, in_len: {}, elem_width: {}" , signed, is_add, in_len, elem_width) ,
830
- } ;
831
835
832
836
let result =
833
837
match ( signed, is_add) {
0 commit comments