Improvements with new .NET 5 functions or bugfixes (#1714)
* Improvements with new .NET 5 functions or bugfixes * This no longer needs to be unsafe
This commit is contained in:
parent
7c3b559830
commit
eafee34fee
4 changed files with 11 additions and 41 deletions
|
@ -66,13 +66,9 @@ namespace Ryujinx.Common
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private unsafe static Hash128 Mult64To128(ulong lhs, ulong rhs)
|
private static Hash128 Mult64To128(ulong lhs, ulong rhs)
|
||||||
{
|
{
|
||||||
// TODO: Use BigMul once .NET 5 lands.
|
ulong high = Math.BigMul(lhs, rhs, out ulong low);
|
||||||
if (Bmi2.X64.IsSupported)
|
|
||||||
{
|
|
||||||
ulong low;
|
|
||||||
ulong high = Bmi2.X64.MultiplyNoFlags(lhs, rhs, &low);
|
|
||||||
return new Hash128
|
return new Hash128
|
||||||
{
|
{
|
||||||
Low = low,
|
Low = low,
|
||||||
|
@ -80,22 +76,6 @@ namespace Ryujinx.Common
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong loLo = Mult32To64((uint)lhs, (uint)rhs);
|
|
||||||
ulong hiLo = Mult32To64(lhs >> 32, (uint)rhs);
|
|
||||||
ulong loHi = Mult32To64((uint)lhs, rhs >> 32);
|
|
||||||
ulong hiHi = Mult32To64(lhs >> 32, rhs >> 32);
|
|
||||||
|
|
||||||
ulong cross = (loLo >> 32) + (uint)hiLo + loHi;
|
|
||||||
ulong upper = (hiLo >> 32) + (cross >> 32) + hiHi;
|
|
||||||
ulong lower = (cross << 32) | (uint)loLo;
|
|
||||||
|
|
||||||
return new Hash128
|
|
||||||
{
|
|
||||||
Low = lower,
|
|
||||||
High = upper
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static ulong Mul128Fold64(ulong lhs, ulong rhs)
|
private static ulong Mul128Fold64(ulong lhs, ulong rhs)
|
||||||
{
|
{
|
||||||
|
@ -321,9 +301,10 @@ namespace Ryujinx.Common
|
||||||
return Xxh3Avalanche(result64);
|
return Xxh3Avalanche(result64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SkipLocalsInit]
|
||||||
private static Hash128 Xxh3HashLong128bInternal(ReadOnlySpan<byte> input, ReadOnlySpan<byte> secret)
|
private static Hash128 Xxh3HashLong128bInternal(ReadOnlySpan<byte> input, ReadOnlySpan<byte> secret)
|
||||||
{
|
{
|
||||||
Span<ulong> acc = stackalloc ulong[AccNb]; // TODO: Use SkipLocalsInit attribute once .NET 5 lands.
|
Span<ulong> acc = stackalloc ulong[AccNb];
|
||||||
Xxh3InitAcc.CopyTo(acc);
|
Xxh3InitAcc.CopyTo(acc);
|
||||||
|
|
||||||
Xxh3HashLongInternalLoop(acc, input, secret);
|
Xxh3HashLongInternalLoop(acc, input, secret);
|
||||||
|
|
|
@ -7,8 +7,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common
|
||||||
{
|
{
|
||||||
internal static class BitUtils
|
internal static class BitUtils
|
||||||
{
|
{
|
||||||
// FIXME: Enable inlining here after AVX2 gather bug is fixed.
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static byte ClipPixel(int val)
|
public static byte ClipPixel(int val)
|
||||||
{
|
{
|
||||||
return (byte)((val > 255) ? 255 : (val < 0) ? 0 : val);
|
return (byte)((val > 255) ? 255 : (val < 0) ? 0 : val);
|
||||||
|
|
|
@ -374,11 +374,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
|
||||||
} while (--bH != 0);
|
} while (--bH != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Size = 80 * 2 * 80 * 2)]
|
[SkipLocalsInit]
|
||||||
struct McBufHigh
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private static unsafe void ExtendAndPredict(
|
private static unsafe void ExtendAndPredict(
|
||||||
byte* bufPtr1,
|
byte* bufPtr1,
|
||||||
int preBufStride,
|
int preBufStride,
|
||||||
|
@ -402,8 +398,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
|
||||||
int xs,
|
int xs,
|
||||||
int ys)
|
int ys)
|
||||||
{
|
{
|
||||||
McBufHigh mcBufHighStruct;
|
ushort* mcBufHigh = stackalloc ushort[80 * 2 * 80 * 2];
|
||||||
ushort* mcBufHigh = (ushort*)Unsafe.AsPointer(ref mcBufHighStruct); // Avoid zero initialization.
|
|
||||||
if (xd.CurBuf.HighBd)
|
if (xd.CurBuf.HighBd)
|
||||||
{
|
{
|
||||||
HighBuildMcBorder(bufPtr1, preBufStride, mcBufHigh, bW, x0, y0, bW, bH, frameWidth, frameHeight);
|
HighBuildMcBorder(bufPtr1, preBufStride, mcBufHigh, bW, x0, y0, bW, bH, frameWidth, frameHeight);
|
||||||
|
|
|
@ -389,11 +389,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
|
||||||
ConvolveAvgVert(src, srcStride, dst, dstStride, filter, y0Q4, yStepQ4, w, h);
|
ConvolveAvgVert(src, srcStride, dst, dstStride, filter, y0Q4, yStepQ4, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Size = 64 * 135)]
|
[SkipLocalsInit]
|
||||||
struct Temp
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe void Convolve8(
|
public static unsafe void Convolve8(
|
||||||
byte* src,
|
byte* src,
|
||||||
int srcStride,
|
int srcStride,
|
||||||
|
@ -422,8 +418,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Dsp
|
||||||
// When calling in frame scaling function, the smallest scaling factor is x1/4
|
// When calling in frame scaling function, the smallest scaling factor is x1/4
|
||||||
// ==> yStepQ4 = 64. Since w and h are at most 16, the temp buffer is still
|
// ==> yStepQ4 = 64. Since w and h are at most 16, the temp buffer is still
|
||||||
// big enough.
|
// big enough.
|
||||||
Temp tempStruct;
|
byte* temp = stackalloc byte[64 * 135];
|
||||||
byte* temp = (byte*)Unsafe.AsPointer(ref tempStruct); // Avoid zero initialization.
|
|
||||||
int intermediateHeight = (((h - 1) * yStepQ4 + y0Q4) >> SubpelBits) + SubpelTaps;
|
int intermediateHeight = (((h - 1) * yStepQ4 + y0Q4) >> SubpelBits) + SubpelTaps;
|
||||||
|
|
||||||
Debug.Assert(w <= 64);
|
Debug.Assert(w <= 64);
|
||||||
|
|
Reference in a new issue