-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mul for Imm32 #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,6 +429,7 @@ impl Inst { | |
| Inst::LoadConst64 { .. } | ||
| Inst::AluRRR { .. } | ||
| Inst::AddImm32 { .. } | ||
| Inst::MulImm32 { .. } | ||
| Inst::FpuRRR { .. } | ||
| Inst::AluRRImm12 { .. } | ||
| Inst::Load { .. } | ||
|
@@ -668,6 +669,14 @@ impl MachInstEmit for Inst { | |
sink, | ||
); | ||
} | ||
&Inst::MulImm32 { rd, src1, src2 } => { | ||
let rd = allocs.next(rd.to_reg()); | ||
// TODO(akashin): Should we have a function for `bits` field? | ||
put_string( | ||
&format!("{} * {} => {}\n", src1.bits, src2.bits, reg_name(rd)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed on Monday, we suspect that this only works for a subset of Imm32 values when the overflow does not happen. (module
(import "env" "assert_eq" (func $assert_eq (param i32) (param i32)))
(func $main
i32.const 131072 ;; 2^17
i32.const 131073 ;; 2^17 + 1
i32.mul ;; This will overflow and wrap.
i32.const 131072 ;; ((2^17 + 1) * 2^17) % 2^32 = 2^17
call $assert_eq)
(start $main)) This will allow us to later validate that the correct implementation handles this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't implement it fast so will create another PR for other multiplications |
||
sink, | ||
); | ||
} | ||
&Inst::AluRRR { | ||
alu_op, | ||
rd, | ||
|
@@ -742,6 +751,7 @@ impl MachInstEmit for Inst { | |
sink, | ||
); | ||
} | ||
|
||
_ => unreachable!("Op {:?} is not implemented", alu_op), | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, looks like ZK ASM does not have
MUL
operation and we instead would encode this with a combination of call to external environment to do the multiplication and anARITH
instruction to verify the computation as done here: https://github.com/0xPolygonHermez/zkevm-rom/blob/23189df42b058f9a5a0dacbb90b073460816071d/main/utils.zkasm#L638So I suggest we revert this particular change (args.rs file) for now as it doesn't have any effect and do a separate PR that does general (non-Immediate) multiplication using
ARITH
by specializing the implementation of&Inst::AluRRR
for Mul operation.