@@ -14,6 +14,9 @@ macro_rules! uint_impl {
14
14
rot = $rot: literal,
15
15
rot_op = $rot_op: literal,
16
16
rot_result = $rot_result: literal,
17
+ fsh_op = $fsh_op: literal,
18
+ fshl_result = $fshl_result: literal,
19
+ fshr_result = $fshr_result: literal,
17
20
swap_op = $swap_op: literal,
18
21
swapped = $swapped: literal,
19
22
reversed = $reversed: literal,
@@ -375,6 +378,76 @@ macro_rules! uint_impl {
375
378
return intrinsics:: rotate_right( self , n) ;
376
379
}
377
380
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
+
378
451
/// Reverses the byte order of the integer.
379
452
///
380
453
/// # Examples
0 commit comments