While optimizing some data structures I’ve realized that the EVM is missing some in-memory bit operations that make it much more gas expensive to do certain calculations compared to x86. I think it would make sense to add them and would love to hear if you’ve come across similar mathematical instructions.
POPCNT- Population Count (Counting all set bits in a uint256)
CLZ- Count Leading Zeros (Getting the highest bit in a uint256)
These two operations need to be simulated in a loop at the moment and become thus pretty expensive. E.g. here is a 700 gas version of getting the highest bit Logarithm math operation in Solidity - Ethereum Stack Exchange
I might turn this into an EIP, so let me know if there are more instructions to add.