Skip to content

Commit

Permalink
Fix division ASM
Browse files Browse the repository at this point in the history
  • Loading branch information
benruijl committed Aug 13, 2024
1 parent 8cdce1b commit e7d4af1
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions src/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1595,57 +1595,75 @@ impl<T: std::fmt::Display> ExpressionEvaluator<T> {
match o {
MemOrReg::Reg(out_reg) => {
if *b == MemOrReg::Reg(*out_reg) {
if let Some(tmp_reg) =
(0..16).position(|k| free & (1 << k) != 0)
{
*out += &format!(
"\t\t\"movapd xmm{}, xmm{}\\n\\t\"\n",
tmp_reg, out_reg
);

*out += &format!(
"\t\t\"movsd xmm{}, QWORD PTR[%1+{}]\\n\\t\"\n",
out_reg,
(self.reserved_indices - self.param_count) * 8,
);

*out += &format!(
"\t\t\"divsd xmm{}, xmm{}\\n\\t\"\n",
out_reg, tmp_reg,
);
} else {
panic!("No free registers for division")
}
} else {
*out += &format!(
"\t\t\"divsd xmm{}, QWORD PTR[%1+{}]\\n\\t\"\n",
"\t\t\"movsd xmm{}, QWORD PTR[%1+{}]\\n\\t\"\n",
out_reg,
(self.reserved_indices - self.param_count) * 8,
);
} else {

match b {
MemOrReg::Reg(j) => {
*out += &format!(
"\t\t\"movapd xmm{}, xmm{}\\n\\t\"\n",
"\t\t\"divsd xmm{}, xmm{}\\n\\t\"\n",
out_reg, j
);
}
MemOrReg::Mem(k) => {
*out += &format!(
"\t\t\"movsd xmm{}, QWORD {}\\n\\t\"\n",
"\t\t\"divsd xmm{}, QWORD {}\\n\\t\"\n",
out_reg,
format_addr!(*k)
);
}
}

*out += &format!(
"\t\t\"divsd xmm{}, QWORD PTR[%1+{}]\\n\\t\"\n",
out_reg,
(self.reserved_indices - self.param_count) * 8,
);
}
}
MemOrReg::Mem(out_mem) => {
if let Some(out_reg) = (0..16).position(|k| free & (1 << k) != 0) {
if let MemOrReg::Reg(j) = b {
*out += &format!(
"\t\t\"movapd xmm{}, xmm{}\\n\\t\"\n",
out_reg, j
);
} else {
if let MemOrReg::Mem(k) = b {
*out += &format!(
"\t\t\"movsd xmm{}, QWORD PTR[%1+{}]\\n\\t\"\n",
out_reg,
(self.reserved_indices - self.param_count) * 8,
);

match b {
MemOrReg::Reg(j) => {
*out += &format!(
"\t\t\"divsd xmm{}, xmm{}\\n\\t\"\n",
out_reg, j
);
}
MemOrReg::Mem(k) => {
*out += &format!(
"\t\t\"movsd xmm{}, QWORD {}\\n\\t\"\n",
"\t\t\"divsd xmm{}, QWORD {}\\n\\t\"\n",
out_reg,
format_addr!(*k)
);
}
}

*out += &format!(
"\t\t\"divsd xmm{}, QWORD PTR[%1+{}]\\n\\t\"\n",
out_reg,
(self.reserved_indices - self.param_count) * 8,
);
*out += &format!(
"\t\t\"movsd QWORD {}, xmm{}\\n\\t\"\n",
format_addr!(*out_mem),
Expand Down

0 comments on commit e7d4af1

Please sign in to comment.