Skip to content

Commit

Permalink
Misc: Align CPU state and SPU voices to cache lines
Browse files Browse the repository at this point in the history
Fixes the ~12% performance regression from the texture replacement
namespace'ify commit. Apparently LTO was placing the CPU struct in the
middle of a cache line...
  • Loading branch information
stenzek committed Jul 6, 2024
1 parent d021a61 commit 77488db
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ static constexpr u32 HOST_CACHE_LINE_SIZE = 128; // Apple Silicon uses 128b cach
#else
static constexpr u32 HOST_CACHE_LINE_SIZE = 64; // Everything else is 64b.
#endif
#define ALIGN_TO_CACHE_LINE alignas(HOST_CACHE_LINE_SIZE)

// Enum class bitwise operators
#define IMPLEMENT_ENUM_CLASS_BITWISE_OPERATORS(type_) \
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static bool WriteMemoryByte(VirtualMemoryAddress addr, u32 value);
static bool WriteMemoryHalfWord(VirtualMemoryAddress addr, u32 value);
static bool WriteMemoryWord(VirtualMemoryAddress addr, u32 value);

State g_state;
alignas(HOST_CACHE_LINE_SIZE) State g_state;
bool TRACE_EXECUTION = false;

static fastjmp_buf s_jmp_buf;
Expand Down
2 changes: 1 addition & 1 deletion src/core/cpu_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct State
static constexpr u32 GTERegisterOffset(u32 index) { return OFFSETOF(State, gte_regs.r32) + (sizeof(u32) * index); }
};

extern State g_state;
ALIGN_TO_CACHE_LINE extern State g_state;

void Initialize();
void Shutdown();
Expand Down
2 changes: 1 addition & 1 deletion src/core/spu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ static std::array<std::array<s16, 128>, 2> s_reverb_downsample_buffer;
static std::array<std::array<s16, 64>, 2> s_reverb_upsample_buffer;
static s32 s_reverb_resample_buffer_position = 0;

static std::array<Voice, NUM_VOICES> s_voices{};
ALIGN_TO_CACHE_LINE static std::array<Voice, NUM_VOICES> s_voices{};

static InlineFIFOQueue<u16, FIFO_SIZE_IN_HALFWORDS> s_transfer_fifo;

Expand Down

0 comments on commit 77488db

Please sign in to comment.