Skip to content

Commit

Permalink
Implement slot conversion in ISLE
Browse files Browse the repository at this point in the history
  • Loading branch information
aborg-dev committed Jan 26, 2024
1 parent 0b18571 commit 7e6d50e
Show file tree
Hide file tree
Showing 6 changed files with 2,486 additions and 2,472 deletions.
3 changes: 2 additions & 1 deletion cranelift/codegen/src/isa/zkasm/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,8 @@

;; In the simplest case we just lower into a Reg+Offset
(rule 0 (amode_inner r @ (value_type (ty_addr64 _)) offset ty)
(gen_reg_offset_amode r offset ty))
(let ((slot XReg (zk_divu r (imm $I32 8))))
(gen_reg_offset_amode slot offset ty)))

;; If the value is a `get_frame_pointer`, we can just use the offset from that.
(rule 1 (amode_inner (get_frame_pointer) offset ty)
Expand Down
32 changes: 11 additions & 21 deletions cranelift/codegen/src/isa/zkasm/inst/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,25 +591,18 @@ impl MachInstEmit for Inst {
match from {
AMode::RegOffset(r, ..) => {
let rem = offset % 8;
let slot_offset = offset / 8;
let width = op.width() as i64;
if rem + width > 8 {
put_string(&format!(";; FIXME Read spans two slots\n"), sink);
}

debug_assert_eq!(r, e0());
put_string(
&format!(
"${{ ({}) / 8 }} => {}\n",
access_reg_with_offset(r, offset),
reg_name(r)
),
sink,
);
put_string(
&format!(
"$ => {} :MLOAD(MEM:{})\n",
reg_name(rd.to_reg()),
reg_name(r)
access_reg_with_offset(r, slot_offset),
),
sink,
);
Expand Down Expand Up @@ -666,20 +659,17 @@ impl MachInstEmit for Inst {
match to {
AMode::RegOffset(r, ..) => {
debug_assert_eq!(r, e0());
put_string(
&format!(
"${{ ({}) / 8 }} => {}\n",
access_reg_with_offset(r, offset),
reg_name(r)
),
sink,
);
let rem = offset % 8;
let slot_offset = offset / 8;
let width = op.width() as i64;

if op == StoreOP::I64 && rem == 0 {
put_string(
&format!("{} :MSTORE(MEM:{})\n", reg_name(src), reg_name(r)),
&format!(
"{} :MSTORE(MEM:{})\n",
reg_name(src),
access_reg_with_offset(r, slot_offset)
),
sink,
);
return;
Expand Down Expand Up @@ -713,7 +703,7 @@ impl MachInstEmit for Inst {
8 * rem,
reg_name(src),
8 * rem,
reg_name(r),
access_reg_with_offset(r, slot_offset)
),
sink,
);
Expand All @@ -724,7 +714,7 @@ impl MachInstEmit for Inst {
&format!(
"$ => {} :MLOAD(MEM:{})\n",
reg_name(d0()),
access_reg_with_offset(r, 1)
access_reg_with_offset(r, slot_offset + 1)
),
sink,
);
Expand All @@ -734,7 +724,7 @@ impl MachInstEmit for Inst {
8 * rem,
reg_name(src),
8 * rem,
access_reg_with_offset(r, 1),
access_reg_with_offset(r, slot_offset + 1)
),
sink,
);
Expand Down
Loading

0 comments on commit 7e6d50e

Please sign in to comment.