@@ -220,12 +220,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
220
220
let after_block = func. new_block ( "after" ) ;
221
221
222
222
let arg = args[ 0 ] . immediate ( ) ;
223
- let result = func. new_local ( None , arg . get_type ( ) , "zeros" ) ;
223
+ let result = func. new_local ( None , self . u32_type , "zeros" ) ;
224
224
let zero = self . cx . gcc_zero ( arg. get_type ( ) ) ;
225
225
let cond = self . gcc_icmp ( IntPredicate :: IntEQ , arg, zero) ;
226
226
self . llbb ( ) . end_with_conditional ( None , cond, then_block, else_block) ;
227
227
228
- let zero_result = self . cx . gcc_uint ( arg . get_type ( ) , width) ;
228
+ let zero_result = self . cx . gcc_uint ( self . u32_type , width) ;
229
229
then_block. add_assignment ( None , result, zero_result) ;
230
230
then_block. end_with_jump ( None , after_block) ;
231
231
@@ -709,6 +709,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
709
709
fn count_leading_zeroes ( & mut self , width : u64 , arg : RValue < ' gcc > ) -> RValue < ' gcc > {
710
710
// TODO(antoyo): use width?
711
711
let arg_type = arg. get_type ( ) ;
712
+ let result_type = self . u32_type ;
712
713
let count_leading_zeroes =
713
714
// TODO(antoyo): write a new function Type::is_compatible_with(&Type) and use it here
714
715
// instead of using is_uint().
@@ -766,30 +767,30 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
766
767
767
768
let res = self . context . new_array_access ( self . location , result, index) ;
768
769
769
- return self . gcc_int_cast ( res. to_rvalue ( ) , arg_type ) ;
770
+ return self . gcc_int_cast ( res. to_rvalue ( ) , result_type ) ;
770
771
}
771
772
else {
772
773
let count_leading_zeroes = self . context . get_builtin_function ( "__builtin_clzll" ) ;
773
774
let arg = self . context . new_cast ( self . location , arg, self . ulonglong_type ) ;
774
775
let diff = self . ulonglong_type . get_size ( ) as i64 - arg_type. get_size ( ) as i64 ;
775
776
let diff = self . context . new_rvalue_from_long ( self . int_type , diff * 8 ) ;
776
777
let res = self . context . new_call ( self . location , count_leading_zeroes, & [ arg] ) - diff;
777
- return self . context . new_cast ( self . location , res, arg_type ) ;
778
+ return self . context . new_cast ( self . location , res, result_type ) ;
778
779
} ;
779
780
let count_leading_zeroes = self . context . get_builtin_function ( count_leading_zeroes) ;
780
781
let res = self . context . new_call ( self . location , count_leading_zeroes, & [ arg] ) ;
781
- self . context . new_cast ( self . location , res, arg_type )
782
+ self . context . new_cast ( self . location , res, result_type )
782
783
}
783
784
784
785
fn count_trailing_zeroes ( & mut self , _width : u64 , arg : RValue < ' gcc > ) -> RValue < ' gcc > {
785
- let result_type = arg. get_type ( ) ;
786
- let arg = if result_type. is_signed ( self . cx ) {
787
- let new_type = result_type. to_unsigned ( self . cx ) ;
786
+ let arg_type = arg. get_type ( ) ;
787
+ let result_type = self . u32_type ;
788
+ let arg = if arg_type. is_signed ( self . cx ) {
789
+ let new_type = arg_type. to_unsigned ( self . cx ) ;
788
790
self . gcc_int_cast ( arg, new_type)
789
791
} else {
790
792
arg
791
793
} ;
792
- let arg_type = arg. get_type ( ) ;
793
794
let ( count_trailing_zeroes, expected_type) =
794
795
// TODO(antoyo): write a new function Type::is_compatible_with(&Type) and use it here
795
796
// instead of using is_uint().
@@ -874,14 +875,12 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
874
875
875
876
fn pop_count ( & mut self , value : RValue < ' gcc > ) -> RValue < ' gcc > {
876
877
// TODO(antoyo): use the optimized version with fewer operations.
877
- let result_type = value. get_type ( ) ;
878
- let value_type = result_type. to_unsigned ( self . cx ) ;
878
+ let result_type = self . u32_type ;
879
+ let arg_type = value. get_type ( ) ;
880
+ let value_type = arg_type. to_unsigned ( self . cx ) ;
879
881
880
- let value = if result_type. is_signed ( self . cx ) {
881
- self . gcc_int_cast ( value, value_type)
882
- } else {
883
- value
884
- } ;
882
+ let value =
883
+ if arg_type. is_signed ( self . cx ) { self . gcc_int_cast ( value, value_type) } else { value } ;
885
884
886
885
// only break apart 128-bit ints if they're not natively supported
887
886
// TODO(antoyo): remove this if/when native 128-bit integers land in libgccjit
0 commit comments