From 4bab8793ed119e445b6c9e69d9250bdede176bc7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 13 Feb 2017 16:05:22 +0000 Subject: [PATCH 01/12] Draft of bitwise shifting opcodes --- EIPS/eip-draft_bitwise_shifts.md | 108 +++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 EIPS/eip-draft_bitwise_shifts.md diff --git a/EIPS/eip-draft_bitwise_shifts.md b/EIPS/eip-draft_bitwise_shifts.md new file mode 100644 index 00000000000000..0f42f9fc0a2c8f --- /dev/null +++ b/EIPS/eip-draft_bitwise_shifts.md @@ -0,0 +1,108 @@ +## Preamble + + EIP: + Title: Bitwise shifting instructions in EVM + Author: Alex Beregszaszi, Paweł Bylica + Type: Standard Track + Category Core + Status: Draft + Created: 2017-02-13 + + +## Simple Summary + +To provide native bitwise shifting with cost on par with other arithmetic operations. + +## Abstract + +Native bitwise shifting instructions are introduced, which are more efficient processing wise on the host and are cheaper to user by a contract. + +## Motivation + +EVM is lacking bitwise shifting operators, but supports other logical and arithmetic operators. Shift operations can be implemented via arithmetic operators, but that has a higher cost and requires more processing time from the host. Implementing `SHL` and `SHR` using arithmetics cost each 35 gas, while the proposed instructions take 3 gas. + +## Specification + +The following instructions are introduced: + +### `0x1b`: `SHL` (shift left) + +The `SHL` instruction (shift left) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the left by the number of bits in the first popped value `arg1`. The result is equal to + +``` +(arg2 * 2^arg1) mod 2^256 +``` + +Notes: +- If the shift amount is greater or equal 256 the result is 0. + +### `0x1c`: `SHR` (logical shift right) + +The `SHR` instruction (logical shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the right by the number of bits in the first popped value `arg1` with zero fill. The result is equal to + +``` +arg2 udiv 2^arg1 +``` + +Notes: +- If the shift amount is greater or equal 256 the result is 0. + +### `0x1d`: `SAR` (arithmetic shift right) + +The `SAR` instruction (arithmetic shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the right by the number of bits in the first popped value `arg1` with sign extension. The result is equal to + +``` +arg2 sdiv 2^arg1 +``` + +Notes: +- `arg1` is interpreted as unsigned number. +- If the shift amount is greater or equal 256 the result is 0 if `arg2` is non-negative or -1 if `arg2` is negative. + +### `0x1e`: `ROL` (rotate left) + +The `ROL` instruction (rotate left) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` circular shifted to the left by the number of bits in the first popped value `arg1`. + +``` +(arg1 shl arg2) or (arg1 shr (256 - arg2) +``` + +Notes: +- `arg2 rol arg1` is equivalent of `arg2 rol (arg1 mod 2^256)` + +### `0x1f`: `ROR` (rotate right) + +The `ROL` instruction (rotate right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` circular shifted to the right by the number of bits in the first popped value `arg1`. + +``` +(arg1 shr arg2) or (arg1 shl (256 - arg2) +``` + +Notes: +- `arg2 ror arg1` is equivalent of `arg2 ror (arg1 mod 2^256)` + +The cost of the shift instructions is set at `verylow` tier (3 gas), while the rotations are 12 gas each. + +## Rationale + +Instruction operands were chosen to match the other logical and arithmetic instructions. + +## Backwards Compatibility + +The newly introduced instructions have no effect on bytecode created in the past. + +## Test Cases + +TBA + +## Implementation + +Client support: +TBA + +Compiler support: +- Solidity: https://github.com/ethereum/solidity/tree/asm-bitshift + +## Copyright + +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From a63aef39d19438d17d80a04cf29183dce81fc89b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 23 Apr 2017 11:28:25 +0100 Subject: [PATCH 02/12] Remove ROR/ROL --- EIPS/eip-draft_bitwise_shifts.md | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/EIPS/eip-draft_bitwise_shifts.md b/EIPS/eip-draft_bitwise_shifts.md index 0f42f9fc0a2c8f..3047beba20fbd3 100644 --- a/EIPS/eip-draft_bitwise_shifts.md +++ b/EIPS/eip-draft_bitwise_shifts.md @@ -59,29 +59,7 @@ Notes: - `arg1` is interpreted as unsigned number. - If the shift amount is greater or equal 256 the result is 0 if `arg2` is non-negative or -1 if `arg2` is negative. -### `0x1e`: `ROL` (rotate left) - -The `ROL` instruction (rotate left) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` circular shifted to the left by the number of bits in the first popped value `arg1`. - -``` -(arg1 shl arg2) or (arg1 shr (256 - arg2) -``` - -Notes: -- `arg2 rol arg1` is equivalent of `arg2 rol (arg1 mod 2^256)` - -### `0x1f`: `ROR` (rotate right) - -The `ROL` instruction (rotate right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` circular shifted to the right by the number of bits in the first popped value `arg1`. - -``` -(arg1 shr arg2) or (arg1 shl (256 - arg2) -``` - -Notes: -- `arg2 ror arg1` is equivalent of `arg2 ror (arg1 mod 2^256)` - -The cost of the shift instructions is set at `verylow` tier (3 gas), while the rotations are 12 gas each. +The cost of the shift instructions is set at `verylow` tier (3 gas). ## Rationale From 0b3461651f2d6b32a68eba407867ec40cb5bc479 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 23 Apr 2017 14:50:20 +0100 Subject: [PATCH 03/12] Add link to client support (cpp-ethereum) --- EIPS/eip-draft_bitwise_shifts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-draft_bitwise_shifts.md b/EIPS/eip-draft_bitwise_shifts.md index 3047beba20fbd3..0475ba7d9f868c 100644 --- a/EIPS/eip-draft_bitwise_shifts.md +++ b/EIPS/eip-draft_bitwise_shifts.md @@ -76,7 +76,7 @@ TBA ## Implementation Client support: -TBA +- cpp-ethereum: https://github.com/ethereum/cpp-ethereum/pull/4054 Compiler support: - Solidity: https://github.com/ethereum/solidity/tree/asm-bitshift From 7bc447717f4a27be091b4d65fd0488b757c85479 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 23 Apr 2017 14:53:46 +0100 Subject: [PATCH 04/12] Swap shift operands (value is the top item) --- EIPS/eip-draft_bitwise_shifts.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/EIPS/eip-draft_bitwise_shifts.md b/EIPS/eip-draft_bitwise_shifts.md index 0475ba7d9f868c..a96665450b777c 100644 --- a/EIPS/eip-draft_bitwise_shifts.md +++ b/EIPS/eip-draft_bitwise_shifts.md @@ -27,10 +27,10 @@ The following instructions are introduced: ### `0x1b`: `SHL` (shift left) -The `SHL` instruction (shift left) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the left by the number of bits in the first popped value `arg1`. The result is equal to +The `SHL` instruction (shift left) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the first popped value `arg1` shifted to the left by the number of bits in the second popped value `arg2`. The result is equal to ``` -(arg2 * 2^arg1) mod 2^256 +(arg1 * 2^arg2) mod 2^256 ``` Notes: @@ -38,10 +38,10 @@ Notes: ### `0x1c`: `SHR` (logical shift right) -The `SHR` instruction (logical shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the right by the number of bits in the first popped value `arg1` with zero fill. The result is equal to +The `SHR` instruction (logical shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the first popped value `arg1` shifted to the right by the number of bits in the second popped value `arg2` with zero fill. The result is equal to ``` -arg2 udiv 2^arg1 +arg1 udiv 2^arg2 ``` Notes: @@ -49,15 +49,15 @@ Notes: ### `0x1d`: `SAR` (arithmetic shift right) -The `SAR` instruction (arithmetic shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the right by the number of bits in the first popped value `arg1` with sign extension. The result is equal to +The `SAR` instruction (arithmetic shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the first popped value `arg1` shifted to the right by the number of bits in the second popped value `arg2` with sign extension. The result is equal to ``` -arg2 sdiv 2^arg1 +arg1 sdiv 2^arg2 ``` Notes: -- `arg1` is interpreted as unsigned number. -- If the shift amount is greater or equal 256 the result is 0 if `arg2` is non-negative or -1 if `arg2` is negative. +- `arg2` is interpreted as unsigned number. +- If the shift amount (`arg2`) is greater or equal 256 the result is 0 if `arg1` is non-negative or -1 if `arg1` is negative. The cost of the shift instructions is set at `verylow` tier (3 gas). From 27847a875dae96c412fa71d6021c33a2ac1adcb4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 23 Apr 2017 14:55:19 +0100 Subject: [PATCH 05/12] Rename to EIP145 --- EIPS/{eip-draft_bitwise_shifts.md => eip-145.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename EIPS/{eip-draft_bitwise_shifts.md => eip-145.md} (99%) diff --git a/EIPS/eip-draft_bitwise_shifts.md b/EIPS/eip-145.md similarity index 99% rename from EIPS/eip-draft_bitwise_shifts.md rename to EIPS/eip-145.md index a96665450b777c..bd2ebc0236ad33 100644 --- a/EIPS/eip-draft_bitwise_shifts.md +++ b/EIPS/eip-145.md @@ -1,6 +1,6 @@ ## Preamble - EIP: + EIP: 145 Title: Bitwise shifting instructions in EVM Author: Alex Beregszaszi, Paweł Bylica Type: Standard Track From d4f5382f5170e30496e26e93f954ec561b8db1ab Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 23 Apr 2017 15:43:43 +0100 Subject: [PATCH 06/12] Clarify shift amount (arg2) --- EIPS/eip-145.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/EIPS/eip-145.md b/EIPS/eip-145.md index bd2ebc0236ad33..91bf3232120e71 100644 --- a/EIPS/eip-145.md +++ b/EIPS/eip-145.md @@ -4,7 +4,7 @@ Title: Bitwise shifting instructions in EVM Author: Alex Beregszaszi, Paweł Bylica Type: Standard Track - Category Core + Category: Core Status: Draft Created: 2017-02-13 @@ -34,7 +34,8 @@ The `SHL` instruction (shift left) pops 2 values from the stack, `arg1` and `arg ``` Notes: -- If the shift amount is greater or equal 256 the result is 0. +- The shift amount (`arg2`) is interpreted as an unsigned number. +- If the shift amount (`arg2`) is greater or equal 256 the result is 0. ### `0x1c`: `SHR` (logical shift right) @@ -45,7 +46,8 @@ arg1 udiv 2^arg2 ``` Notes: -- If the shift amount is greater or equal 256 the result is 0. +- The shift amount (`arg2`) is interpreted as an unsigned number. +- If the shift amount (`arg2`) is greater or equal 256 the result is 0. ### `0x1d`: `SAR` (arithmetic shift right) @@ -56,7 +58,7 @@ arg1 sdiv 2^arg2 ``` Notes: -- `arg2` is interpreted as unsigned number. +- The shift amount (`arg2`) is interpreted as an unsigned number. - If the shift amount (`arg2`) is greater or equal 256 the result is 0 if `arg1` is non-negative or -1 if `arg1` is negative. The cost of the shift instructions is set at `verylow` tier (3 gas). From e5ca9196720c2a52134ce922ba80638e40ad5614 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 3 Jul 2017 21:31:23 +0100 Subject: [PATCH 07/12] Use floor and not udiv/sdiv --- EIPS/eip-145.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-145.md b/EIPS/eip-145.md index 91bf3232120e71..cd1bf8c19d3a61 100644 --- a/EIPS/eip-145.md +++ b/EIPS/eip-145.md @@ -42,7 +42,7 @@ Notes: The `SHR` instruction (logical shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the first popped value `arg1` shifted to the right by the number of bits in the second popped value `arg2` with zero fill. The result is equal to ``` -arg1 udiv 2^arg2 +floor(arg1 / 2^arg2) ``` Notes: @@ -54,7 +54,7 @@ Notes: The `SAR` instruction (arithmetic shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the first popped value `arg1` shifted to the right by the number of bits in the second popped value `arg2` with sign extension. The result is equal to ``` -arg1 sdiv 2^arg2 +floor(arg1 / 2^arg2) ``` Notes: From 4218665af978444201d685c8fef23a360500befd Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 3 Jul 2017 21:35:40 +0100 Subject: [PATCH 08/12] Explain sign of arg1/arg2 --- EIPS/eip-145.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EIPS/eip-145.md b/EIPS/eip-145.md index cd1bf8c19d3a61..95c84816718818 100644 --- a/EIPS/eip-145.md +++ b/EIPS/eip-145.md @@ -34,6 +34,7 @@ The `SHL` instruction (shift left) pops 2 values from the stack, `arg1` and `arg ``` Notes: +- The value (`arg1`) is interpreted as an unsigned number. - The shift amount (`arg2`) is interpreted as an unsigned number. - If the shift amount (`arg2`) is greater or equal 256 the result is 0. @@ -46,6 +47,7 @@ floor(arg1 / 2^arg2) ``` Notes: +- The value (`arg1`) is interpreted as an unsigned number. - The shift amount (`arg2`) is interpreted as an unsigned number. - If the shift amount (`arg2`) is greater or equal 256 the result is 0. @@ -58,6 +60,7 @@ floor(arg1 / 2^arg2) ``` Notes: +- The value (`arg1`) is interpreted as a signed number. - The shift amount (`arg2`) is interpreted as an unsigned number. - If the shift amount (`arg2`) is greater or equal 256 the result is 0 if `arg1` is non-negative or -1 if `arg1` is negative. From 0b08d11f488fa14975fbc585af639aa00d7f4c0b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 31 Jul 2017 13:59:00 +0100 Subject: [PATCH 09/12] Add comparison with current opcodes --- EIPS/eip-145.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/EIPS/eip-145.md b/EIPS/eip-145.md index 95c84816718818..04f36bcd2d537b 100644 --- a/EIPS/eip-145.md +++ b/EIPS/eip-145.md @@ -37,6 +37,7 @@ Notes: - The value (`arg1`) is interpreted as an unsigned number. - The shift amount (`arg2`) is interpreted as an unsigned number. - If the shift amount (`arg2`) is greater or equal 256 the result is 0. +- This is equivalent to `SWAP1 PUSH1 2 EXP MUL`. ### `0x1c`: `SHR` (logical shift right) @@ -50,6 +51,7 @@ Notes: - The value (`arg1`) is interpreted as an unsigned number. - The shift amount (`arg2`) is interpreted as an unsigned number. - If the shift amount (`arg2`) is greater or equal 256 the result is 0. +- This is equivalent to `SWAP1 PUSH1 2 EXP DIV`. ### `0x1d`: `SAR` (arithmetic shift right) @@ -63,6 +65,7 @@ Notes: - The value (`arg1`) is interpreted as a signed number. - The shift amount (`arg2`) is interpreted as an unsigned number. - If the shift amount (`arg2`) is greater or equal 256 the result is 0 if `arg1` is non-negative or -1 if `arg1` is negative. +- This is **not** equivalent to `SWAP1 PUSH1 2 EXP SDIV`, since it rounds differently. See `SDIV(-1, 2) == 0`, while `SAR(-1, 1) == -1`. The cost of the shift instructions is set at `verylow` tier (3 gas). From 9464fa7fa5d82c211a0c433c3d39cac569185fcd Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 22 Sep 2017 14:04:45 +0100 Subject: [PATCH 10/12] Clarify text (user -> use) --- EIPS/eip-145.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-145.md b/EIPS/eip-145.md index 04f36bcd2d537b..01844a9ea1cca7 100644 --- a/EIPS/eip-145.md +++ b/EIPS/eip-145.md @@ -15,7 +15,7 @@ To provide native bitwise shifting with cost on par with other arithmetic operat ## Abstract -Native bitwise shifting instructions are introduced, which are more efficient processing wise on the host and are cheaper to user by a contract. +Native bitwise shifting instructions are introduced, which are more efficient processing wise on the host and are cheaper to use by a contract. ## Motivation @@ -87,7 +87,7 @@ Client support: - cpp-ethereum: https://github.com/ethereum/cpp-ethereum/pull/4054 Compiler support: -- Solidity: https://github.com/ethereum/solidity/tree/asm-bitshift +- Solidity/LLL: https://github.com/ethereum/solidity/pull/2541 ## Copyright From d01c9af47fbc75ee482c132a3b37f847bd5dc4de Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 22 Sep 2017 14:15:50 +0100 Subject: [PATCH 11/12] Swapp operand order for bitwise shifting --- EIPS/eip-145.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/EIPS/eip-145.md b/EIPS/eip-145.md index 01844a9ea1cca7..67370ee91b70e2 100644 --- a/EIPS/eip-145.md +++ b/EIPS/eip-145.md @@ -27,51 +27,51 @@ The following instructions are introduced: ### `0x1b`: `SHL` (shift left) -The `SHL` instruction (shift left) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the first popped value `arg1` shifted to the left by the number of bits in the second popped value `arg2`. The result is equal to +The `SHL` instruction (shift left) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the left by the number of bits in the first popped value `arg1`. The result is equal to ``` -(arg1 * 2^arg2) mod 2^256 +(arg2 * 2^arg1) mod 2^256 ``` Notes: -- The value (`arg1`) is interpreted as an unsigned number. -- The shift amount (`arg2`) is interpreted as an unsigned number. -- If the shift amount (`arg2`) is greater or equal 256 the result is 0. -- This is equivalent to `SWAP1 PUSH1 2 EXP MUL`. +- The value (`arg2`) is interpreted as an unsigned number. +- The shift amount (`arg1`) is interpreted as an unsigned number. +- If the shift amount (`arg1`) is greater or equal 256 the result is 0. +- This is equivalent to `PUSH1 2 EXP MUL`. ### `0x1c`: `SHR` (logical shift right) -The `SHR` instruction (logical shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the first popped value `arg1` shifted to the right by the number of bits in the second popped value `arg2` with zero fill. The result is equal to +The `SHR` instruction (logical shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the right by the number of bits in the first popped value `arg1` with zero fill. The result is equal to ``` -floor(arg1 / 2^arg2) +floor(arg2 / 2^arg1) ``` Notes: -- The value (`arg1`) is interpreted as an unsigned number. -- The shift amount (`arg2`) is interpreted as an unsigned number. -- If the shift amount (`arg2`) is greater or equal 256 the result is 0. -- This is equivalent to `SWAP1 PUSH1 2 EXP DIV`. +- The value (`arg2`) is interpreted as an unsigned number. +- The shift amount (`arg1`) is interpreted as an unsigned number. +- If the shift amount (`arg1`) is greater or equal 256 the result is 0. +- This is equivalent to `PUSH1 2 EXP DIV`. ### `0x1d`: `SAR` (arithmetic shift right) -The `SAR` instruction (arithmetic shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the first popped value `arg1` shifted to the right by the number of bits in the second popped value `arg2` with sign extension. The result is equal to +The `SAR` instruction (arithmetic shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the right by the number of bits in the first popped value `arg1` with sign extension. The result is equal to ``` -floor(arg1 / 2^arg2) +floor(arg2 / 2^arg1) ``` Notes: -- The value (`arg1`) is interpreted as a signed number. -- The shift amount (`arg2`) is interpreted as an unsigned number. -- If the shift amount (`arg2`) is greater or equal 256 the result is 0 if `arg1` is non-negative or -1 if `arg1` is negative. -- This is **not** equivalent to `SWAP1 PUSH1 2 EXP SDIV`, since it rounds differently. See `SDIV(-1, 2) == 0`, while `SAR(-1, 1) == -1`. +- The value (`arg2`) is interpreted as a signed number. +- The shift amount (`arg1`) is interpreted as an unsigned number. +- If the shift amount (`arg1`) is greater or equal 256 the result is 0 if `arg2` is non-negative or -1 if `arg2` is negative. +- This is **not** equivalent to `PUSH1 2 EXP SDIV`, since it rounds differently. See `SDIV(-1, 2) == 0`, while `SAR(-1, 1) == -1`. The cost of the shift instructions is set at `verylow` tier (3 gas). ## Rationale -Instruction operands were chosen to match the other logical and arithmetic instructions. +Instruction operands were chosen to fit the more natural use case of shifting a value already on the stack. This means the operand order is swapped compared to most arithmetic insturctions. ## Backwards Compatibility From 74d9a171ffa97c3ccc10433532e8324b1410f1bf Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 22 Sep 2017 16:07:34 +0100 Subject: [PATCH 12/12] Clarify wording about arg1/arg2 --- EIPS/eip-145.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-145.md b/EIPS/eip-145.md index 67370ee91b70e2..d529c0f3e26df0 100644 --- a/EIPS/eip-145.md +++ b/EIPS/eip-145.md @@ -27,7 +27,7 @@ The following instructions are introduced: ### `0x1b`: `SHL` (shift left) -The `SHL` instruction (shift left) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the left by the number of bits in the first popped value `arg1`. The result is equal to +The `SHL` instruction (shift left) pops 2 values from the stack, first `arg1` and then `arg2`, and pushes on the stack `arg2` shifted to the left by `arg1` number of bits. The result is equal to ``` (arg2 * 2^arg1) mod 2^256 @@ -41,7 +41,7 @@ Notes: ### `0x1c`: `SHR` (logical shift right) -The `SHR` instruction (logical shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the right by the number of bits in the first popped value `arg1` with zero fill. The result is equal to +The `SHR` instruction (logical shift right) pops 2 values from the stack, first `arg1` and then `arg2`, and pushes on the stack `arg2` shifted to the right by `arg1` number of bits with zero fill. The result is equal to ``` floor(arg2 / 2^arg1) @@ -55,7 +55,7 @@ Notes: ### `0x1d`: `SAR` (arithmetic shift right) -The `SAR` instruction (arithmetic shift right) pops 2 values from the stack, `arg1` and `arg2`, and pushes on the stack the second popped value `arg2` shifted to the right by the number of bits in the first popped value `arg1` with sign extension. The result is equal to +The `SAR` instruction (arithmetic shift right) pops 2 values from the stack, first `arg1` and then `arg2`, and pushes on the stack `arg2` shifted to the right by `arg1` number of bits with sign extension. The result is equal to ``` floor(arg2 / 2^arg1)