aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHunter <102537986+HunterBarney@users.noreply.github.com>2022-12-26 09:11:05 -0500
committerGitHub <noreply@github.com>2022-12-26 14:11:05 +0000
commitc963b3c80488f88c9d7f44588b6ba45051af3e2d (patch)
tree3f18132ba47306a65b13690216a61323113da962
parenta4fdfb5f94121f5c60fc5717175fd21f3e774e85 (diff)
Added Generic Math to BitUtils (#3929)1.1.491
* Generic Math Update Updated Several functions in Ryujinx.Common/Utilities/BitUtils to use generic math * Updated BitUtil calls * Removed Whitespace * Switched decrement * Fixed changed method calls. The method calls were originally changed on accident due to me relying too much on intellisense doing stuff for me * Update Ryujinx.Common/Utilities/BitUtils.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> Co-authored-by: gdkchan <gab.dark.100@gmail.com>
-rw-r--r--Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs4
-rw-r--r--Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs8
-rw-r--r--Ryujinx.Common/Utilities/BitUtils.cs74
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs2
-rw-r--r--Ryujinx.Graphics.Gpu/Memory/BufferManager.cs4
-rw-r--r--Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs4
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs10
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs2
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs8
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs4
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs2
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs46
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs4
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs4
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs4
-rw-r--r--Ryujinx.HLE/HOS/ProgramLoader.cs6
-rw-r--r--Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs2
-rw-r--r--Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs2
18 files changed, 67 insertions, 123 deletions
diff --git a/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs b/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs
index 922ce4e3..f35dbec7 100644
--- a/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs
+++ b/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs
@@ -23,7 +23,7 @@ namespace Ryujinx.Audio.Renderer.Common
if (size != 0)
{
- ulong alignedOffset = BitUtils.AlignUp(Offset, align);
+ ulong alignedOffset = BitUtils.AlignUp<ulong>(Offset, (ulong)align);
if (alignedOffset + size <= (ulong)BackingMemory.Length)
{
@@ -55,7 +55,7 @@ namespace Ryujinx.Audio.Renderer.Common
public static ulong GetTargetSize<T>(ulong currentSize, ulong count, int align) where T : unmanaged
{
- return BitUtils.AlignUp(currentSize, align) + (ulong)Unsafe.SizeOf<T>() * count;
+ return BitUtils.AlignUp<ulong>(currentSize, (ulong)align) + (ulong)Unsafe.SizeOf<T>() * count;
}
}
} \ No newline at end of file
diff --git a/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs b/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs
index 5116f7ca..53570243 100644
--- a/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs
+++ b/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs
@@ -167,7 +167,7 @@ namespace Ryujinx.Audio.Renderer.Server
return ResultCode.WorkBufferTooSmall;
}
- _depopBuffer = workBufferAllocator.Allocate<float>((ulong)BitUtils.AlignUp(parameter.MixBufferCount, Constants.BufferAlignment), Constants.BufferAlignment);
+ _depopBuffer = workBufferAllocator.Allocate<float>(BitUtils.AlignUp<ulong>(parameter.MixBufferCount, Constants.BufferAlignment), Constants.BufferAlignment);
if (_depopBuffer.IsEmpty)
{
@@ -772,7 +772,7 @@ namespace Ryujinx.Audio.Renderer.Server
size = WorkBufferAllocator.GetTargetSize<float>(size, Constants.TargetSampleCount * (Constants.VoiceChannelCountMax + parameter.MixBufferCount) * (parameter.SinkCount + parameter.SubMixBufferCount), 0x10);
// Depop buffer
- size = WorkBufferAllocator.GetTargetSize<float>(size, (ulong)BitUtils.AlignUp(parameter.MixBufferCount, Constants.BufferAlignment), Constants.BufferAlignment);
+ size = WorkBufferAllocator.GetTargetSize<float>(size, BitUtils.AlignUp<ulong>(parameter.MixBufferCount, Constants.BufferAlignment), Constants.BufferAlignment);
// Voice
size = WorkBufferAllocator.GetTargetSize<VoiceState>(size, parameter.VoiceCount, VoiceState.Alignment);
@@ -804,10 +804,10 @@ namespace Ryujinx.Audio.Renderer.Server
{
ulong performanceMetricsPerFramesSize = PerformanceManager.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter, ref behaviourContext) * (parameter.PerformanceMetricFramesCount + 1) + 0xC;
- size += BitUtils.AlignUp(performanceMetricsPerFramesSize, Constants.PerformanceMetricsPerFramesSizeAlignment);
+ size += BitUtils.AlignUp<ulong>(performanceMetricsPerFramesSize, Constants.PerformanceMetricsPerFramesSizeAlignment);
}
- return BitUtils.AlignUp(size, Constants.WorkBufferAlignment);
+ return BitUtils.AlignUp<ulong>(size, Constants.WorkBufferAlignment);
}
public ResultCode QuerySystemEvent(out IWritableEvent systemEvent)
diff --git a/Ryujinx.Common/Utilities/BitUtils.cs b/Ryujinx.Common/Utilities/BitUtils.cs
index a42e2cc7..f885ce84 100644
--- a/Ryujinx.Common/Utilities/BitUtils.cs
+++ b/Ryujinx.Common/Utilities/BitUtils.cs
@@ -1,82 +1,26 @@
+using System;
using System.Numerics;
namespace Ryujinx.Common
{
public static class BitUtils
{
- public static uint AlignUp(uint value, int size)
+ public static T AlignUp<T>(T value, T size)
+ where T : IBinaryInteger<T>
{
- return (uint)AlignUp((int)value, size);
+ return (value + (size - T.One)) & -size;
}
- public static int AlignUp(int value, int size)
- {
- return (value + (size - 1)) & -size;
- }
-
- public static ulong AlignUp(ulong value, int size)
- {
- return (ulong)AlignUp((long)value, size);
- }
-
- public static long AlignUp(long value, int size)
- {
- return AlignUp(value, (long)size);
- }
-
- public static ulong AlignUp(ulong value, ulong size)
- {
- return (ulong)AlignUp((long)value, (long)size);
- }
-
- public static long AlignUp(long value, long size)
- {
- return (value + (size - 1)) & -size;
- }
-
- public static uint AlignDown(uint value, int size)
- {
- return (uint)AlignDown((int)value, size);
- }
-
- public static int AlignDown(int value, int size)
+ public static T AlignDown<T>(T value, T size)
+ where T : IBinaryInteger<T>
{
return value & -size;
}
- public static ulong AlignDown(ulong value, int size)
- {
- return (ulong)AlignDown((long)value, size);
- }
-
- public static long AlignDown(long value, int size)
- {
- return AlignDown(value, (long)size);
- }
-
- public static ulong AlignDown(ulong value, ulong size)
- {
- return (ulong)AlignDown((long)value, (long)size);
- }
-
- public static long AlignDown(long value, long size)
- {
- return value & -size;
- }
-
- public static int DivRoundUp(int value, int dividend)
- {
- return (value + dividend - 1) / dividend;
- }
-
- public static ulong DivRoundUp(ulong value, uint dividend)
- {
- return (value + dividend - 1) / dividend;
- }
-
- public static long DivRoundUp(long value, int dividend)
+ public static T DivRoundUp<T>(T value, T dividend)
+ where T : IBinaryInteger<T>
{
- return (value + dividend - 1) / dividend;
+ return (value + (dividend - T.One)) / dividend;
}
public static int Pow2RoundUp(int value)
diff --git a/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs b/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs
index 6120d295..f6effe2e 100644
--- a/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs
@@ -100,7 +100,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory
_isLinear = (argument & 1) != 0;
_offset = 0;
- _size = (int)(BitUtils.AlignUp(state.LineLengthIn, 4) * state.LineCount);
+ _size = (int)(BitUtils.AlignUp<uint>(state.LineLengthIn, 4) * state.LineCount);
int count = _size / 4;
diff --git a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs
index 1728cdb5..e20e1bb6 100644
--- a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs
+++ b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs
@@ -252,7 +252,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
RecordStorageAlignment(_cpStorageBuffers, index, gpuVa);
- gpuVa = BitUtils.AlignDown(gpuVa, _context.Capabilities.StorageBufferOffsetAlignment);
+ gpuVa = BitUtils.AlignDown<ulong>(gpuVa, (ulong)_context.Capabilities.StorageBufferOffsetAlignment);
ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size);
@@ -276,7 +276,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
RecordStorageAlignment(buffers, index, gpuVa);
- gpuVa = BitUtils.AlignDown(gpuVa, _context.Capabilities.StorageBufferOffsetAlignment);
+ gpuVa = BitUtils.AlignDown<ulong>(gpuVa, (ulong)_context.Capabilities.StorageBufferOffsetAlignment);
ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size);
diff --git a/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs b/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs
index 66d339b8..dc3eb598 100644
--- a/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs
+++ b/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs
@@ -53,7 +53,7 @@ namespace Ryujinx.Graphics.Vulkan
{
var range = _freeRanges[i];
- ulong alignedOffset = BitUtils.AlignUp(range.Offset, (int)alignment);
+ ulong alignedOffset = BitUtils.AlignUp<ulong>(range.Offset, alignment);
ulong sizeDelta = alignedOffset - range.Offset;
ulong usableSize = range.Size - sizeDelta;
@@ -196,7 +196,7 @@ namespace Ryujinx.Graphics.Vulkan
}
}
- ulong blockAlignedSize = BitUtils.AlignUp(size, _blockAlignment);
+ ulong blockAlignedSize = BitUtils.AlignUp<ulong>(size, (ulong)_blockAlignment);
var memoryAllocateInfo = new MemoryAllocateInfo()
{
diff --git a/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs b/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs
index a4e7f589..5726299b 100644
--- a/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Ipc/KBufferDescriptorTable.cs
@@ -81,8 +81,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
attributeMask |= MemoryAttribute.DeviceMapped;
}
- ulong clientAddrTruncated = BitUtils.AlignDown(desc.ClientAddress, KPageTableBase.PageSize);
- ulong clientAddrRounded = BitUtils.AlignUp (desc.ClientAddress, KPageTableBase.PageSize);
+ ulong clientAddrTruncated = BitUtils.AlignDown<ulong>(desc.ClientAddress, KPageTableBase.PageSize);
+ ulong clientAddrRounded = BitUtils.AlignUp<ulong>(desc.ClientAddress, KPageTableBase.PageSize);
// Check if address is not aligned, in this case we need to perform 2 copies.
if (clientAddrTruncated != clientAddrRounded)
@@ -113,9 +113,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
ulong clientEndAddr = desc.ClientAddress + desc.Size;
ulong serverEndAddr = desc.ServerAddress + desc.Size;
- ulong clientEndAddrTruncated = BitUtils.AlignDown(clientEndAddr, KPageTableBase.PageSize);
- ulong clientEndAddrRounded = BitUtils.AlignUp (clientEndAddr, KPageTableBase.PageSize);
- ulong serverEndAddrTruncated = BitUtils.AlignDown(serverEndAddr, KPageTableBase.PageSize);
+ ulong clientEndAddrTruncated = BitUtils.AlignDown<ulong>(clientEndAddr, (ulong)KPageTableBase.PageSize);
+ ulong clientEndAddrRounded = BitUtils.AlignUp<ulong>(clientEndAddr, KPageTableBase.PageSize);
+ ulong serverEndAddrTruncated = BitUtils.AlignDown<ulong>(serverEndAddr, (ulong)KPageTableBase.PageSize);
if (clientEndAddrTruncated < clientEndAddrRounded &&
(clientAddrTruncated == clientAddrRounded || clientAddrTruncated < clientEndAddrTruncated))
diff --git a/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs b/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs
index dc5ad717..199e78dc 100644
--- a/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Ipc/KServerSession.cs
@@ -1005,7 +1005,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
recvListEndAddr = recvListBaseAddr + size;
}
- recvListBufferAddress = BitUtils.AlignUp(recvListBaseAddr + dstOffset, 0x10);
+ recvListBufferAddress = BitUtils.AlignUp<ulong>(recvListBaseAddr + dstOffset, 0x10);
ulong endAddress = recvListBufferAddress + descriptor.BufferSize;
diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs
index 2df93d78..05cf4a4f 100644
--- a/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Memory/KCodeMemory.cs
@@ -44,7 +44,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
public KernelResult Map(ulong address, ulong size, KMemoryPermission perm)
{
- if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize))
+ if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, (ulong)KPageTableBase.PageSize))
{
return KernelResult.InvalidSize;
}
@@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
public KernelResult MapToOwner(ulong address, ulong size, KMemoryPermission permission)
{
- if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize))
+ if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, (ulong)KPageTableBase.PageSize))
{
return KernelResult.InvalidSize;
}
@@ -102,7 +102,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
public KernelResult Unmap(ulong address, ulong size)
{
- if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize))
+ if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, (ulong)KPageTableBase.PageSize))
{
return KernelResult.InvalidSize;
}
@@ -128,7 +128,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
public KernelResult UnmapFromOwner(ulong address, ulong size)
{
- if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize))
+ if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, KPageTableBase.PageSize))
{
return KernelResult.InvalidSize;
}
diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs
index 0568325a..fa090b02 100644
--- a/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Memory/KPageBitmap.cs
@@ -101,7 +101,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
for (int depth = HighestDepthIndex; depth >= 0; depth--)
{
_bitStorages[depth] = storage;
- size = BitUtils.DivRoundUp(size, UInt64BitSize);
+ size = BitUtils.DivRoundUp<ulong>(size, (ulong)UInt64BitSize);
storage = storage.Slice((int)size);
}
@@ -288,7 +288,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
for (int depth = GetRequiredDepth(regionSize) - 1; depth >= 0; depth--)
{
- regionSize = BitUtils.DivRoundUp(regionSize, UInt64BitSize);
+ regionSize = BitUtils.DivRoundUp<ulong>(regionSize, UInt64BitSize);
overheadBits += (int)regionSize;
}
diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs
index 39ecfdea..c3586ed7 100644
--- a/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Memory/KPageHeap.cs
@@ -48,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
int diff = 1 << (NextShift - Shift);
- offset = BitUtils.AlignDown(offset, diff);
+ offset = BitUtils.AlignDown(offset, (ulong)diff);
if (_bitmap.ClearRange(offset, diff))
{
diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs
index 501d1cc4..2c94cba2 100644
--- a/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs
@@ -203,8 +203,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
heapRegion.Size = 0x180000000;
stackRegion.Size = 0x80000000;
tlsIoRegion.Size = 0x1000000000;
- CodeRegionStart = BitUtils.AlignDown(address, 0x200000);
- codeRegionSize = BitUtils.AlignUp(endAddr, 0x200000) - CodeRegionStart;
+ CodeRegionStart = BitUtils.AlignDown<ulong>(address, 0x200000);
+ codeRegionSize = BitUtils.AlignUp<ulong>(endAddr, 0x200000) - CodeRegionStart;
stackAndTlsIoStart = 0;
stackAndTlsIoEnd = 0;
baseAddress = 0x8000000;
@@ -1584,8 +1584,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.OutOfResource;
}
- ulong srcMapAddress = BitUtils.AlignUp(src, PageSize);
- ulong srcMapEndAddr = BitUtils.AlignDown(src + size, PageSize);
+ ulong srcMapAddress = BitUtils.AlignUp<ulong>(src, PageSize);
+ ulong srcMapEndAddr = BitUtils.AlignDown<ulong>(src + size, PageSize);
ulong srcMapSize = srcMapEndAddr - srcMapAddress;
result = MapPagesFromClientProcess(size, src, permission, state, srcPageTable, send, out ulong va);
@@ -1659,10 +1659,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
attributeMask |= MemoryAttribute.DeviceMapped;
}
- ulong addressRounded = BitUtils.AlignUp(address, PageSize);
- ulong addressTruncated = BitUtils.AlignDown(address, PageSize);
- ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize);
- ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize);
+ ulong addressRounded = BitUtils.AlignUp<ulong>(address, PageSize);
+ ulong addressTruncated = BitUtils.AlignDown<ulong>(address, PageSize);
+ ulong endAddrRounded = BitUtils.AlignUp<ulong>(endAddr, PageSize);
+ ulong endAddrTruncated = BitUtils.AlignDown<ulong>(endAddr, PageSize);
if (!_slabManager.CanAllocate(MaxBlocksNeededForInsertion))
{
@@ -1769,10 +1769,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong endAddr = address + size;
- ulong addressTruncated = BitUtils.AlignDown(address, PageSize);
- ulong addressRounded = BitUtils.AlignUp(address, PageSize);
- ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize);
- ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize);
+ ulong addressTruncated = BitUtils.AlignDown<ulong>(address, PageSize);
+ ulong addressRounded = BitUtils.AlignUp<ulong>(address, PageSize);
+ ulong endAddrTruncated = BitUtils.AlignDown<ulong>(endAddr, PageSize);
+ ulong endAddrRounded = BitUtils.AlignUp<ulong>(endAddr, PageSize);
ulong neededSize = endAddrRounded - addressTruncated;
@@ -1983,10 +1983,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.OutOfResource;
}
- ulong addressTruncated = BitUtils.AlignDown(address, PageSize);
- ulong addressRounded = BitUtils.AlignUp(address, PageSize);
- ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize);
- ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize);
+ ulong addressTruncated = BitUtils.AlignDown<ulong>(address, PageSize);
+ ulong addressRounded = BitUtils.AlignUp<ulong>(address, PageSize);
+ ulong endAddrTruncated = BitUtils.AlignDown<ulong>(endAddr, PageSize);
+ ulong endAddrRounded = BitUtils.AlignUp<ulong>(endAddr, PageSize);
ulong pagesCount = (endAddrRounded - addressTruncated) / PageSize;
@@ -2010,10 +2010,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
ulong endAddr = address + size;
- ulong addressRounded = BitUtils.AlignUp(address, PageSize);
- ulong addressTruncated = BitUtils.AlignDown(address, PageSize);
- ulong endAddrRounded = BitUtils.AlignUp(endAddr, PageSize);
- ulong endAddrTruncated = BitUtils.AlignDown(endAddr, PageSize);
+ ulong addressRounded = BitUtils.AlignUp<ulong>(address, PageSize);
+ ulong addressTruncated = BitUtils.AlignDown<ulong>(address, PageSize);
+ ulong endAddrRounded = BitUtils.AlignUp<ulong>(endAddr, PageSize);
+ ulong endAddrTruncated = BitUtils.AlignDown<ulong>(endAddr, PageSize);
ulong pagesCount = addressRounded < endAddrTruncated ? (endAddrTruncated - addressRounded) / PageSize : 0;
@@ -2540,7 +2540,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
for (int attempt = 0; attempt < 8; attempt++)
{
- ulong aslrAddress = BitUtils.AlignDown(regionStart + GetRandomValue(0, aslrMaxOffset) * (ulong)alignment, alignment);
+ ulong aslrAddress = BitUtils.AlignDown(regionStart + GetRandomValue(0, aslrMaxOffset) * (ulong)alignment, (ulong)alignment);
ulong aslrEndAddr = aslrAddress + totalNeededSize;
KMemoryInfo info = _blockManager.FindBlock(aslrAddress).GetInfo();
@@ -2618,7 +2618,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
currBaseAddr += reservedSize;
- ulong address = BitUtils.AlignDown(currBaseAddr, alignment) + reservedStart;
+ ulong address = BitUtils.AlignDown<ulong>(currBaseAddr, (ulong)alignment) + reservedStart;
if (currBaseAddr > address)
{
@@ -2834,7 +2834,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
lock (_blockManager)
{
- return BitUtils.DivRoundUp(GetMmUsedSize(), PageSize);
+ return BitUtils.DivRoundUp<ulong>(GetMmUsedSize(), PageSize);
}
}
diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs
index 3711b9df..3af62750 100644
--- a/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs
@@ -33,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
KProcess process,
KMemoryPermission permission)
{
- if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize))
+ if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, KPageTableBase.PageSize))
{
return KernelResult.InvalidSize;
}
@@ -52,7 +52,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
public KernelResult UnmapFromProcess(KPageTableBase memoryManager, ulong address, ulong size, KProcess process)
{
- if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize))
+ if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, KPageTableBase.PageSize))
{
return KernelResult.InvalidSize;
}
diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs
index 107f04c9..2888efb8 100644
--- a/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Memory/KTransferMemory.cs
@@ -67,7 +67,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
KProcess process,
KMemoryPermission permission)
{
- if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize))
+ if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, KPageTableBase.PageSize))
{
return KernelResult.InvalidSize;
}
@@ -95,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong size,
KProcess process)
{
- if (_pageList.GetPagesCount() != BitUtils.DivRoundUp(size, KPageTableBase.PageSize))
+ if (_pageList.GetPagesCount() != BitUtils.DivRoundUp<ulong>(size, (ulong)KPageTableBase.PageSize))
{
return KernelResult.InvalidSize;
}
diff --git a/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs b/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs
index 4c95821c..6a2d45ea 100644
--- a/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs
@@ -472,7 +472,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public KernelResult FreeThreadLocalStorage(ulong tlsSlotAddr)
{
- ulong tlsPageAddr = BitUtils.AlignDown(tlsSlotAddr, KPageTableBase.PageSize);
+ ulong tlsPageAddr = BitUtils.AlignDown<ulong>(tlsSlotAddr, KPageTableBase.PageSize);
KernelContext.CriticalSection.Enter();
@@ -554,7 +554,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
throw new InvalidOperationException("Trying to start a process with a invalid state!");
}
- ulong stackSizeRounded = BitUtils.AlignUp(stackSize, KPageTableBase.PageSize);
+ ulong stackSizeRounded = BitUtils.AlignUp<ulong>(stackSize, KPageTableBase.PageSize);
ulong neededSize = stackSizeRounded + _imageSize;
diff --git a/Ryujinx.HLE/HOS/ProgramLoader.cs b/Ryujinx.HLE/HOS/ProgramLoader.cs
index 66fa20fa..beeb5ad6 100644
--- a/Ryujinx.HLE/HOS/ProgramLoader.cs
+++ b/Ryujinx.HLE/HOS/ProgramLoader.cs
@@ -47,7 +47,7 @@ namespace Ryujinx.HLE.HOS
endOffset = kip.BssOffset + kip.BssSize;
}
- uint codeSize = BitUtils.AlignUp(kip.TextOffset + endOffset, KPageTableBase.PageSize);
+ uint codeSize = BitUtils.AlignUp<uint>(kip.TextOffset + endOffset, KPageTableBase.PageSize);
int codePagesCount = (int)(codeSize / KPageTableBase.PageSize);
@@ -195,7 +195,7 @@ namespace Ryujinx.HLE.HOS
nsoSize = dataEnd;
}
- nsoSize = BitUtils.AlignUp(nsoSize, KPageTableBase.PageSize);
+ nsoSize = BitUtils.AlignUp<uint>(nsoSize, KPageTableBase.PageSize);
nsoBase[index] = codeStart + (ulong)codeSize;
@@ -349,7 +349,7 @@ namespace Ryujinx.HLE.HOS
return KernelResult.Success;
}
- size = BitUtils.AlignUp(size, KPageTableBase.PageSize);
+ size = BitUtils.AlignUp<ulong>(size, KPageTableBase.PageSize);
return process.MemoryManager.SetProcessMemoryPermission(address, size, permission);
}
diff --git a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs
index a111d5d6..36e1078f 100644
--- a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs
+++ b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs
@@ -321,7 +321,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro
ulong bssStart = dataStart + (ulong)relocatableObject.Data.Length;
- ulong bssEnd = BitUtils.AlignUp(bssStart + (ulong)relocatableObject.BssSize, KPageTableBase.PageSize);
+ ulong bssEnd = BitUtils.AlignUp<ulong>(bssStart + relocatableObject.BssSize, KPageTableBase.PageSize);
process.CpuMemory.Write(textStart, relocatableObject.Text);
process.CpuMemory.Write(roStart, relocatableObject.Ro);
diff --git a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs
index fbe38c08..19b22157 100644
--- a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs
+++ b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs
@@ -36,7 +36,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
{
uint headerSize = (uint)Unsafe.SizeOf<ParcelHeader>();
- _rawData = new byte[BitUtils.AlignUp(headerSize + payloadSize + objectsSize, 4)];
+ _rawData = new byte[BitUtils.AlignUp<uint>(headerSize + payloadSize + objectsSize, 4)];
Header.PayloadSize = payloadSize;
Header.ObjectsSize = objectsSize;