@@ -14,6 +14,9 @@ macro_rules! uint_impl {
1414 rot = $rot: literal,
1515 rot_op = $rot_op: literal,
1616 rot_result = $rot_result: literal,
17+ fsh_op = $fsh_op: literal,
18+ fshl_result = $fshl_result: literal,
19+ fshr_result = $fshr_result: literal,
1720 swap_op = $swap_op: literal,
1821 swapped = $swapped: literal,
1922 reversed = $reversed: literal,
@@ -375,6 +378,76 @@ macro_rules! uint_impl {
375378 return intrinsics:: rotate_right( self , n) ;
376379 }
377380
381+ /// Performs a left funnel shift (concatenates `self` with `rhs`, with `self`
382+ /// making up the most significant half, then shifts the combined value left
383+ /// by `n`, and most significant half is extracted to produce the result).
384+ ///
385+ /// Please note this isn't the same operation as the `<<` shifting operator or
386+ /// [`rotate_left`](Self::rotate_left), although `a.funnel_shl(a, n)` is *equivalent*
387+ /// to `a.rotate_left(n)`.
388+ ///
389+ /// # Panics
390+ ///
391+ /// If `n` is greater than or equal to the number of bits in `self`
392+ ///
393+ /// # Examples
394+ ///
395+ /// Basic usage:
396+ ///
397+ /// ```
398+ /// #![feature(funnel_shifts)]
399+ #[ doc = concat!( "let a = " , $rot_op, stringify!( $SelfT) , ";" ) ]
400+ #[ doc = concat!( "let b = " , $fsh_op, stringify!( $SelfT) , ";" ) ]
401+ #[ doc = concat!( "let m = " , $fshl_result, ";" ) ]
402+ ///
403+ #[ doc = concat!( "assert_eq!(a.funnel_shl(b, " , $rot, "), m);" ) ]
404+ /// ```
405+ #[ rustc_const_unstable( feature = "funnel_shifts" , issue = "145686" ) ]
406+ #[ unstable( feature = "funnel_shifts" , issue = "145686" ) ]
407+ #[ must_use = "this returns the result of the operation, \
408+ without modifying the original"]
409+ #[ inline( always) ]
410+ pub const fn funnel_shl( self , rhs: Self , n: u32 ) -> Self {
411+ assert!( n < Self :: BITS , "attempt to funnel shift left with overflow" ) ;
412+ // SAFETY: just checked that `shift` is in-range
413+ unsafe { intrinsics:: unchecked_funnel_shl( self , rhs, n) }
414+ }
415+
416+ /// Performs a right funnel shift (concatenates `self` and `rhs`, with `self`
417+ /// making up the most significant half, then shifts the combined value right
418+ /// by `n`, and least significant half is extracted to produce the result).
419+ ///
420+ /// Please note this isn't the same operation as the `>>` shifting operator or
421+ /// [`rotate_right`](Self::rotate_right), although `a.funnel_shr(a, n)` is *equivalent*
422+ /// to `a.rotate_right(n)`.
423+ ///
424+ /// # Panics
425+ ///
426+ /// If `n` is greater than or equal to the number of bits in `self`
427+ ///
428+ /// # Examples
429+ ///
430+ /// Basic usage:
431+ ///
432+ /// ```
433+ /// #![feature(funnel_shifts)]
434+ #[ doc = concat!( "let a = " , $rot_op, stringify!( $SelfT) , ";" ) ]
435+ #[ doc = concat!( "let b = " , $fsh_op, stringify!( $SelfT) , ";" ) ]
436+ #[ doc = concat!( "let m = " , $fshr_result, ";" ) ]
437+ ///
438+ #[ doc = concat!( "assert_eq!(a.funnel_shr(b, " , $rot, "), m);" ) ]
439+ /// ```
440+ #[ rustc_const_unstable( feature = "funnel_shifts" , issue = "145686" ) ]
441+ #[ unstable( feature = "funnel_shifts" , issue = "145686" ) ]
442+ #[ must_use = "this returns the result of the operation, \
443+ without modifying the original"]
444+ #[ inline( always) ]
445+ pub const fn funnel_shr( self , rhs: Self , n: u32 ) -> Self {
446+ assert!( n < Self :: BITS , "attempt to funnel shift right with overflow" ) ;
447+ // SAFETY: just checked that `shift` is in-range
448+ unsafe { intrinsics:: unchecked_funnel_shr( self , rhs, n) }
449+ }
450+
378451 /// Reverses the byte order of the integer.
379452 ///
380453 /// # Examples
0 commit comments