mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 21:30:19 -06:00
Common: Add alignment header
Gets rid of duplicated alignment code.
This commit is contained in:
24
Source/Core/Common/Align.h
Normal file
24
Source/Core/Common/Align.h
Normal file
@ -0,0 +1,24 @@
|
||||
// This file is under the public domain.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Common
|
||||
{
|
||||
template <typename T>
|
||||
constexpr T AlignUp(T value, size_t size)
|
||||
{
|
||||
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
|
||||
return static_cast<T>(value + (size - value % size) % size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr T AlignDown(T value, size_t size)
|
||||
{
|
||||
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
|
||||
return static_cast<T>(value - value % size);
|
||||
}
|
||||
|
||||
} // namespace Common
|
@ -7,10 +7,10 @@
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/Arm64Emitter.h"
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/MathUtil.h"
|
||||
|
||||
namespace Arm64Gen
|
||||
{
|
||||
@ -2079,14 +2079,14 @@ bool ARM64XEmitter::MOVI2R2(ARM64Reg Rd, u64 imm1, u64 imm2)
|
||||
|
||||
void ARM64XEmitter::ABI_PushRegisters(BitSet32 registers)
|
||||
{
|
||||
int num_regs = registers.Count();
|
||||
unsigned int num_regs = registers.Count();
|
||||
|
||||
if (num_regs % 2)
|
||||
{
|
||||
bool first = true;
|
||||
|
||||
// Stack is required to be quad-word aligned.
|
||||
u32 stack_size = ROUND_UP(num_regs * 8, 16);
|
||||
u32 stack_size = Common::AlignUp(num_regs * 8, 16);
|
||||
u32 current_offset = 0;
|
||||
std::vector<ARM64Reg> reg_pair;
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Align.h" />
|
||||
<ClInclude Include="Analytics.h" />
|
||||
<ClInclude Include="Assert.h" />
|
||||
<ClInclude Include="Atomic.h" />
|
||||
@ -211,4 +212,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -18,6 +18,7 @@
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Align.h" />
|
||||
<ClInclude Include="Atomic.h" />
|
||||
<ClInclude Include="Atomic_GCC.h" />
|
||||
<ClInclude Include="Atomic_Win32.h" />
|
||||
@ -293,4 +294,4 @@
|
||||
<ItemGroup>
|
||||
<Natvis Include="BitField.natvis" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -180,9 +180,6 @@ struct Rectangle
|
||||
|
||||
float MathFloatVectorSum(const std::vector<float>&);
|
||||
|
||||
#define ROUND_UP(x, a) (((x) + (a)-1) & ~((a)-1))
|
||||
#define ROUND_DOWN(x, a) ((x) & ~((a)-1))
|
||||
|
||||
// Rounds down. 0 -> undefined
|
||||
inline int IntLog2(u64 val)
|
||||
{
|
||||
|
Reference in New Issue
Block a user