@@ -468,40 +468,32 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
468
468
}
469
469
}
470
470
471
- fn add ( & mut self , a : RValue < ' gcc > , mut b : RValue < ' gcc > ) -> RValue < ' gcc > {
472
- // FIXME(antoyo): this should not be required.
473
- if format ! ( "{:?}" , a. get_type( ) ) != format ! ( "{:?}" , b. get_type( ) ) {
474
- b = self . context . new_cast ( None , b, a. get_type ( ) ) ;
475
- }
476
- a + b
471
+ fn add ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
472
+ self . gcc_add ( a, b)
477
473
}
478
474
479
475
fn fadd ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
480
476
a + b
481
477
}
482
478
483
- fn sub ( & mut self , a : RValue < ' gcc > , mut b : RValue < ' gcc > ) -> RValue < ' gcc > {
484
- if a. get_type ( ) != b. get_type ( ) {
485
- b = self . context . new_cast ( None , b, a. get_type ( ) ) ;
486
- }
487
- a - b
479
+ fn sub ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
480
+ self . gcc_sub ( a, b)
488
481
}
489
482
490
483
fn fsub ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
491
484
a - b
492
485
}
493
486
494
487
fn mul ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
495
- a * b
488
+ self . gcc_mul ( a , b )
496
489
}
497
490
498
491
fn fmul ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
499
492
a * b
500
493
}
501
494
502
495
fn udiv ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
503
- // TODO(antoyo): convert the arguments to unsigned?
504
- a / b
496
+ self . gcc_udiv ( a, b)
505
497
}
506
498
507
499
fn exactudiv ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
@@ -529,7 +521,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
529
521
}
530
522
531
523
fn urem ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
532
- a % b
524
+ self . gcc_urem ( a , b )
533
525
}
534
526
535
527
fn srem ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
@@ -549,40 +541,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
549
541
}
550
542
551
543
fn shl ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
552
- // FIXME(antoyo): remove the casts when libgccjit can shift an unsigned number by an unsigned number.
553
- let a_type = a. get_type ( ) ;
554
- let b_type = b. get_type ( ) ;
555
- if a_type. is_unsigned ( self ) && b_type. is_signed ( self ) {
556
- let a = self . context . new_cast ( None , a, b_type) ;
557
- let result = a << b;
558
- self . context . new_cast ( None , result, a_type)
559
- }
560
- else if a_type. is_signed ( self ) && b_type. is_unsigned ( self ) {
561
- let b = self . context . new_cast ( None , b, a_type) ;
562
- a << b
563
- }
564
- else {
565
- a << b
566
- }
544
+ self . gcc_shl ( a, b)
567
545
}
568
546
569
547
fn lshr ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
570
- // FIXME(antoyo): remove the casts when libgccjit can shift an unsigned number by an unsigned number.
571
- // TODO(antoyo): cast to unsigned to do a logical shift if that does not work.
572
- let a_type = a. get_type ( ) ;
573
- let b_type = b. get_type ( ) ;
574
- if a_type. is_unsigned ( self ) && b_type. is_signed ( self ) {
575
- let a = self . context . new_cast ( None , a, b_type) ;
576
- let result = a >> b;
577
- self . context . new_cast ( None , result, a_type)
578
- }
579
- else if a_type. is_signed ( self ) && b_type. is_unsigned ( self ) {
580
- let b = self . context . new_cast ( None , b, a_type) ;
581
- a >> b
582
- }
583
- else {
584
- a >> b
585
- }
548
+ self . gcc_lshr ( a, b)
586
549
}
587
550
588
551
fn ashr ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
@@ -604,41 +567,28 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
604
567
}
605
568
}
606
569
607
- fn and ( & mut self , a : RValue < ' gcc > , mut b : RValue < ' gcc > ) -> RValue < ' gcc > {
608
- if a. get_type ( ) != b. get_type ( ) {
609
- b = self . context . new_cast ( None , b, a. get_type ( ) ) ;
610
- }
611
- a & b
570
+ fn and ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
571
+ self . gcc_and ( a, b)
612
572
}
613
573
614
- fn or ( & mut self , a : RValue < ' gcc > , mut b : RValue < ' gcc > ) -> RValue < ' gcc > {
615
- if a. get_type ( ) != b. get_type ( ) {
616
- b = self . context . new_cast ( None , b, a. get_type ( ) ) ;
617
- }
618
- a | b
574
+ fn or ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
575
+ self . gcc_or ( a, b)
619
576
}
620
577
621
578
fn xor ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
622
579
a ^ b
623
580
}
624
581
625
582
fn neg ( & mut self , a : RValue < ' gcc > ) -> RValue < ' gcc > {
626
- self . cx . context . new_unary_op ( None , UnaryOp :: Minus , a . get_type ( ) , a)
583
+ self . gcc_neg ( a)
627
584
}
628
585
629
586
fn fneg ( & mut self , a : RValue < ' gcc > ) -> RValue < ' gcc > {
630
587
self . cx . context . new_unary_op ( None , UnaryOp :: Minus , a. get_type ( ) , a)
631
588
}
632
589
633
590
fn not ( & mut self , a : RValue < ' gcc > ) -> RValue < ' gcc > {
634
- let operation =
635
- if a. get_type ( ) . is_bool ( ) {
636
- UnaryOp :: LogicalNegate
637
- }
638
- else {
639
- UnaryOp :: BitwiseNegate
640
- } ;
641
- self . cx . context . new_unary_op ( None , operation, a. get_type ( ) , a)
591
+ self . gcc_not ( a)
642
592
}
643
593
644
594
fn unchecked_sadd ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
@@ -1049,40 +999,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
1049
999
1050
1000
fn intcast ( & mut self , value : RValue < ' gcc > , dest_typ : Type < ' gcc > , _is_signed : bool ) -> RValue < ' gcc > {
1051
1001
// NOTE: is_signed is for value, not dest_typ.
1052
- if self . supports_native_int_type ( dest_typ) && self . supports_native_int_type ( value. get_type ( ) ) {
1053
- self . cx . context . new_cast ( None , value, dest_typ)
1054
- }
1055
- else {
1056
- let value_type = value. get_type ( ) ;
1057
- let src_size = self . cx . int_type_size ( value_type) ;
1058
- let src_element_size = self . cx . int_type_element_size ( value_type) ;
1059
- let dest_size = self . cx . int_type_size ( dest_typ) ;
1060
- let factor = ( dest_size / src_size) as usize ;
1061
- let array_type = self . context . new_array_type ( None , value_type, factor as i32 ) ;
1062
-
1063
- if src_size < dest_size {
1064
- // TODO: initialize to -1 if negative.
1065
- let mut values = vec ! [ self . context. new_rvalue_zero( value_type) ; factor] ;
1066
- // TODO: take endianness into account.
1067
- values[ factor - 1 ] = value;
1068
- let array_value = self . context . new_rvalue_from_array ( None , array_type, & values) ;
1069
- self . cx . context . new_bitcast ( None , array_value, dest_typ)
1070
- }
1071
- else {
1072
- let mut current_size = 0 ;
1073
- // TODO: take endianness into account.
1074
- let mut current_index = src_size / src_element_size - 1 ;
1075
- let mut values = vec ! [ ] ;
1076
- while current_size < dest_size {
1077
- values. push ( self . context . new_array_access ( None , value, self . context . new_rvalue_from_int ( self . int_type , current_index as i32 ) ) . to_rvalue ( ) ) ;
1078
- current_size += src_element_size;
1079
- current_index -= 1 ;
1080
- }
1081
- let array_value = self . context . new_rvalue_from_array ( None , array_type, & values) ;
1082
- // FIXME: that's not working since we can cast from u8 to struct u128.
1083
- self . cx . context . new_bitcast ( None , array_value, dest_typ)
1084
- }
1085
- }
1002
+ self . gcc_int_cast ( value, dest_typ)
1086
1003
}
1087
1004
1088
1005
fn pointercast ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
@@ -1424,7 +1341,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
1424
1341
// Fix the code in codegen_ssa::base::from_immediate.
1425
1342
return value;
1426
1343
}
1427
- self . context . new_cast ( None , value, dest_typ)
1344
+ self . gcc_int_cast ( value, dest_typ)
1428
1345
}
1429
1346
1430
1347
fn cx ( & self ) -> & CodegenCx < ' gcc , ' tcx > {
0 commit comments