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 #181

Open
katat opened this issue Sep 10, 2024 · 0 comments · May be fixed by #241
Open

Support << left shift or >> right shift operator #181

katat opened this issue Sep 10, 2024 · 0 comments · May be fixed by #241
Labels

Comments

@katat
Copy link
Collaborator

katat commented Sep 10, 2024

It is common to need to << or >> to manipulate a value via bit shifting.

Without bit shifting, it needs to do the following:

   // 1 << LEN
    let mut pow2 = 1;
    for ii in 0..LEN {
        pow2 = pow2 + pow2;
    }

The left hand side will be always the value, while the right hand side will be the number of bits to shift.

We can add a builtin to support this operator. For example, the compiler will call the newly added builtins corresponding to the following new binary operations.

pub enum Op2 {
    Addition,
    Subtraction,
    Multiplication,
    Division,
    Equality,
    Inequality,
    BoolAnd,
    BoolOr,
+   RightShift,
+   LeftShift,
}

To implement, it needs to take care two cases for the value being shifted:

  • constant: When the value is a constant, then the builtin function just do the shifting operation and return the value.
  • cell var: When the value is a cell var, the builtin needs to handle constraints.
@katat katat added the medium label Sep 10, 2024
@Lynette7 Lynette7 linked a pull request Dec 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant