BitfieldExtensions.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Runtime.CompilerServices;
  2. namespace Ryujinx.Graphics.Vic.Types
  3. {
  4. static class BitfieldExtensions
  5. {
  6. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  7. public static bool Extract(this int value, int lsb)
  8. {
  9. return ((value >> (lsb & 0x1f)) & 1) != 0;
  10. }
  11. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  12. public static int Extract(this int value, int lsb, int length)
  13. {
  14. return (value >> (lsb & 0x1f)) & (int)(uint.MaxValue >> (32 - length));
  15. }
  16. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  17. public static bool Extract(this long value, int lsb)
  18. {
  19. return ((int)(value >> (lsb & 0x3f)) & 1) != 0;
  20. }
  21. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  22. public static int Extract(this long value, int lsb, int length)
  23. {
  24. return (int)(value >> (lsb & 0x3f)) & (int)(uint.MaxValue >> (32 - length));
  25. }
  26. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  27. public static int ExtractSx(this long value, int lsb, int length)
  28. {
  29. int shift = lsb & 0x3f;
  30. return (int)((value << (64 - (shift + length))) >> (64 - length));
  31. }
  32. }
  33. }