From c963b3c80488f88c9d7f44588b6ba45051af3e2d Mon Sep 17 00:00:00 2001 From: Hunter <102537986+HunterBarney@users.noreply.github.com> Date: Mon, 26 Dec 2022 09:11:05 -0500 Subject: 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 Co-authored-by: gdkchan --- Ryujinx.Common/Utilities/BitUtils.cs | 74 +++++------------------------------- 1 file changed, 9 insertions(+), 65 deletions(-) (limited to 'Ryujinx.Common/Utilities') 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 value, T size) + where T : IBinaryInteger { - 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 value, T size) + where T : IBinaryInteger { 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 value, T dividend) + where T : IBinaryInteger { - return (value + dividend - 1) / dividend; + return (value + (dividend - T.One)) / dividend; } public static int Pow2RoundUp(int value) -- cgit v1.2.3