Skip to content

Measure code-size #1089

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

Merged
merged 1 commit into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 27 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
bench_components_512 bench_components_768 bench_components_1024 bench_components \
run_bench_components_512 run_bench_components_768 run_bench_components_1024 run_bench_components \
build test all \
clean quickcheck check-defined-CYCLES
clean quickcheck check-defined-CYCLES \
size_512 size_768 size_1024 size \
run_size_512 run_size_768 run_size_1024 run_size

.DEFAULT_GOAL := build
all: build
Expand Down Expand Up @@ -142,6 +144,30 @@ run_bench_components: \
run_bench_components_768 .WAIT\
run_bench_components_1024


size_512: $(BUILD_DIR)/libmlkem512.a
size_768: $(BUILD_DIR)/libmlkem768.a
size_1024: $(BUILD_DIR)/libmlkem1024.a
size: size_512 size_768 size_1024

run_size_512: size_512
$(Q)echo "size $(BUILD_DIR)/libmlkem512.a"
$(Q)$(SIZE) $(BUILD_DIR)/libmlkem512.a | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)

run_size_768: size_768
$(Q)echo "size $(BUILD_DIR)/libmlkem768.a"
$(Q)$(SIZE) $(BUILD_DIR)/libmlkem768.a | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)

run_size_1024: size_1024
$(Q)echo "size $(BUILD_DIR)/libmlkem1024.a"
$(Q)$(SIZE) $(BUILD_DIR)/libmlkem1024.a | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)


run_size: \
run_size_512 \
run_size_768 \
run_size_1024

clean:
-$(RM) -rf *.gcno *.gcda *.lcov *.o *.so
-$(RM) -rf $(BUILD_DIR)
Expand Down
17 changes: 15 additions & 2 deletions examples/basic/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# (SPDX-License-Identifier: CC-BY-4.0)

.PHONY: build run clean
.PHONY: build run clean size
.DEFAULT_GOAL := all

# Append cross-prefix for cross compilation
# Remove or ignore for native builds
CC ?= gcc
SIZE ?= size
# When called from the root Makefile, CROSS_PREFIX has already been added here
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
CC := $(CROSS_PREFIX)$(CC)
endif

ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
SIZE := $(CROSS_PREFIX)$(SIZE)
endif

# Part A:
#
# mlkem-native source and header files
Expand Down Expand Up @@ -80,7 +85,7 @@ $(BINARIES_FULL): $(ALL_SOURCE)
mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) $^ -o $@

all: build
all: build size

build: $(BINARIES_FULL)

Expand All @@ -89,5 +94,13 @@ run: $(BINARIES_FULL)
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_768)
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_1024)

size: build
@echo "=== Size info for $(BINARY_NAME_FULL_512) ==="
@$(SIZE) $(BINARY_NAME_FULL_512)
@echo "=== Size info for $(BINARY_NAME_FULL_768) ==="
@$(SIZE) $(BINARY_NAME_FULL_768)
@echo "=== Size info for $(BINARY_NAME_FULL_1024) ==="
@$(SIZE) $(BINARY_NAME_FULL_1024)

clean:
rm -rf $(BUILD_DIR)
17 changes: 15 additions & 2 deletions examples/bring_your_own_fips202/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# (SPDX-License-Identifier: CC-BY-4.0)

.PHONY: build run clean
.PHONY: build run clean size
.DEFAULT_GOAL := all

# Append cross-prefix for cross compilation
# Remove or ignore for native builds
CC ?= gcc
SIZE ?= size
# When called from the root Makefile, CROSS_PREFIX has already been added here
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
CC := $(CROSS_PREFIX)$(CC)
endif

ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
SIZE := $(CROSS_PREFIX)$(SIZE)
endif

# Part A:
#
# mlkem-native source and header files
Expand Down Expand Up @@ -87,7 +92,7 @@ $(BINARIES_FULL): $(ALL_SOURCE)
mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) $(INC) $^ -o $@

all: build
all: build size

build: $(BINARIES_FULL)

Expand All @@ -96,5 +101,13 @@ run: $(BINARIES_FULL)
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_768)
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_1024)

