From a9f92e5d75199f042dbd8afe4cedfcdc95de2e56 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 13 Jul 2020 13:11:06 +0200 Subject: [PATCH] UserspaceEmulator: Remove an unnecessary step in some instructions We don't need to move the result of shifts around like this, we can just use inline assembly outputs to make it end up in the right place. --- DevTools/UserspaceEmulator/SoftCPU.cpp | 78 +++++++++++++++----------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/DevTools/UserspaceEmulator/SoftCPU.cpp b/DevTools/UserspaceEmulator/SoftCPU.cpp index 67c715f29f..cb967970a6 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -472,20 +472,24 @@ static T op_shr(SoftCPU& cpu, T data, u8 steps) u32 result = 0; u32 new_flags = 0; - if constexpr (sizeof(T) == 4) - asm volatile("shrl %%cl, %%eax\n" ::"a"(data), "c"(steps)); - else if constexpr (sizeof(T) == 2) - asm volatile("shrw %%cl, %%ax\n" ::"a"(data), "c"(steps)); - else if constexpr (sizeof(T) == 1) - asm volatile("shrb %%cl, %%al\n" ::"a"(data), "c"(steps)); + if constexpr (sizeof(T) == 4) { + asm volatile("shrl %%cl, %%eax\n" + : "=a"(result) + : "a"(data), "c"(steps)); + } else if constexpr (sizeof(T) == 2) { + asm volatile("shrw %%cl, %%ax\n" + : "=a"(result) + : "a"(data), "c"(steps)); + } else if constexpr (sizeof(T) == 1) { + asm volatile("shrb %%cl, %%al\n" + : "=a"(result) + : "a"(data), "c"(steps)); + } - asm volatile( - "mov %%eax, %%ebx\n" - : "=b"(result)); asm volatile( "pushf\n" - "pop %%eax" - : "=a"(new_flags)); + "pop %%ebx" + : "=b"(new_flags)); cpu.set_flags_oszapc(new_flags); return result; @@ -500,20 +504,24 @@ static T op_shl(SoftCPU& cpu, T data, u8 steps) u32 result = 0; u32 new_flags = 0; - if constexpr (sizeof(T) == 4) - asm volatile("shll %%cl, %%eax\n" ::"a"(data), "c"(steps)); - else if constexpr (sizeof(T) == 2) - asm volatile("shlw %%cl, %%ax\n" ::"a"(data), "c"(steps)); - else if constexpr (sizeof(T) == 1) - asm volatile("shlb %%cl, %%al\n" ::"a"(data), "c"(steps)); + if constexpr (sizeof(T) == 4) { + asm volatile("shll %%cl, %%eax\n" + : "=a"(result) + : "a"(data), "c"(steps)); + } else if constexpr (sizeof(T) == 2) { + asm volatile("shlw %%cl, %%ax\n" + : "=a"(result) + : "a"(data), "c"(steps)); + } else if constexpr (sizeof(T) == 1) { + asm volatile("shlb %%cl, %%al\n" + : "=a"(result) + : "a"(data), "c"(steps)); + } - asm volatile( - "mov %%eax, %%ebx\n" - : "=b"(result)); asm volatile( "pushf\n" - "pop %%eax" - : "=a"(new_flags)); + "pop %%ebx" + : "=b"(new_flags)); cpu.set_flags_oszapc(new_flags); return result; @@ -1355,20 +1363,24 @@ static T op_sar(SoftCPU& cpu, T data, u8 steps) u32 result = 0; u32 new_flags = 0; - if constexpr (sizeof(T) == 4) - asm volatile("sarl %%cl, %%eax\n" ::"a"(data), "c"(steps)); - else if constexpr (sizeof(T) == 2) - asm volatile("sarw %%cl, %%ax\n" ::"a"(data), "c"(steps)); - else if constexpr (sizeof(T) == 1) - asm volatile("sarb %%cl, %%al\n" ::"a"(data), "c"(steps)); + if constexpr (sizeof(T) == 4) { + asm volatile("sarl %%cl, %%eax\n" + : "=a"(result) + : "a"(data), "c"(steps)); + } else if constexpr (sizeof(T) == 2) { + asm volatile("sarw %%cl, %%ax\n" + : "=a"(result) + : "a"(data), "c"(steps)); + } else if constexpr (sizeof(T) == 1) { + asm volatile("sarb %%cl, %%al\n" + : "=a"(result) + : "a"(data), "c"(steps)); + } - asm volatile( - "mov %%eax, %%ebx\n" - : "=b"(result)); asm volatile( "pushf\n" - "pop %%eax" - : "=a"(new_flags)); + "pop %%ebx" + : "=b"(new_flags)); cpu.set_flags_oszapc(new_flags); return result;