@@ -104,6 +104,19 @@ macro_rules! uint_module {
104
104
assert_eq_const_safe!( $T: C . rotate_left( 128 ) , C ) ;
105
105
}
106
106
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
+
107
120
fn test_swap_bytes( ) {
108
121
assert_eq_const_safe!( $T: A . swap_bytes( ) . swap_bytes( ) , A ) ;
109
122
assert_eq_const_safe!( $T: B . swap_bytes( ) . swap_bytes( ) , B ) ;
@@ -150,6 +163,12 @@ macro_rules! uint_module {
150
163
}
151
164
}
152
165
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
+
153
172
#[ test]
154
173
fn test_isolate_highest_one( ) {
155
174
const BITS : $T = <$T>:: MAX ;
0 commit comments