2018-11-28 17:18:09 -05:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
|
|
|
{
|
|
|
|
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-04 19:52:39 -05:00
|
|
|
public bool TryCoalesce(int Index, int Size)
|
2018-11-28 17:18:09 -05:00
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
long Mask = ((1L << Size) - 1) << (Index & 63);
|
2018-11-28 17:18:09 -05:00
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
Index /= 64;
|
2018-11-28 17:18:09 -05:00
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
if ((Mask & ~Masks[MaxLevel - 1][Index]) != 0)
|
2018-11-28 17:18:09 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
Masks[MaxLevel - 1][Index] &= ~Mask;
|
2018-11-28 17:18:09 -05:00
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
for (int Level = MaxLevel - 2; Level >= 0; Level--, Index /= 64)
|
2018-11-28 17:18:09 -05:00
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
Masks[Level][Index / 64] &= ~(1L << (Index & 63));
|
2018-11-28 17:18:09 -05:00
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
if (Masks[Level][Index / 64] != 0)
|
2018-11-28 17:18:09 -05:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
FreeCount -= (ulong)Size;
|
2018-11-28 17:18:09 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|