mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2025-03-25 10:44:46 +01:00
* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Address or silence dotnet format IDE1006 warnings * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * Fix empty lines before return Co-authored-by: Ac_K <Acoustik666@gmail.com> * Add trailing commas, remove redundant code and remove static modifier from Surface.HighBd * Fix naming rule violations * Fix naming rule violations * Fix empty line before return * Fix comment style Co-authored-by: Ac_K <Acoustik666@gmail.com> * Remove comment alignment * Address review feedback * Separate comments by 2 spaces and fix other formatting issues * Make HighBd an auto-property * Replace if-chain with if-else-chain * Fix new naming rule violations --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Numerics;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace Ryujinx.Graphics.Nvdec.Vp9.Common
|
|
{
|
|
internal static class BitUtils
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte ClipPixel(int val)
|
|
{
|
|
return (byte)((val > 255) ? 255 : (val < 0) ? 0 : val);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static ushort ClipPixelHighbd(int val, int bd)
|
|
{
|
|
return bd switch
|
|
{
|
|
10 => (ushort)Math.Clamp(val, 0, 1023),
|
|
12 => (ushort)Math.Clamp(val, 0, 4095),
|
|
_ => (ushort)Math.Clamp(val, 0, 255),
|
|
};
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static int RoundPowerOfTwo(int value, int n)
|
|
{
|
|
return (value + (1 << (n - 1))) >> n;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static long RoundPowerOfTwo(long value, int n)
|
|
{
|
|
return (value + (1L << (n - 1))) >> n;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static int AlignPowerOfTwo(int value, int n)
|
|
{
|
|
return (value + ((1 << n) - 1)) & ~((1 << n) - 1);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
private static int GetMsb(uint n)
|
|
{
|
|
Debug.Assert(n != 0);
|
|
|
|
return 31 ^ BitOperations.LeadingZeroCount(n);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static int GetUnsignedBits(uint numValues)
|
|
{
|
|
return numValues > 0 ? GetMsb(numValues) + 1 : 0;
|
|
}
|
|
}
|
|
}
|