Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved c-tiny benchmark #5948

Merged
merged 6 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions tutorials/c-tiny/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 70 additions & 46 deletions tutorials/c-tiny/fixeddecimal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,111 @@
# called LICENSE at the top level of the ICU4X source tree
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

# PLEASE KEEP THIS FILE IN SYNC WITH ../segmenter_tiny/Makefile
# PLEASE KEEP THIS FILE IN SYNC WITH ../segmenter/Makefile
# Differences between this file and that one:
# - CAPI_COMPONENT is different
# - This file does builds datagen, baked_data, and sets ICU4X_DATA_DIR

# The component built by this makefile.
CAPI_COMPONENT := decimal

.DEFAULT_GOAL := test
.PHONY: build test
FORCE:

ICU_CAPI := $(shell cargo metadata --manifest-path Cargo.toml --format-version 1 | jq '.packages[] | select(.name == "icu_capi").manifest_path' | xargs dirname)
HEADERS := ${ICU_CAPI}/bindings/c
ALL_HEADERS := $(wildcard ${HEADERS}/*)

ALL_RUST_SRC = $(wildcard ../../../components/**/*.rs) $(wildcard ../../../provider/**/*.rs) $(wildcard ../../../ffi/capi/**/*.rs)

$(ALL_HEADERS):

GCC := gcc
CLANG := clang-17
LLD := lld-17
LLVM_COMPATIBLE_NIGHTLY = "nightly-2024-01-01"

baked_data/macros.rs:
cargo install --path ../../../provider/icu4x-datagen --root target
target/bin/icu4x-datagen --locales en bn --markers all --deduplication none --format baked --out baked_data --overwrite

target/debug/libicu_capi.a: FORCE
cargo rustc -p icu_capi --crate-type staticlib --no-default-features --features icu_capi/compiled_data,icu_capi/decimal,icu_capi/std
target/release/icu4x-datagen: $(ALL_RUST_SRC)
cargo build --manifest-path ../../../Cargo.toml -p icu4x-datagen --target-dir target --release

baked_data/mod.rs: target/release/icu4x-datagen
target/release/icu4x-datagen --locales en bn --markers all --deduplication none --format baked --out baked_data --overwrite

target/debug/libicu_capi.a: baked_data/mod.rs
cargo rustc -p icu_capi --crate-type staticlib --no-default-features --features icu_capi/compiled_data,icu_capi/${CAPI_COMPONENT},icu_capi/std


target-normal/release/libicu_capi.a:
cargo rustc --release --target-dir target-normal -p icu_capi --crate-type staticlib --no-default-features --features icu_capi/compiled_data,icu_capi/${CAPI_COMPONENT},icu_capi/std


target/x86_64-unknown-linux-gnu/debug/libicu_capi.a: FORCE baked_data/macros.rs
target-panic-abort/x86_64-unknown-linux-gnu/release/libicu_capi.a: baked_data/mod.rs
rustup toolchain install ${LLVM_COMPATIBLE_NIGHTLY}
rustup component add rust-src --toolchain ${LLVM_COMPATIBLE_NIGHTLY}
RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" ICU4X_DATA_DIR=$(shell pwd)/baked_data \
cargo +${LLVM_COMPATIBLE_NIGHTLY} rustc -p icu_capi --crate-type staticlib --no-default-features --features icu_capi/compiled_data,icu_capi/decimal,icu_capi/looping_panic_handler,icu_capi/libc_alloc \
-Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu
RUSTFLAGS="-Cpanic=abort -Copt-level=s" ICU4X_DATA_DIR=$(shell pwd)/baked_data \
cargo +${LLVM_COMPATIBLE_NIGHTLY} rustc -p icu_capi --crate-type staticlib --no-default-features --features icu_capi/compiled_data,icu_capi/${CAPI_COMPONENT},icu_capi/looping_panic_handler,icu_capi/libc_alloc \
-Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu --release --target-dir target-panic-abort

