2018-12-18 05:33:36 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Memory
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
|
|
|
class KMemoryRegionBlock
|
|
|
|
{
|
|
|
|
public long[][] Masks;
|
|
|
|
|
|
|
|
public ulong FreeCount;
|
|
|
|
public int MaxLevel;
|
|
|
|
public ulong StartAligned;
|
|
|
|
public ulong SizeInBlocksTruncated;
|
|
|
|
public ulong SizeInBlocksRounded;
|
|
|
|
public int Order;
|
|
|
|
public int NextOrder;
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public bool TryCoalesce(int index, int size)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
long mask = ((1L << size) - 1) << (index & 63);
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
index /= 64;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
if ((mask & ~Masks[MaxLevel - 1][index]) != 0)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
Masks[MaxLevel - 1][index] &= ~mask;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
for (int level = MaxLevel - 2; level >= 0; level--, index /= 64)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
Masks[level][index / 64] &= ~(1L << (index & 63));
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
if (Masks[level][index / 64] != 0)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
FreeCount -= (ulong)size;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|