@@ -907,5 +907,61 @@ ref MemoryMarshal.GetReference(Log2DeBruijn),
907907 /// <param name="divisor">Divisor value.</param>
908908 /// <returns>Ceiled division result.</returns>
909909 public static uint DivideCeil ( uint value , uint divisor ) => ( value + divisor - 1 ) / divisor ;
910+
911+ /// <summary>
912+ /// Rotates the specified value left by the specified number of bits.
913+ /// </summary>
914+ /// <param name="value">The value to rotate.</param>
915+ /// <param name="offset">The number of bits to rotate with.</param>
916+ /// <returns>The rotated value.</returns>
917+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
918+ public static uint RotateLeft( uint value , int offset )
919+ {
920+ #if SUPPORTS_BITOPERATIONS
921+ return BitOperations. RotateLeft ( value , offset ) ;
922+ #else
923+ return RotateLeftSoftwareFallback( value , offset ) ;
924+ #endif
925+ }
926+
927+ #if ! SUPPORTS_BITOPERATIONS
928+ /// <summary>
929+ /// Rotates the specified value left by the specified number of bits.
930+ /// </summary>
931+ /// <param name="value">The value to rotate.</param>
932+ /// <param name="offset">The number of bits to rotate with.</param>
933+ /// <returns>The rotated value.</returns>
934+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
935+ public static uint RotateLeftSoftwareFallback( uint value , int offset )
936+ => ( value << offset ) | ( value >> ( 32 - offset ) ) ;
937+ #endif
938+
939+ /// <summary>
940+ /// Rotates the specified value right by the specified number of bits.
941+ /// </summary>
942+ /// <param name="value">The value to rotate.</param>
943+ /// <param name="offset">The number of bits to rotate with.</param>
944+ /// <returns>The rotated value.</returns>
945+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
946+ public static uint RotateRight( uint value , int offset )
947+ {
948+ #if SUPPORTS_BITOPERATIONS
949+ return BitOperations. RotateRight ( value , offset ) ;
950+ #else
951+ return RotateRightSoftwareFallback( value , offset ) ;
952+ #endif
953+ }
954+
955+ #if ! SUPPORTS_BITOPERATIONS
956+ /// <summary>
957+ /// Rotates the specified value right by the specified number of bits.
958+ /// </summary>
959+ /// <param name="value">The value to rotate.</param>
960+ /// <param name="offset">The number of bits to rotate with.</param>
961+ /// <returns>The rotated value.</returns>
962+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
963+ public static uint RotateRightSoftwareFallback( uint value , int offset )
964+ => ( value >> offset ) | ( value << ( 32 - offset ) ) ;
965+ #endif
910966 }
911967}
0 commit comments