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

Introduce Emit instruction #1496

Merged
merged 4 commits into from
Sep 18, 2024
Merged

Introduce Emit instruction #1496

merged 4 commits into from
Sep 18, 2024

Conversation

plafer
Copy link
Contributor

@plafer plafer commented Sep 13, 2024

Implements step 1 of #1457

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left a few small comments inline.

Comment on lines 112 to 115
pub const OPCODE_EMIT: u8 = 0b0101_1010;

pub const OPCODE_MRUPDATE: u8 = 0b0110_0000;
pub const OPCODE_PUSH: u8 = 0b0110_0100;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless it causes some complications, I'd probably still move the PUSH opcode to be immediately after the EMIT opcode (e.g., be 0b0101_1011). Not only would this lower the degree of $f_{imm}$ flag, but it would also mean that we can save one operation when computing $f_{imm}$ (i.e., we'd get it naturally in the process of computing PUSH/EMIT flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved PUSH to 0b0101_1011.

this lower the degree of $f_{imm}$ flag,

The degree doesn't change though right? Since now both f_emit and f_push are degree 5.

Copy link
Collaborator

@Al-Kindi-0 Al-Kindi-0 Sep 18, 2024

Choose a reason for hiding this comment

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

I think by virtue of having a common prefix and differing only in the first bit, the flags when added together will cause the last bit to cancel out, something like $x * b_0 + x * (1 - b_0) = x$. This is also what happens for SPLIT and LOOP.
One thing that I just remembered, reductions in degree like these (or sometimes even more complex) can cause the constraint evaluation logic related to flags to result in the wrong evaluations. This happened a while back and took some time to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup that makes sense, very interesting. $f_{imm}$ is now set to degree 4

@plafer plafer force-pushed the plafer-1457-emit-instr branch 2 times, most recently from 6ca48d9 to 0701221 Compare September 16, 2024 21:01
@plafer plafer marked this pull request as ready for review September 16, 2024 21:02
@plafer plafer requested a review from bobbinth September 16, 2024 21:02
@plafer plafer force-pushed the plafer-1457-emit-instr branch from 0701221 to 44e69f5 Compare September 16, 2024 21:04
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left some more comments inline.

Also, one thing I think we are missing is the description, as well as the implementation, of the actual constraints for the EMIT operation. The implementation would probably go somewhere here and the documentation would go somewhere here.

Comment on lines 427 to 430
> $$
sp \cdot \Delta gc \cdot (1 - f_{push})\cdot h_0 = 0 \text{ | degree} = 7
sp \cdot \Delta gc \cdot (1 - f_{imm})\cdot h_0 = 0 \text{ | degree} = 8
$$
Copy link
Contributor

Choose a reason for hiding this comment

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

If we change the PUSH opcode as described in #1496 (comment), the degree here would remain the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As commented above, I believe this remains the same, since f_imm is still degree 5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Brought back to degree 7

@plafer plafer force-pushed the plafer-1457-emit-instr branch 2 times, most recently from 45ce154 to 25b8a5c Compare September 17, 2024 18:53
@plafer plafer requested a review from bobbinth September 17, 2024 21:15
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left a few comments inline - but they are all pretty small (most are doc-related).

Copy link
Collaborator

@Al-Kindi-0 Al-Kindi-0 left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you!

@@ -158,6 +161,40 @@ fn nested_blocks() -> Result<(), Report> {
Ok(())
}

/// Ensures that the arguments of `emit` does indeed modify the digest of a basic block
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: does -> do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@plafer plafer force-pushed the plafer-1457-emit-instr branch from e18b8bf to 0e2d4c4 Compare September 18, 2024 15:17
@plafer plafer requested a review from bobbinth September 18, 2024 15:17
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

All looks good! Thank you!

@plafer plafer merged commit 080597b into next Sep 18, 2024
9 checks passed
@plafer plafer deleted the plafer-1457-emit-instr branch September 18, 2024 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants