@@ -197,10 +197,7 @@ fn bool_to_zero_or_max_uint<'tcx>(
197
197
ty => ty,
198
198
} ;
199
199
200
- let val = if int_ty == types:: I8 { val } else { fx. bcx . ins ( ) . uextend ( int_ty, val) } ;
201
-
202
- // FIXME use bmask instead
203
- let mut res = fx. bcx . ins ( ) . ineg ( val) ;
200
+ let mut res = fx. bcx . ins ( ) . bmask ( int_ty, val) ;
204
201
205
202
if ty. is_float ( ) {
206
203
res = fx. bcx . ins ( ) . bitcast ( ty, res) ;
@@ -636,85 +633,21 @@ fn codegen_regular_intrinsic_call<'tcx>(
636
633
ret. write_cvalue ( fx, res) ;
637
634
}
638
635
sym:: bswap => {
639
- // FIXME(CraneStation/cranelift#794) add bswap instruction to cranelift
640
- fn swap ( bcx : & mut FunctionBuilder < ' _ > , v : Value ) -> Value {
641
- match bcx. func . dfg . value_type ( v) {
642
- types:: I8 => v,
643
-
644
- // https://code.woboq.org/gcc/include/bits/byteswap.h.html
645
- types:: I16 => {
646
- let tmp1 = bcx. ins ( ) . ishl_imm ( v, 8 ) ;
647
- let n1 = bcx. ins ( ) . band_imm ( tmp1, 0xFF00 ) ;
648
-
649
- let tmp2 = bcx. ins ( ) . ushr_imm ( v, 8 ) ;
650
- let n2 = bcx. ins ( ) . band_imm ( tmp2, 0x00FF ) ;
651
-
652
- bcx. ins ( ) . bor ( n1, n2)
653
- }
654
- types:: I32 => {
655
- let tmp1 = bcx. ins ( ) . ishl_imm ( v, 24 ) ;
656
- let n1 = bcx. ins ( ) . band_imm ( tmp1, 0xFF00_0000 ) ;
657
-
658
- let tmp2 = bcx. ins ( ) . ishl_imm ( v, 8 ) ;
659
- let n2 = bcx. ins ( ) . band_imm ( tmp2, 0x00FF_0000 ) ;
660
-
661
- let tmp3 = bcx. ins ( ) . ushr_imm ( v, 8 ) ;
662
- let n3 = bcx. ins ( ) . band_imm ( tmp3, 0x0000_FF00 ) ;
663
-
664
- let tmp4 = bcx. ins ( ) . ushr_imm ( v, 24 ) ;
665
- let n4 = bcx. ins ( ) . band_imm ( tmp4, 0x0000_00FF ) ;
666
-
667
- let or_tmp1 = bcx. ins ( ) . bor ( n1, n2) ;
668
- let or_tmp2 = bcx. ins ( ) . bor ( n3, n4) ;
669
- bcx. ins ( ) . bor ( or_tmp1, or_tmp2)
670
- }
671
- types:: I64 => {
672
- let tmp1 = bcx. ins ( ) . ishl_imm ( v, 56 ) ;
673
- let n1 = bcx. ins ( ) . band_imm ( tmp1, 0xFF00_0000_0000_0000u64 as i64 ) ;
674
-
675
- let tmp2 = bcx. ins ( ) . ishl_imm ( v, 40 ) ;
676
- let n2 = bcx. ins ( ) . band_imm ( tmp2, 0x00FF_0000_0000_0000u64 as i64 ) ;
677
-
678
- let tmp3 = bcx. ins ( ) . ishl_imm ( v, 24 ) ;
679
- let n3 = bcx. ins ( ) . band_imm ( tmp3, 0x0000_FF00_0000_0000u64 as i64 ) ;
680
-
681
- let tmp4 = bcx. ins ( ) . ishl_imm ( v, 8 ) ;
682
- let n4 = bcx. ins ( ) . band_imm ( tmp4, 0x0000_00FF_0000_0000u64 as i64 ) ;
683
-
684
- let tmp5 = bcx. ins ( ) . ushr_imm ( v, 8 ) ;
685
- let n5 = bcx. ins ( ) . band_imm ( tmp5, 0x0000_0000_FF00_0000u64 as i64 ) ;
686
-
687
- let tmp6 = bcx. ins ( ) . ushr_imm ( v, 24 ) ;
688
- let n6 = bcx. ins ( ) . band_imm ( tmp6, 0x0000_0000_00FF_0000u64 as i64 ) ;
689
-
690
- let tmp7 = bcx. ins ( ) . ushr_imm ( v, 40 ) ;
691
- let n7 = bcx. ins ( ) . band_imm ( tmp7, 0x0000_0000_0000_FF00u64 as i64 ) ;
692
-
693
- let tmp8 = bcx. ins ( ) . ushr_imm ( v, 56 ) ;
694
- let n8 = bcx. ins ( ) . band_imm ( tmp8, 0x0000_0000_0000_00FFu64 as i64 ) ;
695
-
696
- let or_tmp1 = bcx. ins ( ) . bor ( n1, n2) ;
697
- let or_tmp2 = bcx. ins ( ) . bor ( n3, n4) ;
698
- let or_tmp3 = bcx. ins ( ) . bor ( n5, n6) ;
699
- let or_tmp4 = bcx. ins ( ) . bor ( n7, n8) ;
700
-
701
- let or_tmp5 = bcx. ins ( ) . bor ( or_tmp1, or_tmp2) ;
702
- let or_tmp6 = bcx. ins ( ) . bor ( or_tmp3, or_tmp4) ;
703
- bcx. ins ( ) . bor ( or_tmp5, or_tmp6)
704
- }
705
- types:: I128 => {
706
- let ( lo, hi) = bcx. ins ( ) . isplit ( v) ;
707
- let lo = swap ( bcx, lo) ;
708
- let hi = swap ( bcx, hi) ;
709
- bcx. ins ( ) . iconcat ( hi, lo)
710
- }
711
- ty => unreachable ! ( "bswap {}" , ty) ,
712
- }
713
- }
714
636
intrinsic_args ! ( fx, args => ( arg) ; intrinsic) ;
715
637
let val = arg. load_scalar ( fx) ;
716
638
717
- let res = CValue :: by_val ( swap ( & mut fx. bcx , val) , arg. layout ( ) ) ;
639
+ let res = match fx. bcx . func . dfg . value_type ( val) {
640
+ types:: I8 => val,
641
+ types:: I128 => {
642
+ // FIXME(bytecodealliance/wasmtime#1092) bswap.i128 is not yet implemented
643
+ let ( lsb, msb) = fx. bcx . ins ( ) . isplit ( val) ;
644
+ let lsb_swap = fx. bcx . ins ( ) . bswap ( lsb) ;
645
+ let msb_swap = fx. bcx . ins ( ) . bswap ( msb) ;
646
+ fx. bcx . ins ( ) . iconcat ( msb_swap, lsb_swap)
647
+ }
648
+ _ => fx. bcx . ins ( ) . bswap ( val) ,
649
+ } ;
650
+ let res = CValue :: by_val ( res, arg. layout ( ) ) ;
718
651
ret. write_cvalue ( fx, res) ;
719
652
}
720
653
sym:: assert_inhabited | sym:: assert_zero_valid | sym:: assert_uninit_valid => {
0 commit comments