Skip to content

Commit

Permalink
Merge pull request #196 from near/heap_offset
Browse files Browse the repository at this point in the history
Add ISLE rule for heap offset symbol
  • Loading branch information
aborg-dev authored Jan 26, 2024
2 parents 9dc141e + fe4edfb commit ca0d6dc
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 134 deletions.
11 changes: 1 addition & 10 deletions cranelift/codegen/src/isa/zkasm/inst/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,16 +1475,7 @@ impl MachInstEmit for Inst {
ref name,
offset,
} => {
// TODO(akashin): Replace this with a more general logic when we have more than
// one external constant.
let rd = allocs.next_writable(rd);
put_string(
&format!(
"{offset} => {} ;; LoadExtName({name:?})\n",
reg_name(rd.to_reg())
),
sink,
);
unimplemented!("LoadExtName: {name:?}");
}
&Inst::TrapIfC {
rs1,
Expand Down
5 changes: 3 additions & 2 deletions cranelift/codegen/src/isa/zkasm/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@
(load_ext_name name 0))

;;;;; Rules for `symbol_value`;;;;;;;;;
;; Heap starts at offset 0 in zkAsm machine memory.
(rule
(lower (symbol_value (symbol_value_data name _ offset)))
(load_ext_name name offset))
(lower (symbol_value (zkasm_base ZkasmBase.Heap)))
(imm $I32 0))

;;;;; Rules for `bitcast`;;;;;;;;;
(rule
Expand Down
4 changes: 4 additions & 0 deletions cranelift/codegen/src/isa/zkasm/lower/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ impl generated_code::Context for ZkAsmIsleContext<'_, '_, MInst, ZkAsmBackend> {
match name {
ExternalName::User(user_name_ref) => {
// All ZKASM "memory"-like accesses use this name, but different offsets.
// This is our convention as is not related to the actual offsets in zkAsm
// machine memory that will be used by each base.
// These offsets need to be aligned with the offsets used in
// `cranelift_wasm::environ::zkasm::ZkasmFuncEnvironment`.
if user_name_ref.index() != 0 {
return None;
}
Expand Down
Loading

0 comments on commit ca0d6dc

Please sign in to comment.