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