solady icon indicating copy to clipboard operation
solady copied to clipboard

📝 Plan for `CLZ` opcode

Open Vectorized opened this issue 9 months ago • 0 comments

In the future, when the CLZ opcode https://eips.ethereum.org/EIPS/eip-7939 is added, many algorithms in Solady can be drastically improved upon.

Libraries such as LibBit, LibBytes, LibString, FixedPointMathLib, LibZip can see a dramatic speedup.

CLZ can be the highest impact improvement to accelerate the EVM for the next 2 years:

  • More so than transient storage (can be substituted with using warm slots).
  • More so than PUSH0 (can be substituted with other 2 gas opcodes).
  • LibZip.cdCompress will be more widely used to pack storage automatically. This uses CLZ repeatedly.

To enable maximum support and backwards compatibility:

  • Once the CLZ opcode appears on mainnet, the corresponding library will be in the future directory (e.g. utils/future).
  • Let's also take the opportunity to introduce stuff like MCOPY (e.g. for insertion sort).
  • When most L2s have the CLZ opcode, we may decide to move the libraries from future into the actual directory. Then, the non CLZ libraries will be moved into the legacy directory.

Vectorized avatar May 07 '25 22:05 Vectorized