This replaces #105.
Motivation
To provide native bitwise shifting with cost on par with other arithmetic operations.
Specification
The following new EVM opcodes are introduced:
-
0x1b: SHL (logical left shift)
-
0x1c: SHR (logical right shift)
-
0x1d: SAR (arithmetic right shift)
-
0x1e: ROL (rotate left)
-
0x1f: ROR (rotate right)
The gast cost is set at verylow (3 gas)
All shift / rotate instructions take two stack elements (i.e. value << index), with the top element being the index to shift with and the next stack element is the value. Both index and value is considered as unsigned, with the exception of SAR, where value is signed.
All results must be mod 2^256.
For index ≥ 256, the result is 0.
Effect
This effectively reduces the gas cost and number of instructions for the above. A SHL and SHR can be implemented as a * (2 ** b) ( and a / (2 ** b) respectively. The upper gas bound for these is 35 gas.
SAR and the rotation opcodes cost more than 35.
This replaces #105.
Motivation
To provide native bitwise shifting with cost on par with other arithmetic operations.
Specification
The following new EVM opcodes are introduced:
0x1b:SHL(logical left shift)0x1c:SHR(logical right shift)0x1d:SAR(arithmetic right shift)0x1e:ROL(rotate left)0x1f:ROR(rotate right)The gast cost is set at
verylow(3 gas)All shift / rotate instructions take two stack elements (i.e.
value << index), with the top element being theindexto shift with and the next stack element is thevalue. Bothindexandvalueis considered as unsigned, with the exception ofSAR, wherevalueis signed.All results must be mod
2^256.For
index≥ 256, the result is0.Effect
This effectively reduces the gas cost and number of instructions for the above. A
SHLandSHRcan be implemented asa * (2 ** b)( anda / (2 ** b)respectively. The upper gas bound for these is 35 gas.SARand the rotation opcodes cost more than 35.