From 133803b8a75304803a5816c7e7e42d7b71ec84dd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 11 Jul 2020 13:43:27 +0200 Subject: UserspaceEmulator: Split SAR inline assembly into 8/16/32 bit variants --- DevTools/UserspaceEmulator/SoftCPU.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/DevTools/UserspaceEmulator/SoftCPU.cpp b/DevTools/UserspaceEmulator/SoftCPU.cpp index f650401241..c7462b5d86 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.cpp +++ b/DevTools/UserspaceEmulator/SoftCPU.cpp @@ -702,12 +702,21 @@ T SoftCPU::sar_impl(T data, u8 steps) u32 result = 0; u32 new_flags = 0; - asm("sarl %%cl, %%eax\n" + + 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)); + + asm volatile( "mov %%eax, %%ebx\n" + : "=b"(result)); + asm volatile( "pushf\n" - "pop %%eax\n" - : "=a"(new_flags), "=b"(result) - : "a"(data), "c"(steps)); + "pop %%eax" + : "=a"(new_flags)); set_flags_oszapc(new_flags); return result; -- cgit v1.2.3