target/x86_64-unknown-linux-gnu/release/libicu_capi.a: FORCE baked_data/macros.rs
target-panic-abort-lto/x86_64-unknown-linux-gnu/release/libicu_capi.a: baked_data/mod.rs
rustup toolchain install ${LLVM_COMPATIBLE_NIGHTLY}
rustup component add rust-src --toolchain ${LLVM_COMPATIBLE_NIGHTLY}
RUSTFLAGS="-Clto -Cembed-bitcode -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort -Copt-level=s" ICU4X_DATA_DIR=$(shell pwd)/baked_data \
cargo +${LLVM_COMPATIBLE_NIGHTLY} rustc -p icu_capi --crate-type staticlib --no-default-features --features icu_capi/compiled_data,icu_capi/${CAPI_COMPONENT},icu_capi/looping_panic_handler,icu_capi/libc_alloc \
-Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu --release --target-dir target-panic-abort-lto


target-panic-abort-linker-plugin-lto/x86_64-unknown-linux-gnu/release/libicu_capi.a: baked_data/mod.rs
rustup toolchain install ${LLVM_COMPATIBLE_NIGHTLY}
rustup component add rust-src --toolchain ${LLVM_COMPATIBLE_NIGHTLY}
RUSTFLAGS="-Clto -Cembed-bitcode -Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort -Copt-level=s" ICU4X_DATA_DIR=$(shell pwd)/baked_data \
cargo +${LLVM_COMPATIBLE_NIGHTLY} rustc -p icu_capi --crate-type staticlib --no-default-features --features icu_capi/compiled_data,icu_capi/decimal,icu_capi/looping_panic_handler,icu_capi/libc_alloc \
-Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu --release
cargo +${LLVM_COMPATIBLE_NIGHTLY} rustc -p icu_capi --crate-type staticlib --no-default-features --features icu_capi/compiled_data,icu_capi/${CAPI_COMPONENT},icu_capi/looping_panic_handler,icu_capi/libc_alloc \
-Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu --release --target-dir target-panic-abort-linker-plugin-lto

# Naive target: basic release mode, full std
1-release.elf: target-normal/release/libicu_capi.a $(ALL_HEADERS) test.c
$(GCC) test.c -I${HEADERS} target-normal/release/libicu_capi.a -ldl -lm -g -o 1-release.elf
Manishearth marked this conversation as resolved.
Show resolved Hide resolved

# gcc with maximum link-time code stripping (gc-sections and strip-all)
2-release-gcc-stripped.elf: target-normal/release/libicu_capi.a $(ALL_HEADERS) test.c
$(GCC) -fdata-sections -ffunction-sections test.c -I${HEADERS} target-normal/release/libicu_capi.a -ldl -lm -g -o 2-release-gcc-stripped.elf -Wl,--gc-sections -Wl,--strip-all

# clang; rust with release, panic-abort (std panic-immediate-abort)
3-panic-abort-clang.elf: target-panic-abort/x86_64-unknown-linux-gnu/release/libicu_capi.a $(ALL_HEADERS) test.c
$(CLANG) test.c -I${HEADERS} target-panic-abort/x86_64-unknown-linux-gnu/release/libicu_capi.a -g -o 3-panic-abort-clang.elf

# Naive target: no optimizations, full std
optim0.elf: target/debug/libicu_capi.a $(ALL_HEADERS) test.c
$(GCC) test.c -I${HEADERS} target/debug/libicu_capi.a -ldl -lm -g -o optim0.elf

# optim.elf: gcc with maximum link-time code stripping (gc-sections and strip-all)
optim1.elf: target/debug/libicu_capi.a $(ALL_HEADERS) test.c
$(GCC) -fdata-sections -ffunction-sections test.c -I${HEADERS} target/debug/libicu_capi.a -ldl -lm -g -o optim1.elf -Wl,--gc-sections -Wl,--strip-all
# clang with LTO, rust with release, LTO, panic-abort (std panic-immediate-abort)
4-panic-abort-lto-clang.elf: target-panic-abort-lto/x86_64-unknown-linux-gnu/release/libicu_capi.a $(ALL_HEADERS) test.c
$(CLANG) -flto=thin -fuse-ld=$(LLD) -fdata-sections -ffunction-sections test.c -I${HEADERS} target-panic-abort-lto/x86_64-unknown-linux-gnu/release/libicu_capi.a -g -o 4-panic-abort-lto-clang.elf

# optim2.elf: clang single-step with gc-sections
optim2.elf: target/x86_64-unknown-linux-gnu/debug/libicu_capi.a $(ALL_HEADERS) test.c
$(CLANG) -flto -fdata-sections -ffunction-sections test.c -I${HEADERS} target/x86_64-unknown-linux-gnu/debug/libicu_capi.a -g -o optim2.elf -Wl,--gc-sections