size: build
@echo "=== Size info for binaries $(BINARY_NAME_FULL_512) ==="
@$(SIZE) $(BINARY_NAME_FULL_512)
@echo "=== Size info for binaries $(BINARY_NAME_FULL_768) ==="
@$(SIZE) $(BINARY_NAME_FULL_768)
@echo "=== Size info for binaries $(BINARY_NAME_FULL_1024) ==="
@$(SIZE) $(BINARY_NAME_FULL_1024)

clean:
rm -rf $(BUILD_DIR)
17 changes: 15 additions & 2 deletions examples/custom_backend/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# (SPDX-License-Identifier: CC-BY-4.0)

.PHONY: build run clean
.PHONY: build run clean size
.DEFAULT_GOAL := all

# Append cross-prefix for cross compilation
# Remove or ignore for native builds
CC ?= gcc
SIZE ?= size
# When called from the root Makefile, CROSS_PREFIX has already been added here
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
CC := $(CROSS_PREFIX)$(CC)
endif

ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
SIZE := $(CROSS_PREFIX)$(SIZE)
endif

# Part A:
#
# mlkem-native source and header files
Expand Down Expand Up @@ -83,7 +88,7 @@ $(BINARIES_FULL): $(ALL_SOURCE)
mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) $(INC) $^ -o $@

all: build
all: build size

build: $(BINARIES_FULL)

Expand All @@ -92,5 +97,13 @@ run: $(BINARIES_FULL)
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_768)
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_1024)

size: build
@echo "=== Size info for binaries $(BINARY_NAME_FULL_512) ==="
@$(SIZE) $(BINARY_NAME_FULL_512)
@echo "=== Size info for binaries $(BINARY_NAME_FULL_768) ==="
@$(SIZE) $(BINARY_NAME_FULL_768)
@echo "=== Size info for binaries $(BINARY_NAME_FULL_1024) ==="
@$(SIZE) $(BINARY_NAME_FULL_1024)

clean:
rm -rf $(BUILD_DIR)
15 changes: 13 additions & 2 deletions examples/monolithic_build/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# (SPDX-License-Identifier: CC-BY-4.0)

.PHONY: build run clean
.PHONY: build run clean size
.DEFAULT_GOAL := all

# Append cross-prefix for cross compilation
# Remove or ignore for native builds
CC ?= gcc
AR ?= ar
SIZE ?= size
# When called from the root Makefile, CROSS_PREFIX has already been added here
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
CC := $(CROSS_PREFIX)$(CC)
Expand All @@ -16,6 +17,10 @@ ifeq (,$(findstring $(CROSS_PREFIX),$(AR)))
AR := $(CROSS_PREFIX)$(AR)
endif

ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
SIZE := $(CROSS_PREFIX)$(SIZE)
endif

Q ?= @

# Part A:
Expand Down Expand Up @@ -116,7 +121,7 @@ $(BIN1024_FULL): $(APP_SOURCE) $(LIB1024_FULL)
$(Q)[ -d $(@) ] || mkdir -p $(@D)
$(Q)$(CC) $(CFLAGS) -DMLK_CONFIG_API_PARAMETER_SET=1024 $(INC) $^ -o $@

all: build
all: build size

build: $(BIN512_FULL) $(BIN768_FULL) $(BIN1024_FULL)

Expand All @@ -125,5 +130,11 @@ run: $(BIN512_FULL) $(BIN768_FULL) $(BIN1024_FULL)
$(Q)$(EXEC_WRAPPER) ./$(BIN768_FULL)
$(Q)$(EXEC_WRAPPER) ./$(BIN1024_FULL)

size: build
@echo "=== Size info for static libs ==="
@$(Q)$(SIZE) $(LIB512_FULL)
@$(Q)$(SIZE) $(LIB768_FULL)
@$(Q)$(SIZE) $(LIB1024_FULL)

clean:
rm -rf $(BUILD_DIR)
15 changes: 13 additions & 2 deletions examples/monolithic_build_multilevel/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# (SPDX-License-Identifier: CC-BY-4.0)

.PHONY: build run clean
.PHONY: build run clean size
.DEFAULT_GOAL := all

# Append cross-prefix for cross compilation
# Remove or ignore for native builds
CC ?= gcc
AR ?= ar
SIZE ?= size
Q ?= @
# When called from the root Makefile, CROSS_PREFIX has already been added here
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
CC := $(CROSS_PREFIX)$(CC)
Expand All @@ -16,6 +18,11 @@ ifeq (,$(findstring $(CROSS_PREFIX),$(AR)))
AR := $(CROSS_PREFIX)$(AR)
endif

ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
SIZE := $(CROSS_PREFIX)$(SIZE)
endif


