sign extend rax into rbx before calling idiv, the replaces the rbx zeroing

This commit is contained in:
2020-03-05 17:13:19 +01:00
parent 09eec634b1
commit 1530dc6c55

View File

@@ -357,7 +357,7 @@ public class GenASM implements Visitor<Void> {
if (isFloatOperation) {
this.ex.write(" divsd %xmm1, %xmm0\n");
} else {
this.ex.write(" xor %rdx, %rdx\n"); // clear upper part of division
this.ex.write(" cqto\n"); // sign extend rax into rdx since we're dealing with signed values
this.ex.write(" idiv %rbx\n"); // %rax/%rbx, quotient now in %rax
}
return null;
@@ -370,7 +370,7 @@ public class GenASM implements Visitor<Void> {
e.rhs.welcome(this);
this.ex.write(" movq %rax, %rbx\n");
this.ex.write(" popq %rax\n");
this.ex.write(" xor %rdx, %rdx\n"); // clear upper part of division
this.ex.write(" cqto\n"); // sign extend rax into rdx since we're dealing with signed values
this.ex.write(" idiv %rbx\n"); // %rax/%rbx, remainder now in %rdx
this.ex.write(" movq %rdx, %rax\n");
return null;