feat: differentiate between signed and unsigned multiplication

- Split `BinaryOp::Mul` into `BinaryOp::SMul` and `BinaryOp::UMul` in
the IR.
- Implement x86_64 codegen for `UMul` using the `mulq` instruction.
- Update `X86Backend` to use `imulq` specifically for `SMul`.
- Update constant folding and IR printer to support the new
multiplication operations.
- Optimize function epilogue by omitting the final `jmp` on fallthrough.
- Update `main` test case to use `build_umul`.
This commit is contained in:
2026-04-27 13:36:17 +02:00
parent 5b8a0cb398
commit 6f6c84eac4
6 changed files with 39 additions and 12 deletions
+2 -1
View File
@@ -146,7 +146,8 @@ fn evaluate_binary(op: BinaryOp, src1: &Operand, src2: &Operand) -> Option<Opera
match op {
BinaryOp::Add => Some(Operand::Integer(a.wrapping_add(b))),
BinaryOp::Sub => Some(Operand::Integer(a.wrapping_sub(b))),
BinaryOp::Mul => Some(Operand::Integer(a.wrapping_mul(b))),
BinaryOp::SMul => Some(Operand::Integer((a as i64).wrapping_mul(b as i64) as u64)),
BinaryOp::UMul => Some(Operand::Integer(a.wrapping_mul(b))),
BinaryOp::UDiv => {
if b != 0 {
Some(Operand::Integer(a.wrapping_div(b)))