From 1575f55abee50a563502e5afb098ebed9d5d8995 Mon Sep 17 00:00:00 2001 From: Exverge Date: Tue, 15 Sep 2026 01:14:31 +0200 Subject: [PATCH] [dynarmic] fix sign extension logic on x64 (#4415) - [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- Co-authored-by: lizzie Co-authored-by: lizzie Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4415 Reviewed-by: lizzie Reviewed-by: MaranBr --- .../src/dynarmic/backend/x64/emit_x64_memory.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dynarmic/src/dynarmic/backend/x64/emit_x64_memory.h b/src/dynarmic/src/dynarmic/backend/x64/emit_x64_memory.h index 9686e4fc04..54ad638ada 100644 --- a/src/dynarmic/src/dynarmic/backend/x64/emit_x64_memory.h +++ b/src/dynarmic/src/dynarmic/backend/x64/emit_x64_memory.h @@ -85,8 +85,13 @@ template<> code.mov(tmp, vaddr); code.shr(tmp, int(page_table_const_bits)); - code.shl(tmp, int(ctx.conf.page_table_log2_stride)); - code.mov(page, qword[r14 + tmp.cvt64()]); + + if (ctx.conf.page_table_log2_stride > 3) { + code.shl(tmp, int(ctx.conf.page_table_log2_stride)); + code.mov(page, qword[r14 + tmp.cvt64()]); + } else { + code.mov(page, qword[r14 + tmp.cvt64() * int(ctx.conf.page_table_log2_stride)]); + } // check for marked bit, use as unmapped if marked if (ctx.conf.page_table_marked_bit) { @@ -102,9 +107,10 @@ template<> code.mov(tmp, ctx.conf.page_table_pointer_mask); code.and_(page, tmp); } + // check for sign bit, apply sign extension as needed if (ctx.conf.page_table_sign_extension) { - code.shl(page, *ctx.conf.page_table_sign_extension); - code.sar(page, *ctx.conf.page_table_sign_extension); + code.shl(page, 63 - int(*ctx.conf.page_table_sign_extension)); + code.sar(page, 63 - int(*ctx.conf.page_table_sign_extension)); } code.jz(abort, code.T_NEAR);