@@ -596,34 +596,17 @@ fn numeric_intrinsic<'tcx>(
596596 bytes : u128 ,
597597 kind : Primitive ,
598598) -> EvalResult < ' tcx , Scalar > {
599- macro_rules! integer_intrinsic {
600- ( $method: ident) => ( {
601- use rustc_target:: abi:: Integer ;
602- let ( bits, defined) = match kind {
603- Primitive :: Int ( Integer :: I8 , true ) => ( ( bytes as i8 ) . $method( ) as u128 , 8 ) ,
604- Primitive :: Int ( Integer :: I8 , false ) => ( ( bytes as u8 ) . $method( ) as u128 , 8 ) ,
605- Primitive :: Int ( Integer :: I16 , true ) => ( ( bytes as i16 ) . $method( ) as u128 , 16 ) ,
606- Primitive :: Int ( Integer :: I16 , false ) => ( ( bytes as u16 ) . $method( ) as u128 , 16 ) ,
607- Primitive :: Int ( Integer :: I32 , true ) => ( ( bytes as i32 ) . $method( ) as u128 , 32 ) ,
608- Primitive :: Int ( Integer :: I32 , false ) => ( ( bytes as u32 ) . $method( ) as u128 , 32 ) ,
609- Primitive :: Int ( Integer :: I64 , true ) => ( ( bytes as i64 ) . $method( ) as u128 , 64 ) ,
610- Primitive :: Int ( Integer :: I64 , false ) => ( ( bytes as u64 ) . $method( ) as u128 , 64 ) ,
611- Primitive :: Int ( Integer :: I128 , true ) => ( ( bytes as i128 ) . $method( ) as u128 , 128 ) ,
612- Primitive :: Int ( Integer :: I128 , false ) => ( bytes. $method( ) as u128 , 128 ) ,
613- _ => bug!( "invalid `{}` argument: {:?}" , name, bytes) ,
614- } ;
615-
616- Scalar :: Bits { bits, defined }
617- } ) ;
618- }
619-
620- let result_val = match name {
621- "bswap" => integer_intrinsic ! ( swap_bytes) ,
622- "ctlz" => integer_intrinsic ! ( leading_zeros) ,
623- "ctpop" => integer_intrinsic ! ( count_ones) ,
624- "cttz" => integer_intrinsic ! ( trailing_zeros) ,
599+ let defined = match kind {
600+ Primitive :: Int ( integer, _) => integer. size ( ) . bits ( ) as u8 ,
601+ _ => bug ! ( "invalid `{}` argument: {:?}" , name, bytes) ,
602+ } ;
603+ let extra = 128 - defined as u128 ;
604+ let bytes_out = match name {
605+ "ctpop" => bytes. count_ones ( ) as u128 ,
606+ "ctlz" => bytes. leading_zeros ( ) as u128 - extra,
607+ "cttz" => ( bytes << extra) . trailing_zeros ( ) as u128 - extra,
608+ "bswap" => ( bytes << extra) . swap_bytes ( ) ,
625609 _ => bug ! ( "not a numeric intrinsic: {}" , name) ,
626610 } ;
627-
628- Ok ( result_val)
611+ Ok ( Scalar :: Bits { bits : bytes_out, defined } )
629612}
0 commit comments