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 left shift or right shift operator #241

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Lynette7
Copy link

@Lynette7 Lynette7 commented Dec 8, 2024

Resolves #181

To implement right-shift and left-shift operators, here are the changes I've made:

  • Added token recognition for << and >> in the lexer
  • Extended Op2 enum to include RightShift and LeftShift
  • Updated the parser to recognize and handle bit shift tokens
  • Modified type checker to support the shift operations
  • Implemented circuit writer logic for bit shifts using field arithmetic
  • Implemented bit shift operations for field elements, supporting constant value shifts and cell variable shifts with constant shift amounts
  • Added bitwise shift operations using logical shift right (Lshr) and shift left (Shl) in circuit IR generation

@katat
Copy link
Collaborator

katat commented Dec 10, 2024

Thanks for addressing this.

I realized this feature can be complicated to support in the constraint level, because the unit in that level is finite field. It makes sense to support logical shifting in finite field, but that can be confusing from user perspective since they might assume they are arithmetic shifting.

Therefore, I think for now we can just make it support in the hint function. That is the feature can be implemented in the ir.rs, which is based on Circ term.

Also please add tests in the examples.

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.

Support << left shift or >> right shift operator
2 participants