diff --git a/src/xenia/cpu/backend/x64/x64_emitter.cc b/src/xenia/cpu/backend/x64/x64_emitter.cc index df5c1b40d..5262d0a4f 100644 --- a/src/xenia/cpu/backend/x64/x64_emitter.cc +++ b/src/xenia/cpu/backend/x64/x64_emitter.cc @@ -231,7 +231,13 @@ bool X64Emitter::Emit(HIRBuilder* builder, EmitFunctionInfo& func_info) { locals_page_delta_ = 0; } - assert_true((stack_size + 8) % 16 == 0); + // Ensure that after we SUB the stack_size, RSP is 16-byte aligned. + // On function entry, RSP is misaligned by 8 (due to CALL pushing return + // address). So we need stack_size to be 8 mod 16, not 0 mod 16. + if ((stack_size % 16) == 0) { + stack_size += 8; // Make it 8 mod 16 + } + assert_true((stack_size % 16) == 8); // Should be 8 mod 16 for alignment func_info.stack_size = stack_size; stack_size_ = stack_size;