diff --git a/CHANGELOG.md b/CHANGELOG.md index ae593883d23..e4b1fff4c7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ are provided with different values, using input as per the execution-apis spec i - Performance improvements on MOD variant instructions while converting from byte[] to longs [#9976](https://github.com/besu-eth/besu/pull/9976) - Implement DIV and SDIV with long limbs [#9923](https://github.com/besu-eth/besu/pull/9923) - Improve MULMOD worst cases [#10088](https://github.com/besu-eth/besu/pull/10088) +- Optimized MUL and SUB to use UInt256 [#10030](https://github.com/besu-eth/besu/pull/10030) - Use cache locality to improve Shift opcodes [#9878](https://github.com/besu-eth/besu/pull/9878) - Defer Snappy decompression of inbound P2P messages from the Netty I/O thread to the worker thread, reducing memory held in the transaction worker queue to compressed size [#10048](https://github.com/besu-eth/besu/pull/10048) - Dispatch snap server request processing (GET_ACCOUNT_RANGE, GET_STORAGE_RANGE, GET_BYTECODES, GET_TRIE_NODES, GET_BLOCK_ACCESS_LISTS) off the Netty event loop to prevent heavy trie/DB work from blocking ETH protocol message handling [#10083](https://github.com/besu-eth/besu/pull/10083) diff --git a/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/MulOperationOptimizedBenchmark.java b/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/MulOperationOptimizedBenchmark.java new file mode 100644 index 00000000000..08d5241bd4a --- /dev/null +++ b/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/MulOperationOptimizedBenchmark.java @@ -0,0 +1,27 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.vm.operations; + +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.operation.MulOperationOptimized; +import org.hyperledger.besu.evm.operation.Operation; + +public class MulOperationOptimizedBenchmark extends BinaryOperationBenchmark { + + @Override + protected Operation.OperationResult invoke(final MessageFrame frame) { + return MulOperationOptimized.staticOperation(frame); + } +} diff --git a/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/SubOperationOptimizedBenchmark.java b/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/SubOperationOptimizedBenchmark.java new file mode 100644 index 00000000000..02deeb061bd --- /dev/null +++ b/ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/SubOperationOptimizedBenchmark.java @@ -0,0 +1,27 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.vm.operations; + +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.operation.Operation; +import org.hyperledger.besu.evm.operation.SubOperationOptimized; + +public class SubOperationOptimizedBenchmark extends BinaryOperationBenchmark { + + @Override + protected Operation.OperationResult invoke(final MessageFrame frame) { + return SubOperationOptimized.staticOperation(frame); + } +} diff --git a/evm/src/main/java/org/hyperledger/besu/evm/EVM.java b/evm/src/main/java/org/hyperledger/besu/evm/EVM.java index 83dfef073b8..99c4eb8014b 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/EVM.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/EVM.java @@ -54,6 +54,7 @@ import org.hyperledger.besu.evm.operation.MulModOperation; import org.hyperledger.besu.evm.operation.MulModOperationOptimized; import org.hyperledger.besu.evm.operation.MulOperation; +import org.hyperledger.besu.evm.operation.MulOperationOptimized; import org.hyperledger.besu.evm.operation.NotOperation; import org.hyperledger.besu.evm.operation.NotOperationOptimized; import org.hyperledger.besu.evm.operation.Operation; @@ -79,6 +80,7 @@ import org.hyperledger.besu.evm.operation.SignExtendOperation; import org.hyperledger.besu.evm.operation.StopOperation; import org.hyperledger.besu.evm.operation.SubOperation; +import org.hyperledger.besu.evm.operation.SubOperationOptimized; import org.hyperledger.besu.evm.operation.SwapNOperation; import org.hyperledger.besu.evm.operation.SwapOperation; import org.hyperledger.besu.evm.operation.VirtualOperation; @@ -251,8 +253,14 @@ public void runToHalt(final MessageFrame frame, final OperationTracer tracing) { evmConfiguration.enableOptimizedOpcodes() ? AddOperationOptimized.staticOperation(frame) : AddOperation.staticOperation(frame); - case 0x02 -> MulOperation.staticOperation(frame); - case 0x03 -> SubOperation.staticOperation(frame); + case 0x02 -> + evmConfiguration.enableOptimizedOpcodes() + ? MulOperationOptimized.staticOperation(frame) + : MulOperation.staticOperation(frame); + case 0x03 -> + evmConfiguration.enableOptimizedOpcodes() + ? SubOperationOptimized.staticOperation(frame) + : SubOperation.staticOperation(frame); case 0x04 -> evmConfiguration.enableOptimizedOpcodes() ? DivOperationOptimized.staticOperation(frame) diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/MulOperationOptimized.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/MulOperationOptimized.java similarity index 93% rename from evm/src/main/java/org/hyperledger/besu/evm/operation/MulOperationOptimized.java rename to evm/src/main/java/org/hyperledger/besu/evm/operation/MulOperationOptimized.java index 32bf01d68c9..8367bfb82d2 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/MulOperationOptimized.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/MulOperationOptimized.java @@ -1,5 +1,5 @@ -/** - * Copyright ConsenSys AG. +/* + * Copyright contributors to Besu. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -32,7 +32,7 @@ public class MulOperationOptimized extends AbstractFixedCostOperation { * * @param gasCalculator the gas calculator */ - public MulOperation(final GasCalculator gasCalculator) { + public MulOperationOptimized(final GasCalculator gasCalculator) { super(0x02, "MUL", 2, 1, gasCalculator, gasCalculator.getLowTierGasCost()); } @@ -57,6 +57,6 @@ public static OperationResult staticOperation(final MessageFrame frame) { Bytes resultBytes = Bytes.wrap(u0.mul(u1).toBytesBE()); frame.pushStackItem(resultBytes); - return mulModSuccess; + return mulSuccess; } }