Skip to content
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

Use longer integers to fill ZKASM data section #187

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cranelift/filetests/src/test_zkasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod tests {
chunk_data <<= 8;
chunk_data |= *c as u64;
}
program.push(format!(" {chunk_data} :MSTORE(MEM:E + {i})"));
program.push(format!(" {chunk_data}n :MSTORE(MEM:E + {i})"));
}
}

Expand Down
55 changes: 26 additions & 29 deletions cranelift/zkasm_data/benchmarks/fibonacci/generated/from_rust.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,75 @@ start:
function_1:
SP + 1 => SP
RR :MSTORE(SP - 1)
SP + 5 => SP
SP + 4 => SP
C :MSTORE(SP - 1)
D :MSTORE(SP - 2)
E :MSTORE(SP - 3)
B :MSTORE(SP - 4)
1n => A ;; LoadConst64
0n => B ;; LoadConst64
10000n => C ;; LoadConst32
C => D
Comment on lines -14 to -22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does register allocation become smarter if this zkasm file has no data segment? Naively thinking, shouldn't this zkasm remain unchanged as the code path that was modified isn't hit? For fibonacci/from_rust the length of data_segments is zero in generate_preamble(..., data_segments), so the loop that emits {chunk_data}n ... isn't entered.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also find this surprising and have seen this non-stable behavior by the codegen quite a few times. I've filed an issue to investigate it in more detail #190.

Unfortunately, we can't submit the change in this PR without the diff to the generated zkasm files as our tests require the snapshots to match. We should think how to handle this case in the new testing infrastructure. CC @MCJOHN974

:JMP(label_1_1)
label_1_1:
$ => B :ADD
A => C
A => D
B => A
C => B
D => B
$ => B :ADD
A => C
A => D
B => A
C => B
D => B
$ => B :ADD
A => C
A => D
B => A
C => B
D => B
$ => B :ADD
A => C
A => D
B => A
C => B
D => B
$ => B :ADD
A => C
A => D
B => A
C => B
D => B
$ => B :ADD
A => C
A => D
B => A
C => B
D => B
$ => B :ADD
A => C
A => D
B => A
C => B
D => B
$ => B :ADD
A => C
A => D
B => A
C => B
D => B
$ => B :ADD
A => C
A => D
B => A
C => B
D => B
$ => E :ADD
A :MSTORE(SP)
A => D
4294967286n => B ;; LoadConst32
D => A
C => A
$ => A :ADD
4294967295n => B ;; LoadConst64
$ => A :AND
A => C
A => D
C :JMPNZ(label_1_2)
A :JMPNZ(label_1_2)
:JMP(label_1_3)
label_1_2:
C => D
$ => B :MLOAD(SP)
D => B
A => C
E => A
:JMP(label_1_1)
label_1_3:
15574651946073070043n => B ;; LoadConst64
$ => A :MLOAD(SP)
D => A
B :ASSERT
$ => C :MLOAD(SP - 1)
$ => D :MLOAD(SP - 2)
$ => E :MLOAD(SP - 3)
$ => B :MLOAD(SP - 4)
SP - 5 => SP
SP - 4 => SP
$ => RR :MLOAD(SP - 1)
SP - 1 => SP
:JMP(RR)
Expand Down
2 changes: 1 addition & 1 deletion cranelift/zkasm_data/benchmarks/fibonacci/state.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Test,Status,Cycles
from_rust,pass,50026
from_rust,pass,48025
handwritten,pass,50008
handwritten_wat,pass,140023
Loading