optim3.o: $(ALL_HEADERS) test.c
$(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -I${HEADERS} -g -o optim3.o
# clang with gc-sections, stripping; rust with release, LTO, panic-abort (std panic-immediate-abort)
5-panic-abort-clang-stripped.elf: target-panic-abort/x86_64-unknown-linux-gnu/release/libicu_capi.a $(ALL_HEADERS) test.c
$(CLANG) test.c -fdata-sections -ffunction-sections -I${HEADERS} target-panic-abort/x86_64-unknown-linux-gnu/release/libicu_capi.a -g -o 5-panic-abort-clang-stripped.elf -Wl,--gc-sections -Wl,--strip-all

# optim3.elf: clang two-step with lld, debug mode
optim3.elf: optim3.o target/x86_64-unknown-linux-gnu/debug/libicu_capi.a
$(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim3.elf optim3.o target/x86_64-unknown-linux-gnu/debug/libicu_capi.a -Wl,--gc-sections

optim4.o: $(ALL_HEADERS) test.c
$(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -I${HEADERS} -g -o optim4.o
# clang with LTO, gc-sections, stripping, rust with release, LTO, panic-abort (std panic-immediate-abort)
6-panic-abort-lto-clang-stripped.elf: target-panic-abort-lto/x86_64-unknown-linux-gnu/release/libicu_capi.a $(ALL_HEADERS) test.c
$(CLANG) -flto=thin -fuse-ld=$(LLD) -fdata-sections -ffunction-sections test.c -I${HEADERS} target-panic-abort-lto/x86_64-unknown-linux-gnu/release/libicu_capi.a -g -o 6-panic-abort-lto-clang-stripped.elf -Wl,--gc-sections -Wl,--strip-all

# optim4.elf: clang two-step with lld, release mode with debug symbols
optim4.elf: optim4.o target/x86_64-unknown-linux-gnu/release/libicu_capi.a
$(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim4.elf optim4.o target/x86_64-unknown-linux-gnu/release/libicu_capi.a -Wl,--gc-sections

optim5.o: $(ALL_HEADERS) test.c
$(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -I${HEADERS} -o optim5.o
# clang with lld, ThinLTO, gc-sections, stripping, rust with release, LTO, panic-abort (std panic-immediate-abort), with cross-compiler LTO
7-panic-abort-linker-plugin-lto-clang-stripped.elf: target-panic-abort-linker-plugin-lto/x86_64-unknown-linux-gnu/release/libicu_capi.a
$(CLANG) -flto=thin -fuse-ld=$(LLD) --target=x86_64-unknown-linux-gnu test.c -I${HEADERS} -o 7-panic-abort-linker-plugin-lto-clang-stripped.elf target-panic-abort-linker-plugin-lto/x86_64-unknown-linux-gnu/release/libicu_capi.a -Wl,--gc-sections -Wl,--strip-all

# optim5.elf: clang two-step with lld, release mode stripped of debug symbols
optim5.elf: optim5.o target/x86_64-unknown-linux-gnu/release/libicu_capi.a
$(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim5.elf optim5.o target/x86_64-unknown-linux-gnu/release/libicu_capi.a -Wl,--gc-sections -Wl,--strip-all

build: optim0.elf optim1.elf optim2.elf optim3.elf optim4.elf optim5.elf
ls -l optim*.elf
build: 1-release.elf 2-release-gcc-stripped.elf 3-panic-abort-clang.elf 4-panic-abort-lto-clang.elf 5-panic-abort-clang-stripped.elf 6-panic-abort-lto-clang-stripped.elf 7-panic-abort-linker-plugin-lto-clang-stripped.elf
ls -l *.elf

test: build
./optim0.elf bn
./optim1.elf bn
./optim2.elf bn
./optim2.elf bn
./optim4.elf bn
./optim5.elf bn
./1-release.elf bn
./2-release-gcc-stripped.elf bn
./3-panic-abort-clang.elf bn
./4-panic-abort-lto-clang.elf bn
./5-panic-abort-clang-stripped.elf bn
./6-panic-abort-lto-clang-stripped.elf bn
./7-panic-abort-linker-plugin-lto-clang-stripped.elf bn

clean:
git clean -xf *
Loading
Loading