@@ -583,6 +583,27 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
583583 self . pointercast ( val, self . type_ptr ( ) )
584584 }
585585
586+ sym:: sve_cast => {
587+ let Some ( ( in_cnt, in_elem, in_num_vecs) ) =
588+ args[ 0 ] . layout . ty . scalable_vector_parts ( self . cx . tcx )
589+ else {
590+ bug ! ( "input parameter to `sve_cast` was not scalable vector" ) ;
591+ } ;
592+ let out_layout = self . layout_of ( fn_args. type_at ( 1 ) ) ;
593+ let Some ( ( out_cnt, out_elem, out_num_vecs) ) =
594+ out_layout. ty . scalable_vector_parts ( self . cx . tcx )
595+ else {
596+ bug ! ( "output parameter to `sve_cast` was not scalable vector" ) ;
597+ } ;
598+ assert_eq ! ( in_cnt, out_cnt) ;
599+ assert_eq ! ( in_num_vecs, out_num_vecs) ;
600+ let out_llty = self . backend_type ( out_layout) ;
601+ match simd_cast ( self , sym:: simd_cast, args, out_llty, in_elem, out_elem) {
602+ Some ( val) => val,
603+ _ => bug ! ( "could not cast scalable vectors" ) ,
604+ }
605+ }
606+
586607 sym:: sve_tuple_create2 => {
587608 assert_matches ! (
588609 self . layout_of( fn_args. type_at( 0 ) ) . backend_repr,
@@ -2757,96 +2778,17 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
27572778 out_len
27582779 }
27592780 ) ;
2760- // casting cares about nominal type, not just structural type
2761- if in_elem == out_elem {
2762- return Ok ( args[ 0 ] . immediate ( ) ) ;
2763- }
2764-
2765- #[ derive( Copy , Clone ) ]
2766- enum Sign {
2767- Unsigned ,
2768- Signed ,
2769- }
2770- use Sign :: * ;
2771-
2772- enum Style {
2773- Float ,
2774- Int ( Sign ) ,
2775- Unsupported ,
2776- }
2777-
2778- let ( in_style, in_width) = match in_elem. kind ( ) {
2779- // vectors of pointer-sized integers should've been
2780- // disallowed before here, so this unwrap is safe.
2781- ty:: Int ( i) => (
2782- Style :: Int ( Signed ) ,
2783- i. normalize ( bx. tcx ( ) . sess . target . pointer_width ) . bit_width ( ) . unwrap ( ) ,
2784- ) ,
2785- ty:: Uint ( u) => (
2786- Style :: Int ( Unsigned ) ,
2787- u. normalize ( bx. tcx ( ) . sess . target . pointer_width ) . bit_width ( ) . unwrap ( ) ,
2788- ) ,
2789- ty:: Float ( f) => ( Style :: Float , f. bit_width ( ) ) ,
2790- _ => ( Style :: Unsupported , 0 ) ,
2791- } ;
2792- let ( out_style, out_width) = match out_elem. kind ( ) {
2793- ty:: Int ( i) => (
2794- Style :: Int ( Signed ) ,
2795- i. normalize ( bx. tcx ( ) . sess . target . pointer_width ) . bit_width ( ) . unwrap ( ) ,
2796- ) ,
2797- ty:: Uint ( u) => (
2798- Style :: Int ( Unsigned ) ,
2799- u. normalize ( bx. tcx ( ) . sess . target . pointer_width ) . bit_width ( ) . unwrap ( ) ,
2800- ) ,
2801- ty:: Float ( f) => ( Style :: Float , f. bit_width ( ) ) ,
2802- _ => ( Style :: Unsupported , 0 ) ,
2803- } ;
2804-
2805- match ( in_style, out_style) {
2806- ( Style :: Int ( sign) , Style :: Int ( _) ) => {
2807- return Ok ( match in_width. cmp ( & out_width) {
2808- Ordering :: Greater => bx. trunc ( args[ 0 ] . immediate ( ) , llret_ty) ,
2809- Ordering :: Equal => args[ 0 ] . immediate ( ) ,
2810- Ordering :: Less => match sign {
2811- Sign :: Signed => bx. sext ( args[ 0 ] . immediate ( ) , llret_ty) ,
2812- Sign :: Unsigned => bx. zext ( args[ 0 ] . immediate ( ) , llret_ty) ,
2813- } ,
2814- } ) ;
2815- }
2816- ( Style :: Int ( Sign :: Signed ) , Style :: Float ) => {
2817- return Ok ( bx. sitofp ( args[ 0 ] . immediate ( ) , llret_ty) ) ;
2818- }
2819- ( Style :: Int ( Sign :: Unsigned ) , Style :: Float ) => {
2820- return Ok ( bx. uitofp ( args[ 0 ] . immediate ( ) , llret_ty) ) ;
2821- }
2822- ( Style :: Float , Style :: Int ( sign) ) => {
2823- return Ok ( match ( sign, name == sym:: simd_as) {
2824- ( Sign :: Unsigned , false ) => bx. fptoui ( args[ 0 ] . immediate ( ) , llret_ty) ,
2825- ( Sign :: Signed , false ) => bx. fptosi ( args[ 0 ] . immediate ( ) , llret_ty) ,
2826- ( _, true ) => bx. cast_float_to_int (
2827- matches ! ( sign, Sign :: Signed ) ,
2828- args[ 0 ] . immediate ( ) ,
2829- llret_ty,
2830- ) ,
2831- } ) ;
2832- }
2833- ( Style :: Float , Style :: Float ) => {
2834- return Ok ( match in_width. cmp ( & out_width) {
2835- Ordering :: Greater => bx. fptrunc ( args[ 0 ] . immediate ( ) , llret_ty) ,
2836- Ordering :: Equal => args[ 0 ] . immediate ( ) ,
2837- Ordering :: Less => bx. fpext ( args[ 0 ] . immediate ( ) , llret_ty) ,
2838- } ) ;
2839- }
2840- _ => { /* Unsupported. Fallthrough. */ }
2781+ match simd_cast ( bx, name, args, llret_ty, in_elem, out_elem) {
2782+ Some ( val) => return Ok ( val) ,
2783+ None => return_error ! ( InvalidMonomorphization :: UnsupportedCast {
2784+ span,
2785+ name,
2786+ in_ty,
2787+ in_elem,
2788+ ret_ty,
2789+ out_elem
2790+ } ) ,
28412791 }
2842- return_error ! ( InvalidMonomorphization :: UnsupportedCast {
2843- span,
2844- name,
2845- in_ty,
2846- in_elem,
2847- ret_ty,
2848- out_elem
2849- } ) ;
28502792 }
28512793 macro_rules! arith_binary {
28522794 ( $( $name: ident: $( $( $p: ident) ,* => $call: ident) ,* ; ) * ) => {
@@ -3020,3 +2962,86 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
30202962
30212963 span_bug ! ( span, "unknown SIMD intrinsic" ) ;
30222964}
2965+
2966+ /// Implementation of `core::intrinsics::simd_cast`, re-used by `core::scalable::sve_cast`.
2967+ fn simd_cast < ' ll , ' tcx > (
2968+ bx : & mut Builder < ' _ , ' ll , ' tcx > ,
2969+ name : Symbol ,
2970+ args : & [ OperandRef < ' tcx , & ' ll Value > ] ,
2971+ llret_ty : & ' ll Type ,
2972+ in_elem : Ty < ' tcx > ,
2973+ out_elem : Ty < ' tcx > ,
2974+ ) -> Option < & ' ll Value > {
2975+ // Casting cares about nominal type, not just structural type
2976+ if in_elem == out_elem {
2977+ return Some ( args[ 0 ] . immediate ( ) ) ;
2978+ }
2979+
2980+ #[ derive( Copy , Clone ) ]
2981+ enum Sign {
2982+ Unsigned ,
2983+ Signed ,
2984+ }
2985+ use Sign :: * ;
2986+
2987+ enum Style {
2988+ Float ,
2989+ Int ( Sign ) ,
2990+ Unsupported ,
2991+ }
2992+
2993+ let ( in_style, in_width) = match in_elem. kind ( ) {
2994+ // vectors of pointer-sized integers should've been
2995+ // disallowed before here, so this unwrap is safe.
2996+ ty:: Int ( i) => (
2997+ Style :: Int ( Signed ) ,
2998+ i. normalize ( bx. tcx ( ) . sess . target . pointer_width ) . bit_width ( ) . unwrap ( ) ,
2999+ ) ,
3000+ ty:: Uint ( u) => (
3001+ Style :: Int ( Unsigned ) ,
3002+ u. normalize ( bx. tcx ( ) . sess . target . pointer_width ) . bit_width ( ) . unwrap ( ) ,
3003+ ) ,
3004+ ty:: Float ( f) => ( Style :: Float , f. bit_width ( ) ) ,
3005+ _ => ( Style :: Unsupported , 0 ) ,
3006+ } ;
3007+ let ( out_style, out_width) = match out_elem. kind ( ) {
3008+ ty:: Int ( i) => (
3009+ Style :: Int ( Signed ) ,
3010+ i. normalize ( bx. tcx ( ) . sess . target . pointer_width ) . bit_width ( ) . unwrap ( ) ,
3011+ ) ,
3012+ ty:: Uint ( u) => (
3013+ Style :: Int ( Unsigned ) ,
3014+ u. normalize ( bx. tcx ( ) . sess . target . pointer_width ) . bit_width ( ) . unwrap ( ) ,
3015+ ) ,
3016+ ty:: Float ( f) => ( Style :: Float , f. bit_width ( ) ) ,
3017+ _ => ( Style :: Unsupported , 0 ) ,
3018+ } ;
3019+
3020+ match ( in_style, out_style) {
3021+ ( Style :: Int ( sign) , Style :: Int ( _) ) => Some ( match in_width. cmp ( & out_width) {
3022+ Ordering :: Greater => bx. trunc ( args[ 0 ] . immediate ( ) , llret_ty) ,
3023+ Ordering :: Equal => args[ 0 ] . immediate ( ) ,
3024+ Ordering :: Less => match sign {
3025+ Sign :: Signed => bx. sext ( args[ 0 ] . immediate ( ) , llret_ty) ,
3026+ Sign :: Unsigned => bx. zext ( args[ 0 ] . immediate ( ) , llret_ty) ,
3027+ } ,
3028+ } ) ,
3029+ ( Style :: Int ( Sign :: Signed ) , Style :: Float ) => Some ( bx. sitofp ( args[ 0 ] . immediate ( ) , llret_ty) ) ,
3030+ ( Style :: Int ( Sign :: Unsigned ) , Style :: Float ) => {
3031+ Some ( bx. uitofp ( args[ 0 ] . immediate ( ) , llret_ty) )
3032+ }
3033+ ( Style :: Float , Style :: Int ( sign) ) => Some ( match ( sign, name == sym:: simd_as) {
3034+ ( Sign :: Unsigned , false ) => bx. fptoui ( args[ 0 ] . immediate ( ) , llret_ty) ,
3035+ ( Sign :: Signed , false ) => bx. fptosi ( args[ 0 ] . immediate ( ) , llret_ty) ,
3036+ ( _, true ) => {
3037+ bx. cast_float_to_int ( matches ! ( sign, Sign :: Signed ) , args[ 0 ] . immediate ( ) , llret_ty)
3038+ }
3039+ } ) ,
3040+ ( Style :: Float , Style :: Float ) => Some ( match in_width. cmp ( & out_width) {
3041+ Ordering :: Greater => bx. fptrunc ( args[ 0 ] . immediate ( ) , llret_ty) ,
3042+ Ordering :: Equal => args[ 0 ] . immediate ( ) ,
3043+ Ordering :: Less => bx. fpext ( args[ 0 ] . immediate ( ) , llret_ty) ,
3044+ } ) ,
3045+ _ => None ,
3046+ }
3047+ }
0 commit comments