From a8b9cd8e65a4d02d4d1ccd550b90936241282278 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Sun, 23 Jun 2024 14:38:06 -0700 Subject: [PATCH] [a64] Implement support for large stack sizes The `SUB` instruction can only encode immediates in the form of `0xFFF` or `0xFFF000`. In the case that the stack size is greater than `0xFFF`, then just align the stack-size by `0x1000` to keep the bottom 12 bits clear. --- src/xenia/cpu/backend/a64/a64_emitter.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/xenia/cpu/backend/a64/a64_emitter.cc b/src/xenia/cpu/backend/a64/a64_emitter.cc index e835f4aff..6ae853ff3 100644 --- a/src/xenia/cpu/backend/a64/a64_emitter.cc +++ b/src/xenia/cpu/backend/a64/a64_emitter.cc @@ -196,7 +196,14 @@ bool A64Emitter::Emit(HIRBuilder* builder, EmitFunctionInfo& func_info) { // IMPORTANT: any changes to the prolog must be kept in sync with // A64CodeCache, which dynamically generates exception information. // Adding or changing anything here must be matched! - const size_t stack_size = StackLayout::GUEST_STACK_SIZE + stack_offset; + size_t stack_size = StackLayout::GUEST_STACK_SIZE + stack_offset; + + // The SUB instruction can only encode immediates withi 0xFFF or 0xFFF000 + // If the stack size is greater than 0xFFF, then just align it to 0x1000 + if (stack_size > 0xFFF) { + stack_size = xe::align(stack_size, static_cast(0x1000)); + } + assert_true(stack_size % 16 == 0); func_info.stack_size = stack_size; stack_size_ = stack_size;