Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
perf: activate compiler optimization for size
Browse files Browse the repository at this point in the history
  • Loading branch information
Flouse authored and jjyr committed Nov 7, 2022
1 parent f82a4a4 commit 0cc7a81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,<args> 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.
Expand Down Expand Up @@ -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 $@ $<
Expand Down
10 changes: 10 additions & 0 deletions c/contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
#include "sudt_contracts.h"
#include "other_contracts.h"

#include <intx/intx.hpp>
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
Expand Down

0 comments on commit 0cc7a81

Please sign in to comment.