diff options
Diffstat (limited to 'Ryujinx.Graphics.Vic/Types/BitfieldExtensions.cs')
| -rw-r--r-- | Ryujinx.Graphics.Vic/Types/BitfieldExtensions.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Vic/Types/BitfieldExtensions.cs b/Ryujinx.Graphics.Vic/Types/BitfieldExtensions.cs new file mode 100644 index 00000000..06d0f006 --- /dev/null +++ b/Ryujinx.Graphics.Vic/Types/BitfieldExtensions.cs @@ -0,0 +1,39 @@ +using System.Runtime.CompilerServices; + +namespace Ryujinx.Graphics.Vic.Types +{ + static class BitfieldExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool Extract(this int value, int lsb) + { + return ((value >> (lsb & 0x1f)) & 1) != 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Extract(this int value, int lsb, int length) + { + return (value >> (lsb & 0x1f)) & (int)(uint.MaxValue >> (32 - length)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool Extract(this long value, int lsb) + { + return ((int)(value >> (lsb & 0x3f)) & 1) != 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Extract(this long value, int lsb, int length) + { + return (int)(value >> (lsb & 0x3f)) & (int)(uint.MaxValue >> (32 - length)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int ExtractSx(this long value, int lsb, int length) + { + int shift = lsb & 0x3f; + + return (int)((value << (64 - (shift + length))) >> (64 - length)); + } + } +} |
