-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Labels
Description
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.