Skip to content

Commit

Permalink
Add assert about aligned addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
aborg-dev committed Feb 1, 2024
1 parent f4fe1a2 commit d7de340
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 210 deletions.
10 changes: 10 additions & 0 deletions cranelift/codegen/src/isa/zkasm/inst/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,11 @@ impl MachInstEmit for Inst {
match from {
AMode::RegOffset(r, ..) => {
debug_assert_eq!(r, e0());
// For simplicity we assume that register address is word-aligned.
// This was the case for Rust-generated code, but might be violated in the
// future.
put_string(&format!("${{ {} % 8 }} => A\n", reg_name(r)), sink);
put_string(&format!("0: ASSERT\n"), sink);
// TODO(#43): Implement the conversion using verifiable computations.
put_string(
&format!(
Expand Down Expand Up @@ -689,6 +694,11 @@ impl MachInstEmit for Inst {
match to {
AMode::RegOffset(r, ..) => {
debug_assert_eq!(r, e0());
// For simplicity we assume that register address is word-aligned.
// This was the case for Rust-generated code, but might be violated in the
// future.
put_string(&format!("${{ {} % 8 }} => A\n", reg_name(r)), sink);
put_string(&format!("0: ASSERT\n"), sink);
// TODO(#43): Implement the conversion using verifiable computations.
put_string(
&format!(
Expand Down
2 changes: 2 additions & 0 deletions cranelift/codegen/src/isa/zkasm/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ fn zkasm_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandC
collector.reg_fixed_use(r, e0());
}
let mut clobbered = PRegSet::empty();
clobbered.add(a0().to_real_reg().unwrap().into());
clobbered.add(d0().to_real_reg().unwrap().into());
collector.reg_clobbers(clobbered);
collector.reg_def(rd);
Expand All @@ -346,6 +347,7 @@ fn zkasm_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandC
collector.reg_fixed_use(r, e0());
}
let mut clobbered = PRegSet::empty();
clobbered.add(a0().to_real_reg().unwrap().into());
clobbered.add(d0().to_real_reg().unwrap().into());
collector.reg_clobbers(clobbered);
collector.reg_late_use(src);
Expand Down
Loading

0 comments on commit d7de340

Please sign in to comment.