EIP-616 · Stagnant · Core · 2017-04-25
EIP-616: SIMD Operations for the EVM
Proposed SIMD vector opcodes for the EVM, so one instruction could add or compare many small integers packed in a 256-bit stack word; it is Stagnant and was never adopted.
What problem does it solve?
Every EVM stack item is 256 bits wide, and every arithmetic opcode treats it as one big integer. Many real workloads (hash functions, elliptic curve math, byte shuffling) work on 8-, 32- or 64-bit numbers. Doing them one at a time on 256-bit words wastes both CPU time and gas.
Modern CPUs solve this with SIMD (Single Instruction, Multiple Data): one instruction operates on several "lanes" of a wide register in parallel. EIP-616 proposes the same idea for the EVM, citing published speedups of roughly 1.3x to 7x for algorithms such as SHA-512, BLAKE2b and elliptic curve operations on native hardware.
How it works
Two-byte opcodes. Each SIMD instruction is an opcode byte followed by a type byte:
| Bits | Field |
|---|---|
| 1 | scalar type: 0 = unsigned int, 1 = IEEE float (reserved for later) |
| 2 | lane width: log2 of bytes per lane (1, 2, 4 or 8 bytes) |
| 3 | element count: log2 of the number of lanes |
So one 256-bit word can be, for example, 32 lanes of uint8 or 4 lanes of uint64. A type byte of 0x7F means a normal 256-bit EVM integer.
Extended operations. XADD, XMUL, XSUB, XDIV, XMOD, comparisons (XLT, XEQ…), bitwise ops, shifts and rotates work lane by lane with the same meaning as their scalar versions. Extra ops:
XSHUFFLEreorders lanes according to a mask.XCASTconverts between vector types or to/from a plain 256-bit integer. Memory loads and stores still use 256-bit words, so you cast afterMLOADand beforeMSTORE.XINDEXpicks one lane, likeBYTE.
Cheaper gas. The spec argues current MUL/DIV pricing is off relative to ADD, and suggests SIMD ops cost 1 gas (2 for division), since native SIMD instructions take about as long as the interpreter overhead.
Sample code
Illustrative EVM assembly from the spec:
PUSH uint8[1, 2, 3]
PUSH uint8[4, 5, 6]
XADD ; -> uint8[5, 7, 9]
PUSH uint64[4, 5, 6, 0]
PUSH uint8[2, 0, 1, 3]
XSHUFFLE ; -> uint64[6, 4, 5, 0]
Things to know
- This proposal is Stagnant and was never adopted. No Ethereum fork has added SIMD opcodes, and none of these mnemonics exist on mainnet.
- Floating-point lanes were explicitly not proposed for the first release; the bits were only reserved.
- Mixing vector types is invalid for most ops. The spec leaves open whether this is checked at deploy time or at run time.
- The typed subroutine syntax (
BEGINSUBX) depended on a separate subroutine proposal (EIP-187) being accepted. - The nearest related change that did ship is the bitwise shift opcodes of EIP-145, which are plain 256-bit operations, not vector ones.