Skip to content

Commit

Permalink
zkasm: i64.const
Browse files Browse the repository at this point in the history
  • Loading branch information
MCJOHN974 committed Nov 1, 2023
1 parent 20945d9 commit fb4d6b7
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cranelift/codegen/src/isa/zkasm/inst/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl MachInstEmit for Inst {
}
&Inst::LoadConst64 { rd, imm } => {
let rd = allocs.next_writable(rd);
put_string(&format!("{imm} => {}\n", reg_name(rd.to_reg())), sink);
put_string(&format!("{imm}n => {}\n", reg_name(rd.to_reg())), sink);
}
&Inst::Unwind { ref inst } => {
put_string(&format!("Unwind\n"), sink);
Expand Down
4 changes: 3 additions & 1 deletion cranelift/codegen/src/isa/zkasm/lower/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ impl generated_code::Context for ZkAsmIsleContext<'_, '_, MInst, ZkAsmBackend> {
let insts = match ty {
F32 => MInst::load_fp_constant32(tmp, val as u32, alloc_tmp),
F64 => MInst::load_fp_constant64(tmp, val, alloc_tmp),
_ => MInst::load_constant_u64(tmp, val, alloc_tmp),
I32 => MInst::load_constant_u32(tmp, val, alloc_tmp),
I64 => MInst::load_constant_u64(tmp, val, alloc_tmp),
_ => panic!("Not implemented"),
};
self.emit_list(&insts);
tmp.to_reg()
Expand Down
2 changes: 2 additions & 0 deletions cranelift/filetests/src/test_zkasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,7 @@ mod tests {
ne,
nop,
_should_fail_unreachable,
i32_const,
i64_const,
}
}
20 changes: 20 additions & 0 deletions cranelift/zkasm_data/generated/i32_const.zkasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
start:
zkPC + 2 => RR
:JMP(function_1)
:JMP(finalizeExecution)
function_1:
SP + 1 => SP
RR :MSTORE(SP - 1)
SP + 2 => SP
B :MSTORE(SP - 1)
4 => A
4 => B
B :ASSERT
$ => B :MLOAD(SP - 1)
SP - 2 => SP
$ => RR :MLOAD(SP - 1)
SP - 1 => SP
:JMP(RR)
finalizeExecution:
${beforeLast()} :JMPN(finalizeExecution)
:JMP(start)
20 changes: 20 additions & 0 deletions cranelift/zkasm_data/generated/i64_const.zkasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
start:
zkPC + 2 => RR
:JMP(function_1)
:JMP(finalizeExecution)
function_1:
SP + 1 => SP
RR :MSTORE(SP - 1)
SP + 2 => SP
B :MSTORE(SP - 1)
9223372036854775807n => A
9223372036854775807n => B
B :ASSERT
$ => B :MLOAD(SP - 1)
SP - 2 => SP
$ => RR :MLOAD(SP - 1)
SP - 1 => SP
:JMP(RR)
finalizeExecution:
${beforeLast()} :JMPN(finalizeExecution)
:JMP(start)
7 changes: 7 additions & 0 deletions cranelift/zkasm_data/i32_const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(module
(import "env" "assert_eq" (func $assert_eq (param i32) (param i32)))
(func $main
i32.const 4
i32.const 4
call $assert_eq)
(start $main))
7 changes: 7 additions & 0 deletions cranelift/zkasm_data/i64_const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(module
(import "env" "assert_eq" (func $assert_eq (param i64) (param i64)))
(func $main
i64.const 9223372036854775807
i64.const 9223372036854775807
call $assert_eq)
(start $main))

0 comments on commit fb4d6b7

Please sign in to comment.