using System.Runtime.CompilerServices;
namespace ComputeSharp.D2D1.NetStandard.System.Buffers;
///
/// A polyfill type that mirrors some methods from on .NET 6.
///
internal static class BitOperations
{
///
/// Rounds the given integral value up to a power of 2.
///
/// The value.
///
/// The smallest power of 2 which is greater than or equal to .
/// If is 0 or the result overflows, returns 0.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RoundUpToPowerOf2(uint value)
{
// Based on https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
--value;
value |= value >> 1;
value |= value >> 2;
value |= value >> 4;
value |= value >> 8;
value |= value >> 16;
return value + 1;
}
}