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

Support the immediate values for u32 bitwise instructions #1362

Merged
merged 7 commits into from
Jul 2, 2024

Conversation

Fumuran
Copy link
Contributor

@Fumuran Fumuran commented Jun 21, 2024

This PR adds support for the immediate values for u32 bitwise operations: u32and, u32or, u32xor and u32not.

TODO:

  • Update docs
  • Update changelog

@Fumuran Fumuran force-pushed the andrew-imm-values-for-u32-bitwise-instrs branch from 0dc7693 to c0ce2a2 Compare June 25, 2024 20:46
@Fumuran Fumuran force-pushed the andrew-imm-values-for-u32-bitwise-instrs branch from 83ddbfc to 9d3a1c0 Compare June 26, 2024 13:46
@Fumuran
Copy link
Contributor Author

Fumuran commented Jun 26, 2024

It turned out that with our lalrpop parser we can just emulate instructions with immediate values with [Push(imm), ActualInstruction] array, without the need to create new *Imm() versions of instructions (of course only in case we don't need to do some other preparations and calculations for immediate value). The same approach could be applied to the u32 and Felt comparison instructions, so probably I should create an issue to rework them.

@Fumuran Fumuran marked this pull request as ready for review June 26, 2024 13:57
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 couple comments inline (both related to using only u32 values), but also didn't review .lalrpop file in detail. @bitwalker could you take a look at it?

Also, we should update the changelog and documentation.

assembly/src/parser/token.rs Outdated Show resolved Hide resolved
assembly/src/parser/lexer.rs Outdated Show resolved Hide resolved
@Fumuran Fumuran requested a review from bobbinth July 2, 2024 13:53
Copy link
Contributor

@bitwalker bitwalker 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 overall, but I did find one bug in the lexer. Other than that just one suggestion, your call on that one.

Marking this as needing changes, but only due to the lexer bug. Just ping me for review again once its ready and I'll approve ASAP.

loop {
// If we hit a non-binary digit, we're done
let c1 = self.read();
if !c1.is_ascii_hexdigit() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be !is_ascii_binary(c1) no?

}
}

fn is_ascii_binary(c: char) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Mark this #[inline(always)] to ensure that it gets inlined, otherwise it goes from a very cheap comparison operation to a quite expensive function call if it isn't inlined. While Rust may inline functions like this automatically, it is based on a heuristic, and is sensitive to what is happening in the caller, so in cases where you know it is important, it's always worth providing the inline annotation

@Fumuran Fumuran requested a review from bitwalker July 2, 2024 17:42
Copy link
Contributor

@bitwalker bitwalker left a comment

Choose a reason for hiding this comment

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

LGTM

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 one comment inline, also I think #1362 (comment) still needs to be addressed. After these, we can merge.

assembly/src/parser/lexer.rs Outdated Show resolved Hide resolved
@Fumuran Fumuran merged commit ecd26a2 into next Jul 2, 2024
15 checks passed
@Fumuran Fumuran deleted the andrew-imm-values-for-u32-bitwise-instrs branch July 2, 2024 23:31
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