@@ -104,6 +104,19 @@ macro_rules! uint_module {
104104 assert_eq_const_safe!( $T: C . rotate_left( 128 ) , C ) ;
105105 }
106106
107+ fn test_funnel_shift( ) {
108+ // Shifting by 0 should have no effect
109+ assert_eq_const_safe!( $T: <$T>:: funnel_shl( A , B , 0 ) , A ) ;
110+ assert_eq_const_safe!( $T: <$T>:: funnel_shr( A , B , 0 ) , B ) ;
111+
112+ assert_eq_const_safe!( $T: <$T>:: funnel_shl( _0, _1, 4 ) , 0b1111 ) ;
113+ assert_eq_const_safe!( $T: <$T>:: funnel_shr( _0, _1, 4 ) , _1 >> 4 ) ;
114+ assert_eq_const_safe!( $T: <$T>:: funnel_shl( _1, _0, 4 ) , _1 << 4 ) ;
115+
116+ assert_eq_const_safe!( $T: <$T>:: funnel_shl( _1, _1, 4 ) , <$T>:: rotate_left( _1, 4 ) ) ;
117+ assert_eq_const_safe!( $T: <$T>:: funnel_shr( _1, _1, 4 ) , <$T>:: rotate_right( _1, 4 ) ) ;
118+ }
119+
107120 fn test_swap_bytes( ) {
108121 assert_eq_const_safe!( $T: A . swap_bytes( ) . swap_bytes( ) , A ) ;
109122 assert_eq_const_safe!( $T: B . swap_bytes( ) . swap_bytes( ) , B ) ;
@@ -150,6 +163,12 @@ macro_rules! uint_module {
150163 }
151164 }
152165
166+ #[ test]
167+ #[ should_panic = "attempt to funnel shift left with overflow" ]
168+ fn test_funnel_shift_overflow( ) {
169+ let _ = <$T>:: funnel_shl( A , B , 150 ) ;
170+ }
171+
153172 #[ test]
154173 fn test_isolate_highest_one( ) {
155174 const BITS : $T = <$T>:: MAX ;
0 commit comments