KMemoryRegionBlock.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. namespace Ryujinx.HLE.HOS.Kernel
  2. {
  3. class KMemoryRegionBlock
  4. {
  5. public long[][] Masks;
  6. public ulong FreeCount;
  7. public int MaxLevel;
  8. public ulong StartAligned;
  9. public ulong SizeInBlocksTruncated;
  10. public ulong SizeInBlocksRounded;
  11. public int Order;
  12. public int NextOrder;
  13. public bool TryCoalesce(int Index, int Size)
  14. {
  15. long Mask = ((1L << Size) - 1) << (Index & 63);
  16. Index /= 64;
  17. if ((Mask & ~Masks[MaxLevel - 1][Index]) != 0)
  18. {
  19. return false;
  20. }
  21. Masks[MaxLevel - 1][Index] &= ~Mask;
  22. for (int Level = MaxLevel - 2; Level >= 0; Level--, Index /= 64)
  23. {
  24. Masks[Level][Index / 64] &= ~(1L << (Index & 63));
  25. if (Masks[Level][Index / 64] != 0)
  26. {
  27. break;
  28. }
  29. }
  30. FreeCount -= (ulong)Size;
  31. return true;
  32. }
  33. }
  34. }