@@ -4,6 +4,7 @@ use gccjit::{BinaryOp, RValue, Type};
44
55use rustc_codegen_ssa:: base:: compare_simd_types;
66use rustc_codegen_ssa:: common:: { IntPredicate , TypeKind } ;
7+ use rustc_codegen_ssa:: errors:: { ExpectedPointerMutability , InvalidMonomorphization } ;
78use rustc_codegen_ssa:: mir:: operand:: OperandRef ;
89use rustc_codegen_ssa:: mir:: place:: PlaceRef ;
910use rustc_codegen_ssa:: traits:: { BaseTypeMethods , BuilderMethods } ;
@@ -295,11 +296,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
295296 ( Style :: Unsupported , Style :: Unsupported ) => {
296297 require ! (
297298 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+ }
303307 ) ;
304308 } ,
305309 _ => return Ok ( bx. context . convert_vector ( None , args[ 0 ] . immediate ( ) , llret_ty) ) ,
@@ -362,7 +366,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
362366 }
363367 ty:: Array ( elem, len)
364368 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 ( ) )
366370 == Some ( expected_bytes) =>
367371 {
368372 // Zero-extend iN to the array length:
@@ -375,12 +379,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
375379 let ptr = bx. pointercast ( ptr, bx. cx . type_ptr_to ( array_ty) ) ;
376380 return Ok ( bx. load ( array_ty, ptr, Align :: ONE ) ) ;
377381 }
378- _ => return_error ! (
379- "cannot return `{}`, expected `u{}` or `[u8; {}]`" ,
382+ _ => return_error ! ( InvalidMonomorphization :: CannotReturn {
383+ span,
384+ name,
380385 ret_ty,
381386 expected_int_bits,
382387 expected_bytes
383- ) ,
388+ } ) ,
384389 }
385390 }
386391
@@ -410,9 +415,9 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
410415 }
411416 }
412417 }
413- } else {
414- return_error ! ( InvalidMonomorphizationNotFloat { span, name, ty: in_ty } ) ;
415- } ;
418+ else {
419+ return_error ! ( InvalidMonomorphizationNotFloat { span, name, ty: in_ty } ) ;
420+ } ;
416421
417422 let vec_ty = bx. cx . type_vector ( elem_ty, in_len) ;
418423
@@ -560,27 +565,32 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
560565 let ( out_len2, _) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
561566 require ! (
562567 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+ }
570576 ) ;
571577 require ! (
572578 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+ }
580587 ) ;
581588
582589 // 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+ ) ;
584594
585595 // This counts how many pointers
586596 fn ptr_count ( t : Ty < ' _ > ) -> usize {
@@ -607,15 +617,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
607617 _ => {
608618 require ! (
609619 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 ] ,
615625 in_elem,
616626 in_ty,
617- element_ty1 ,
618- in_elem
627+ mutability : ExpectedPointerMutability :: Not ,
628+ }
619629 ) ;
620630 unreachable ! ( ) ;
621631 }
@@ -631,10 +641,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
631641 _ => {
632642 require ! (
633643 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+ }
638650 ) ;
639651 }
640652 }
@@ -660,23 +672,25 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
660672 let ( element_len2, _) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
661673 require ! (
662674 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+ }
670683 ) ;
671684 require ! (
672685 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+ }
680694 ) ;
681695
682696 // This counts how many pointers
@@ -707,15 +721,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
707721 _ => {
708722 require ! (
709723 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 ] ,
715729 in_elem,
716730 in_ty,
717- element_ty1 ,
718- in_elem
731+ mutability : ExpectedPointerMutability :: Mut ,
732+ }
719733 ) ;
720734 unreachable ! ( ) ;
721735 }
@@ -730,10 +744,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
730744 _ => {
731745 require ! (
732746 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+ }
737753 ) ;
738754 }
739755 }
@@ -816,18 +832,6 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
816832 } ) ;
817833 }
818834 } ;
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- } ;
831835
832836 let result =
833837 match ( signed, is_add) {
0 commit comments