From 08c430dcfb8efb37af34be5eb20bce90e741558f Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Thu, 14 Aug 2025 00:25:23 +0100 Subject: [PATCH 1/2] OpcodeDispatcher: Simplify CALLOp return addr calc --- FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp index 749d76604..1936161be 100644 --- a/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp +++ b/FEXCore/Source/Interface/Core/OpcodeDispatcher.cpp @@ -526,8 +526,7 @@ void OpDispatchBuilder::CALLOp(OpcodeArgs) { // Call instruction only uses up to 32-bit signed displacement int64_t TargetOffset = Op->Src[0].Literal(); - auto NewRIP = GetRelocatedPC(Op, TargetOffset); - auto ConstantPC = Sub(GPRSize, NewRIP, TargetOffset); + auto ConstantPC = GetRelocatedPC(Op); // Push the return address. Push(GPRSize, ConstantPC); From 5c078d13c03a1fa4cce5b51740b3af7c2620a997 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Thu, 14 Aug 2025 15:35:23 +0100 Subject: [PATCH 2/2] Update InstCountCI --- .../FlagM/x87-HalfLife.json | 45 ++++++---------- .../FlagM/x87-Oblivion.json | 54 +++++++------------ .../FlagM/x87-Psychonauts.json | 36 +++++-------- 3 files changed, 45 insertions(+), 90 deletions(-) diff --git a/unittests/InstructionCountCI/FlagM/x87-HalfLife.json b/unittests/InstructionCountCI/FlagM/x87-HalfLife.json index b98f7962d..ba366fb4a 100644 --- a/unittests/InstructionCountCI/FlagM/x87-HalfLife.json +++ b/unittests/InstructionCountCI/FlagM/x87-HalfLife.json @@ -1065,7 +1065,7 @@ }, "Block4": { "x86InstructionCount": 54, - "ExpectedInstructionCount": 78, + "ExpectedInstructionCount": 75, "x86Insts": [ "push ebp", "push edi", @@ -1187,11 +1187,8 @@ "ldr x30, [sp], #16", "fmov d2, d0", "str d2, [x8]", - "mov w20, #0xd100", - "movk w20, #0x7, lsl #16", - "mov w21, #0xd0bc", - "movk w21, #0x6, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x44", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "ldrb w21, [x28, #1019]", "add w21, w21, #0x7 (7)", @@ -1205,7 +1202,7 @@ }, "Block5": { "x86InstructionCount": 49, - "ExpectedInstructionCount": 302, + "ExpectedInstructionCount": 299, "x86Insts": [ "fld dword [esp + 0x80]", "fsub dword [esp + 0x7c]", @@ -1546,11 +1543,8 @@ "str w4, [x8, #8]", "str w6, [x8, #4]", "str w11, [x8]", - "mov w20, #0xb5b0", - "movk w20, #0x3, lsl #16", - "mov w21, #0xb4fe", - "movk w21, #0x2, lsl #16", - "sub w20, w20, w21", + "mov w20, #0xb2", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "ldrb w21, [x28, #1019]", "add w21, w21, #0x5 (5)", @@ -2202,7 +2196,7 @@ }, "Block8": { "x86InstructionCount": 25, - "ExpectedInstructionCount": 172, + "ExpectedInstructionCount": 169, "x86Insts": [ "fstp st0", "fstp st3", @@ -2397,17 +2391,14 @@ "add w20, w20, #0x1 (1)", "and w20, w20, #0x7", "strb w20, [x28, #1019]", - "mov w20, #0xd0d8", - "movk w20, #0x7, lsl #16", - "mov w21, #0xd0b4", - "movk w21, #0x6, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x24", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!" ] }, "Block9": { "x86InstructionCount": 25, - "ExpectedInstructionCount": 172, + "ExpectedInstructionCount": 169, "x86Insts": [ "fstp st0", "fstp st3", @@ -2602,17 +2593,14 @@ "add w20, w20, #0x1 (1)", "and w20, w20, #0x7", "strb w20, [x28, #1019]", - "mov w20, #0xd0d8", - "movk w20, #0x7, lsl #16", - "mov w21, #0xd0b4", - "movk w21, #0x6, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x24", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!" ] }, "Block10": { "x86InstructionCount": 125, - "ExpectedInstructionCount": 20, + "ExpectedInstructionCount": 17, "x86Insts": [ "push esi", "push ebx", @@ -2755,11 +2743,8 @@ "add w20, w6, w20", "ldr w4, [x20]", "str w4, [x8]", - "mov w20, #0x9090", - "movk w20, #0x2, lsl #16", - "mov w21, #0x9060", - "movk w21, #0x1, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x30", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!" ] } diff --git a/unittests/InstructionCountCI/FlagM/x87-Oblivion.json b/unittests/InstructionCountCI/FlagM/x87-Oblivion.json index 52e3cf6ba..fdefe3a45 100644 --- a/unittests/InstructionCountCI/FlagM/x87-Oblivion.json +++ b/unittests/InstructionCountCI/FlagM/x87-Oblivion.json @@ -13639,7 +13639,7 @@ }, "Block3": { "x86InstructionCount": 649, - "ExpectedInstructionCount": 3427, + "ExpectedInstructionCount": 3424, "x86Insts": [ "fld dword [esi + 0x64]", "mov eax,dword [esi + 0x88]", @@ -17705,11 +17705,8 @@ "ldr w5, [x8, #124]", "add w7, w8, #0x190 (400)", "str w5, [x8, #232]", - "mov w20, #0xdf30", - "movk w20, #0x71, lsl #16", - "mov w21, #0xd4f1", - "movk w21, #0x70, lsl #16", - "sub w20, w20, w21", + "mov w20, #0xa3f", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "ldrb w21, [x28, #1019]", "add w21, w21, #0x1 (1)", @@ -17723,7 +17720,7 @@ }, "Block4": { "x86InstructionCount": 2050, - "ExpectedInstructionCount": 39, + "ExpectedInstructionCount": 36, "x86Insts": [ "fldz", "push 0x0", @@ -19802,11 +19799,8 @@ "mov w20, #0x4157", "movk w20, #0x5242, lsl #16", "str w20, [x8, #-4]!", - "mov w20, #0x7220", - "movk w20, #0x42, lsl #16", - "mov w21, #0x71fe", - "movk w21, #0x41, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x22", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "ldrb w21, [x28, #1019]", "add w21, w21, #0x7 (7)", @@ -19820,7 +19814,7 @@ }, "Block5": { "x86InstructionCount": 368, - "ExpectedInstructionCount": 131, + "ExpectedInstructionCount": 128, "x86Insts": [ "mov ebx,dword [eax + 0x68]", "fld dword [esi + 0x2c]", @@ -20309,11 +20303,8 @@ "str s2, [x8, #56]", "ldr s2, [x8, #56]", "str s2, [x8]", - "mov w20, #0xeb0", - "movk w20, #0x42, lsl #16", - "mov w21, #0xe52", - "movk w21, #0x41, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x5e", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "ldrb w21, [x28, #1019]", "add w21, w21, #0x6 (6)", @@ -20327,7 +20318,7 @@ }, "Block6": { "x86InstructionCount": 315, - "ExpectedInstructionCount": 35, + "ExpectedInstructionCount": 32, "x86Insts": [ "mov eax,dword [esp + 0x110]", "fldz", @@ -20667,11 +20658,8 @@ "ldr x30, [sp], #16", "fmov s2, s0", "str s2, [x8]", - "mov w20, #0x4370", - "movk w20, #0x79, lsl #16", - "mov w21, #0x433f", - "movk w21, #0x78, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x31", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "ldrb w21, [x28, #1019]", "add w21, w21, #0x7 (7)", @@ -26212,7 +26200,7 @@ }, "Block9": { "x86InstructionCount": 260, - "ExpectedInstructionCount": 83, + "ExpectedInstructionCount": 80, "x86Insts": [ "fld dword [edi]", "fmul st0", @@ -26542,11 +26530,8 @@ "blr x0", "ldr x30, [sp], #16", "mov v2.16b, v0.16b", - "mov w20, #0x2c30", - "movk w20, #0x99, lsl #16", - "mov w21, #0x2c11", - "movk w21, #0x98, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x1f", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "ldrb w21, [x28, #1019]", "sub w21, w21, #0x1 (1)", @@ -26563,7 +26548,7 @@ }, "Block10": { "x86InstructionCount": 206, - "ExpectedInstructionCount": 228, + "ExpectedInstructionCount": 225, "x86Insts": [ "fld dword [0x00b42a74]", "push ecx", @@ -26995,11 +26980,8 @@ "add w20, w20, #0x1 (1)", "and w20, w20, #0x7", "strb w20, [x28, #1019]", - "mov w20, #0x3aa0", - "movk w20, #0x7a, lsl #16", - "mov w21, #0x39db", - "movk w21, #0x79, lsl #16", - "sub w20, w20, w21", + "mov w20, #0xc5", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!" ] } diff --git a/unittests/InstructionCountCI/FlagM/x87-Psychonauts.json b/unittests/InstructionCountCI/FlagM/x87-Psychonauts.json index eb4553de9..16ece1e86 100644 --- a/unittests/InstructionCountCI/FlagM/x87-Psychonauts.json +++ b/unittests/InstructionCountCI/FlagM/x87-Psychonauts.json @@ -9486,7 +9486,7 @@ }, "Block3": { "x86InstructionCount": 702, - "ExpectedInstructionCount": 95, + "ExpectedInstructionCount": 92, "x86Insts": [ "mov eax,dword [ebp + 0xffffff44]", "mov ecx,dword [eax + 0x4]", @@ -10280,11 +10280,8 @@ "stur w4, [x9, #-92]", "sub w4, w9, #0xfc (252)", "str w4, [x8]", - "mov w20, #0xba1a", - "movk w20, #0x81a, lsl #16", - "mov w21, #0xb8da", - "movk w21, #0x819, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x140", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "cfinv" ] @@ -21483,7 +21480,7 @@ }, "Block6": { "x86InstructionCount": 409, - "ExpectedInstructionCount": 2207, + "ExpectedInstructionCount": 2204, "x86Insts": [ "mov eax,dword [ebp + 0x10]", "fld dword [eax + 0x30]", @@ -24096,18 +24093,15 @@ "fmov s2, s0", "str s2, [x8, #4]", "str w6, [x8]", - "mov w20, #0xd57a", - "movk w20, #0x819, lsl #16", - "mov w21, #0xd118", - "movk w21, #0x818, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x462", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "strb wzr, [x28, #1186]" ] }, "Block7": { "x86InstructionCount": 418, - "ExpectedInstructionCount": 2214, + "ExpectedInstructionCount": 2211, "x86Insts": [ "push ebp", "mov ebp,esp", @@ -26736,11 +26730,8 @@ "fmov s2, s0", "str s2, [x8, #4]", "str w6, [x8]", - "mov w20, #0xd57a", - "movk w20, #0x819, lsl #16", - "mov w21, #0xd10b", - "movk w21, #0x818, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x46f", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "strb wzr, [x28, #1186]" ] @@ -34584,7 +34575,7 @@ }, "Block10": { "x86InstructionCount": 420, - "ExpectedInstructionCount": 1957, + "ExpectedInstructionCount": 1954, "x86Insts": [ "push ebp", "mov ebp,esp", @@ -36950,11 +36941,8 @@ "str s2, [x4]", "ldr w4, [x9, #8]", "str w4, [x8]", - "mov w20, #0xde98", - "movk w20, #0x817, lsl #16", - "mov w21, #0xda1c", - "movk w21, #0x816, lsl #16", - "sub w20, w20, w21", + "mov w20, #0x47c", + "movk w20, #0x1, lsl #16", "str w20, [x8, #-4]!", "cfinv", "ldrb w21, [x28, #1019]",