1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

UserspaceEmulator: Convert the XOR instruction to inline assembly

This commit is contained in:
Andreas Kling 2020-07-11 15:55:00 +02:00
parent 9db588daf1
commit 76b9fb258d
2 changed files with 31 additions and 6 deletions

View file

@ -139,12 +139,31 @@ u32 SoftCPU::pop32()
template<typename Destination, typename Source>
static typename TypeDoubler<Destination>::type op_xor(SoftCPU& cpu, const Destination& dest, const Source& src)
{
auto result = dest ^ src;
cpu.set_zf(dest == 0);
cpu.set_sf(dest & 0x80000000);
// FIXME: set_pf
cpu.set_of(false);
cpu.set_cf(false);
Destination result = 0;
u32 new_flags = 0;
if constexpr (sizeof(Destination) == 4) {
asm volatile("xorl %%ecx, %%eax\n"
: "=a"(result)
: "a"(dest), "c"(src));
} else if constexpr (sizeof(Destination) == 2) {
asm volatile("xor %%cx, %%ax\n"
: "=a"(result)
: "a"(dest), "c"(src));
} else if constexpr (sizeof(Destination) == 1) {
asm volatile("xorb %%cl, %%al\n"
: "=a"(result)
: "a"(dest), "c"(src));
} else {
ASSERT_NOT_REACHED();
}
asm volatile(
"pushf\n"
"pop %%ebx"
: "=b"(new_flags));
cpu.set_flags_oszpc(new_flags);
return result;
}