From 0cc7a81b9e8f16dc188312a93b089a3d745418c9 Mon Sep 17 00:00:00 2001 From: Flouse Date: Mon, 7 Nov 2022 00:44:10 +0800 Subject: [PATCH] perf: activate compiler optimization for size --- Makefile | 20 ++++++++++++-------- c/contracts.h | 10 ++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 3e344d66..218582d7 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ OBJCOPY := $(TARGET)-objcopy SECP_DIR := deps/secp256k1-fix SECP256K1_SRC := $(SECP_DIR)/src/ecmult_static_pre_context.h + CFLAGS_CKB_STD = -Ideps/ckb-c-stdlib -Ideps/ckb-c-stdlib/molecule CFLAGS_SECP := -isystem $(SECP_DIR)/src -isystem $(SECP_DIR) CFLAGS_INTX := -Ideps/intx/lib/intx -Ideps/intx/include @@ -18,8 +19,11 @@ CFLAGS_MBEDTLS := -Ideps/mbedtls/include CFLAGS_EVMONE := -Ideps/evmone/lib/evmone -Ideps/evmone/include -Ideps/evmone/evmc/include CFLAGS_SMT := -Ideps/godwoken-scripts/c/deps/sparse-merkle-tree/c CFLAGS_GODWOKEN := -Ideps/godwoken-scripts/c -CFLAGS := -O3 -Ic/ripemd160 $(CFLAGS_CKB_STD) $(CFLAGS_EVMONE) $(CFLAGS_ETHASH) $(CFLAGS_CRYPTO_ALGORITHMS) $(CFLAGS_MBEDTLS) $(CFLAGS_SMT) $(CFLAGS_GODWOKEN) $(CFLAGS_SECP) + +# -O3: Higher level of optmization. Slower compile-time, better for production builds. +CFLAGS := -O3 -Ic/ripemd160 $(CFLAGS_INTX) $(CFLAGS_CKB_STD) $(CFLAGS_EVMONE) $(CFLAGS_ETHASH) $(CFLAGS_CRYPTO_ALGORITHMS) $(CFLAGS_MBEDTLS) $(CFLAGS_SMT) $(CFLAGS_GODWOKEN) $(CFLAGS_SECP) CXXFLAGS := $(CFLAGS) -std=c++1z + # -Wl, Pass the comma separated arguments in args to the linker(GNU linker) # --gc-sections # This will perform a garbage collection of code and data never referenced. @@ -156,23 +160,23 @@ build/test_ripemd160: c/ripemd160/test_ripemd160.c c/ripemd160/ripemd160.h c/rip riscv64-unknown-elf-run build/test_ripemd160 build/execution_state.o: deps/evmone/lib/evmone/execution_state.cpp - $(CXX) $(CXXFLAGS) $(CFLAGS_INTX) $(LDFLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $< build/baseline.o: deps/evmone/lib/evmone/baseline.cpp - $(CXX) $(CXXFLAGS) $(CFLAGS_INTX) $(LDFLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $< build/analysis.o: deps/evmone/lib/evmone/analysis.cpp - $(CXX) $(CXXFLAGS) $(CFLAGS_INTX) $(LDFLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $< build/execution.o: deps/evmone/lib/evmone/execution.cpp - $(CXX) $(CXXFLAGS) $(CFLAGS_INTX) $(LDFLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $< build/instructions.o: deps/evmone/lib/evmone/instructions.cpp - $(CXX) $(CXXFLAGS) $(CFLAGS_INTX) $(LDFLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $< build/instruction_metrics.o: deps/evmone/evmc/lib/instructions/instruction_metrics.c $(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $< build/instruction_names.o: deps/evmone/evmc/lib/instructions/instruction_names.c $(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $< build/instructions_calls.o: deps/evmone/lib/evmone/instructions_calls.cpp - $(CXX) $(CXXFLAGS) $(CFLAGS_INTX) $(LDFLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $< build/evmone.o: deps/evmone/lib/evmone/evmone.cpp - $(CXX) $(CXXFLAGS) $(CFLAGS_INTX) $(LDFLAGS) -c -o $@ $< -DPROJECT_VERSION=\"0.6.0-dev\" + $(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $< -DPROJECT_VERSION=\"0.6.0-dev\" build/keccak.o: deps/ethash/lib/keccak/keccak.c build/keccakf800.o $(CC) $(CFLAGS) $(LDFLAGS) -c -o $@ $< diff --git a/c/contracts.h b/c/contracts.h index 7e39d5d6..7fb59791 100644 --- a/c/contracts.h +++ b/c/contracts.h @@ -9,6 +9,16 @@ #include "sudt_contracts.h" #include "other_contracts.h" +#include +using intx::uint256; +/** + * This unused function will activate compiler optimization for size. + * It reduces Polyjuice generator and validator by ~100KB. + */ +uint256 _activate_size_optimization(uint256 x, uint256 y) { + return intx::udivrem(x, y).quot; +} + /* Protocol Params: [Referenced]: https://github.com/ethereum/go-ethereum/blob/master/params/protocol_params.go