Skip to content

Commit 6beb4b0

Browse files
Merge pull request #4533 from Sonicadvance1/align_tail_in_the_pale_moonlight
JIT: Align JITCodeTail to native alignment
2 parents 23a8462 + 735f537 commit 6beb4b0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CodeEmitter/CodeEmitter/Buffer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class Buffer {
4747
CurrentOffset += StringLength;
4848
}
4949

50-
void Align() {
51-
// Align the buffer to instruction size
52-
auto CurrentAlignment = reinterpret_cast<uint64_t>(CurrentOffset) & 0b11;
50+
void Align(size_t Size = 4) {
51+
// Align the buffer to provided size.
52+
auto CurrentAlignment = reinterpret_cast<uint64_t>(CurrentOffset) & (Size - 1);
5353
if (!CurrentAlignment) {
5454
return;
5555
}
56-
CurrentOffset += 4 - CurrentAlignment;
56+
CurrentOffset += Size - CurrentAlignment;
5757
}
5858

5959
template<typename T>

FEXCore/Source/Interface/Core/JIT/JIT.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ CPUBackend::CompiledCode Arm64JITCore::CompileCode(uint64_t Entry, uint64_t Size
867867
const uint64_t CodeOnlySize = GetCursorAddress<uint8_t*>() - CodeData.BlockBegin;
868868

869869
// Add the JitCodeTail
870+
Align(alignof(JITCodeTail));
870871
auto JITBlockTailLocation = GetCursorAddress<uint8_t*>();
871872
auto JITBlockTail = GetCursorAddress<JITCodeTail*>();
872873
CursorIncrement(sizeof(JITCodeTail));

0 commit comments

Comments
 (0)