// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
#if !NETCOREAPP
using System.Runtime.CompilerServices;
// Some routines inspired by the Stanford Bit Twiddling Hacks by Sean Eron Anderson:
// http://graphics.stanford.edu/~seander/bithacks.html
namespace System.Numerics
{
///
/// Utility methods for intrinsic bit-twiddling operations.
/// The methods use hardware intrinsics when available on the underlying platform,
/// otherwise they use optimized software fallbacks.
///
internal static class BitOperations
{
///
/// Rotates the specified value left by the specified number of bits.
/// Similar in behavior to the x86 instruction ROL.
///
/// The value to rotate.
/// The number of bits to rotate by.
/// Any value outside the range [0..31] is treated as congruent mod 32.
/// The rotated value.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateLeft(uint value, int offset)
=> (value << offset) | (value >> (32 - offset));
}
}
#endif