mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
UserspaceEmulator: Convert the SUB instruction to inline assembly
This commit is contained in:
parent
7d41b95071
commit
9db588daf1
1 changed files with 25 additions and 5 deletions
|
@ -151,11 +151,31 @@ static typename TypeDoubler<Destination>::type op_xor(SoftCPU& cpu, const Destin
|
||||||
template<typename Destination, typename Source>
|
template<typename Destination, typename Source>
|
||||||
static typename TypeDoubler<Destination>::type op_sub(SoftCPU& cpu, const Destination& dest, const Source& src)
|
static typename TypeDoubler<Destination>::type op_sub(SoftCPU& cpu, const Destination& dest, const Source& src)
|
||||||
{
|
{
|
||||||
u64 result = (u64)dest - (u64)src;
|
Destination result = 0;
|
||||||
cpu.set_zf(result == 0);
|
u32 new_flags = 0;
|
||||||
cpu.set_sf((result >> (X86::TypeTrivia<Destination>::bits - 1) & 1));
|
|
||||||
cpu.set_af((((result ^ (src ^ dest)) & 0x10) >> 4) & 1);
|
if constexpr (sizeof(Destination) == 4) {
|
||||||
cpu.set_of((((result ^ dest) & (src ^ dest)) >> (X86::TypeTrivia<Destination>::bits - 1)) & 1);
|
asm volatile("subl %%ecx, %%eax\n"
|
||||||
|
: "=a"(result)
|
||||||
|
: "a"(dest), "c"(src));
|
||||||
|
} else if constexpr (sizeof(Destination) == 2) {
|
||||||
|
asm volatile("subw %%cx, %%ax\n"
|
||||||
|
: "=a"(result)
|
||||||
|
: "a"(dest), "c"(src));
|
||||||
|
} else if constexpr (sizeof(Destination) == 1) {
|
||||||
|
asm volatile("subb %%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_oszap(new_flags);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue