diff options
author | Hunter <102537986+HunterBarney@users.noreply.github.com> | 2022-12-26 09:11:05 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-26 14:11:05 +0000 |
commit | c963b3c80488f88c9d7f44588b6ba45051af3e2d (patch) | |
tree | 3f18132ba47306a65b13690216a61323113da962 /Ryujinx.Common/Utilities/BitUtils.cs | |
parent | a4fdfb5f94121f5c60fc5717175fd21f3e774e85 (diff) |
Added Generic Math to BitUtils (#3929)1.1.491
* 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>
Diffstat (limited to 'Ryujinx.Common/Utilities/BitUtils.cs')
-rw-r--r-- | Ryujinx.Common/Utilities/BitUtils.cs | 74 |
1 files changed, 9 insertions, 65 deletions
diff --git a/Ryujinx.Common/Utilities/BitUtils.cs b/Ryujinx.Common/Utilities/BitUtils.cs index a42e2cc7..f885ce84 100644 --- a/Ryujinx.Common/Utilities/BitUtils.cs +++ b/Ryujinx.Common/Utilities/BitUtils.cs @@ -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) - { - 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) + public static T DivRoundUp<T>(T value, T dividend) + where T : IBinaryInteger<T> { - return (value + dividend - 1) / dividend; + return (value + (dividend - T.One)) / dividend; } public static int Pow2RoundUp(int value) |