Added Generic Math to BitUtils (#3929)

* Generic Math Update

Updated Several functions in Ryujinx.Common/Utilities/BitUtils to use generic math

* Updated BitUtil calls

* Removed Whitespace

* Switched decrement

* Fixed changed method calls.

The method calls were originally changed on accident due to me relying too much on intellisense doing stuff for me

* Update Ryujinx.Common/Utilities/BitUtils.cs

Co-authored-by: gdkchan <gab.dark.100@gmail.com>

Co-authored-by: gdkchan <gab.dark.100@gmail.com>
This commit is contained in:
Hunter 2022-12-26 09:11:05 -05:00 committed by GitHub
parent a4fdfb5f94
commit c963b3c804
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 67 additions and 123 deletions

View file

@ -1,82 +1,26 @@
using System;
using System.Numerics;
namespace Ryujinx.Common
{
public static class BitUtils
{
public static uint AlignUp(uint value, int size)
public static T AlignUp<T>(T value, T size)
where T : IBinaryInteger<T>
{
return (uint)AlignUp((int)value, size);
return (value + (size - T.One)) & -size;
}
public static int AlignUp(int value, int size)
{
return (value + (size - 1)) & -size;
}
public static ulong AlignUp(ulong value, int size)
{
return (ulong)AlignUp((long)value, size);
}
public static long AlignUp(long value, int size)
{
return AlignUp(value, (long)size);
}
public static ulong AlignUp(ulong value, ulong size)
{
return (ulong)AlignUp((long)value, (long)size);
}
public static long AlignUp(long value, long size)
{
return (value + (size - 1)) & -size;
}
public static uint AlignDown(uint value, int size)
{
return (uint)AlignDown((int)value, size);
}
public static int AlignDown(int value, int size)
public static T AlignDown<T>(T value, T size)
where T : IBinaryInteger<T>
{
return value & -size;
}
public static ulong AlignDown(ulong value, int size)
public static T DivRoundUp<T>(T value, T dividend)
where T : IBinaryInteger<T>
{
return (ulong)AlignDown((long)value, size);
}
public static long AlignDown(long value, int size)
{
return AlignDown(value, (long)size);
}
public static ulong AlignDown(ulong value, ulong size)
{
return (ulong)AlignDown((long)value, (long)size);
}
public static long AlignDown(long value, long size)
{
return value & -size;
}
public static int DivRoundUp(int value, int dividend)
{
return (value + dividend - 1) / dividend;
}
public static ulong DivRoundUp(ulong value, uint dividend)
{
return (value + dividend - 1) / dividend;
}
public static long DivRoundUp(long value, int dividend)
{
return (value + dividend - 1) / dividend;
return (value + (dividend - T.One)) / dividend;
}
public static int Pow2RoundUp(int value)