@@ -549,17 +549,18 @@ pub trait Int: Primitive
549
549
}
550
550
}
551
551
552
- macro_rules! int_impl {
553
- ( $T: ty, $BITS: expr, $ctpop: path, $ctlz: path, $cttz: path, $bswap: path) => {
552
+ macro_rules! uint_impl {
553
+ ( $T: ty, $ActualT: ty, $BITS: expr,
554
+ $ctpop: path, $ctlz: path, $cttz: path, $bswap: path) => {
554
555
impl Int for $T {
555
556
#[ inline]
556
- fn count_ones( self ) -> uint { unsafe { $ctpop( self ) as uint } }
557
+ fn count_ones( self ) -> uint { unsafe { $ctpop( self as $ActualT ) as uint } }
557
558
558
559
#[ inline]
559
- fn leading_zeros( self ) -> uint { unsafe { $ctlz( self ) as uint } }
560
+ fn leading_zeros( self ) -> uint { unsafe { $ctlz( self as $ActualT ) as uint } }
560
561
561
562
#[ inline]
562
- fn trailing_zeros( self ) -> uint { unsafe { $cttz( self ) as uint } }
563
+ fn trailing_zeros( self ) -> uint { unsafe { $cttz( self as $ActualT ) as uint } }
563
564
564
565
#[ inline]
565
566
fn rotate_left( self , n: uint) -> $T {
@@ -576,7 +577,7 @@ macro_rules! int_impl {
576
577
}
577
578
578
579
#[ inline]
579
- fn swap_bytes( self ) -> $T { unsafe { $bswap( self ) } }
580
+ fn swap_bytes( self ) -> $T { unsafe { $bswap( self as $ActualT ) as $T } }
580
581
}
581
582
}
582
583
}
@@ -585,31 +586,45 @@ macro_rules! int_impl {
585
586
/// consistency with the other `bswap` intrinsics.
586
587
unsafe fn bswap8 ( x : u8 ) -> u8 { x }
587
588
588
- int_impl ! ( u8 , 8 ,
589
+ uint_impl ! ( u8 , u8 , 8 ,
589
590
intrinsics:: ctpop8,
590
591
intrinsics:: ctlz8,
591
592
intrinsics:: cttz8,
592
593
bswap8)
593
594
594
- int_impl ! ( u16 , 16 ,
595
+ uint_impl ! ( u16 , u16 , 16 ,
595
596
intrinsics:: ctpop16,
596
597
intrinsics:: ctlz16,
597
598
intrinsics:: cttz16,
598
599
intrinsics:: bswap16)
599
600
600
- int_impl ! ( u32 , 32 ,
601
+ uint_impl ! ( u32 , u32 , 32 ,
601
602
intrinsics:: ctpop32,
602
603
intrinsics:: ctlz32,
603
604
intrinsics:: cttz32,
604
605
intrinsics:: bswap32)
605
606
606
- int_impl ! ( u64 , 64 ,
607
+ uint_impl ! ( u64 , u64 , 64 ,
607
608
intrinsics:: ctpop64,
608
609
intrinsics:: ctlz64,
609
610
intrinsics:: cttz64,
610
611
intrinsics:: bswap64)
611
612
612
- macro_rules! int_cast_impl {
613
+ #[ cfg( target_word_size = "32" ) ]
614
+ uint_impl ! ( uint, u32 , 32 ,
615
+ intrinsics:: ctpop32,
616
+ intrinsics:: ctlz32,
617
+ intrinsics:: cttz32,
618
+ intrinsics:: bswap32)
619
+
620
+ #[ cfg( target_word_size = "64" ) ]
621
+ uint_impl ! ( uint, u64 , 64 ,
622
+ intrinsics:: ctpop64,
623
+ intrinsics:: ctlz64,
624
+ intrinsics:: cttz64,
625
+ intrinsics:: bswap64)
626
+
627
+ macro_rules! int_impl {
613
628
( $T: ty, $U: ty) => {
614
629
impl Int for $T {
615
630
#[ inline]
@@ -633,15 +648,12 @@ macro_rules! int_cast_impl {
633
648
}
634
649
}
635
650
636
- int_cast_impl ! ( i8 , u8 )
637
- int_cast_impl ! ( i16 , u16 )
638
- int_cast_impl ! ( i32 , u32 )
639
- int_cast_impl ! ( i64 , u64 )
640
-
641
- #[ cfg( target_word_size = "32" ) ] int_cast_impl ! ( uint, u32 )
642
- #[ cfg( target_word_size = "64" ) ] int_cast_impl ! ( uint, u64 )
643
- #[ cfg( target_word_size = "32" ) ] int_cast_impl ! ( int, u32 )
644
- #[ cfg( target_word_size = "64" ) ] int_cast_impl ! ( int, u64 )
651
+ int_impl ! ( i8 , u8 )
652
+ int_impl ! ( i16 , u16 )
653
+ int_impl ! ( i32 , u32 )
654
+ int_impl ! ( i64 , u64 )
655
+ #[ cfg( target_word_size = "32" ) ] int_impl ! ( int, u32 )
656
+ #[ cfg( target_word_size = "64" ) ] int_impl ! ( int, u64 )
645
657
646
658
/// Unsigned integers
647
659
pub trait UnsignedInt : Int {
0 commit comments