# Part A:
#
# mlkem-native source and header files
Expand Down Expand Up @@ -80,12 +87,16 @@ $(BINARY_NAME_FULL): $(APP_SOURCE) $(LIB_NAME_FULL)
mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) $(INC) $^ -o $@

all: build
all: build size

build: $(BINARY_NAME_FULL)

run: $(BINARY_NAME_FULL)
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL)

size: build
$(Q)echo "=== Size info for static lib ==="
$(Q)$(SIZE) ${LIB_NAME_FULL}

clean:
rm -rf $(BUILD_DIR)
15 changes: 13 additions & 2 deletions examples/monolithic_build_multilevel_native/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# (SPDX-License-Identifier: CC-BY-4.0)

.PHONY: build run clean
.PHONY: build run clean size
.DEFAULT_GOAL := all

# Append cross-prefix for cross compilation
# Remove or ignore for native builds
CC ?= gcc
AR ?= ar
SIZE ?= size
# When called from the root Makefile, CROSS_PREFIX has already been added here
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
CC := $(CROSS_PREFIX)$(CC)
Expand All @@ -16,6 +17,10 @@ ifeq (,$(findstring $(CROSS_PREFIX),$(AR)))
AR := $(CROSS_PREFIX)$(AR)
endif

ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
SIZE := $(CROSS_PREFIX)$(SIZE)
endif

# Part A:
#
# mlkem-native source and header files
Expand Down Expand Up @@ -123,12 +128,18 @@ $(BINARY_NAME_FULL): $(APP_SOURCE) $(MLK_OBJ_ASM)
$(Q)$(CC) $(CFLAGS) $(INC) $^ -o $@
$(Q)strip -S $@

all: build
all: build size

build: $(BINARY_NAME_FULL)

run: $(BINARY_NAME_FULL)
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL)

size: build
$(Q)echo "=== Size info for binaries $(BINARY_NAME_FULL)==="
$(Q)$(SIZE) $(BINARY_NAME_FULL)
$(Q)echo " "


clean:
rm -rf $(BUILD_DIR)
16 changes: 13 additions & 3 deletions examples/monolithic_build_native/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# (SPDX-License-Identifier: CC-BY-4.0)

.PHONY: build run clean
.PHONY: build run clean size
.DEFAULT_GOAL := all

# Append cross-prefix for cross compilation
# Remove or ignore for native builds
CC ?= gcc
AR ?= ar
SIZE ?= size
# When called from the root Makefile, CROSS_PREFIX has already been added here
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
CC := $(CROSS_PREFIX)$(CC)
Expand All @@ -16,8 +17,11 @@ ifeq (,$(findstring $(CROSS_PREFIX),$(AR)))
AR := $(CROSS_PREFIX)$(AR)
endif

Q ?= @
ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
SIZE := $(CROSS_PREFIX)$(SIZE)
endif

Q ?= @
# Part A:
#
# mlkem-native source and header files
Expand Down Expand Up @@ -129,7 +133,7 @@ $(BIN1024_FULL): $(APP_SOURCE) $(LIB1024_FULL)
$(Q)[ -d $(@) ] || mkdir -p $(@D)
$(Q)$(CC) $(CFLAGS) -DMLK_CONFIG_API_PARAMETER_SET=1024 $(INC) $^ -o $@

all: build
all: build size

build: $(BIN512_FULL) $(BIN768_FULL) $(BIN1024_FULL)

Expand All @@ -138,5 +142,11 @@ run: $(BIN512_FULL) $(BIN768_FULL) $(BIN1024_FULL)
$(Q)$(EXEC_WRAPPER) ./$(BIN768_FULL)
$(Q)$(EXEC_WRAPPER) ./$(BIN1024_FULL)

size: build
@echo "=== Size info for static libs ==="
$(Q)$(SIZE) $(LIB512_FULL) | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)
$(Q)$(SIZE) $(LIB768_FULL) | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)
$(Q)$(SIZE) $(LIB1024_FULL) | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)

clean:
rm -rf $(BUILD_DIR)
Loading