Skip to content

Commit ef6dfe4

Browse files
authored
Merge pull request #1089 from pq-code-package/measure-code-size
Measure code-size
2 parents 24fcceb + d1b33b0 commit ef6dfe4

File tree

11 files changed

+193
-20
lines changed

11 files changed

+193
-20
lines changed

Makefile

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
bench_components_512 bench_components_768 bench_components_1024 bench_components \
1515
run_bench_components_512 run_bench_components_768 run_bench_components_1024 run_bench_components \
1616
build test all \
17-
clean quickcheck check-defined-CYCLES
17+
clean quickcheck check-defined-CYCLES \
18+
size_512 size_768 size_1024 size \
19+
run_size_512 run_size_768 run_size_1024 run_size
1820

1921
.DEFAULT_GOAL := build
2022
all: build
@@ -142,6 +144,30 @@ run_bench_components: \
142144
run_bench_components_768 .WAIT\
143145
run_bench_components_1024
144146

147+
148+
size_512: $(BUILD_DIR)/libmlkem512.a
149+
size_768: $(BUILD_DIR)/libmlkem768.a
150+
size_1024: $(BUILD_DIR)/libmlkem1024.a
151+
size: size_512 size_768 size_1024
152+
153+
run_size_512: size_512
154+
$(Q)echo "size $(BUILD_DIR)/libmlkem512.a"
155+
$(Q)$(SIZE) $(BUILD_DIR)/libmlkem512.a | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)
156+
157+
run_size_768: size_768
158+
$(Q)echo "size $(BUILD_DIR)/libmlkem768.a"
159+
$(Q)$(SIZE) $(BUILD_DIR)/libmlkem768.a | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)
160+
161+
run_size_1024: size_1024
162+
$(Q)echo "size $(BUILD_DIR)/libmlkem1024.a"
163+
$(Q)$(SIZE) $(BUILD_DIR)/libmlkem1024.a | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)
164+
165+
166+
run_size: \
167+
run_size_512 \
168+
run_size_768 \
169+
run_size_1024
170+
145171
clean:
146172
-$(RM) -rf *.gcno *.gcda *.lcov *.o *.so
147173
-$(RM) -rf $(BUILD_DIR)

examples/basic/Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# (SPDX-License-Identifier: CC-BY-4.0)
22

3-
.PHONY: build run clean
3+
.PHONY: build run clean size
44
.DEFAULT_GOAL := all
55

66
# Append cross-prefix for cross compilation
77
# Remove or ignore for native builds
88
CC ?= gcc
9+
SIZE ?= size
910
# When called from the root Makefile, CROSS_PREFIX has already been added here
1011
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
1112
CC := $(CROSS_PREFIX)$(CC)
1213
endif
1314

15+
ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
16+
SIZE := $(CROSS_PREFIX)$(SIZE)
17+
endif
18+
1419
# Part A:
1520
#
1621
# mlkem-native source and header files
@@ -80,7 +85,7 @@ $(BINARIES_FULL): $(ALL_SOURCE)
8085
mkdir -p $(BUILD_DIR)
8186
$(CC) $(CFLAGS) $^ -o $@
8287

83-
all: build
88+
all: build size
8489

8590
build: $(BINARIES_FULL)
8691

@@ -89,5 +94,13 @@ run: $(BINARIES_FULL)
8994
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_768)
9095
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_1024)
9196

97+
size: build
98+
@echo "=== Size info for $(BINARY_NAME_FULL_512) ==="
99+
@$(SIZE) $(BINARY_NAME_FULL_512)
100+
@echo "=== Size info for $(BINARY_NAME_FULL_768) ==="
101+
@$(SIZE) $(BINARY_NAME_FULL_768)
102+
@echo "=== Size info for $(BINARY_NAME_FULL_1024) ==="
103+
@$(SIZE) $(BINARY_NAME_FULL_1024)
104+
92105
clean:
93106
rm -rf $(BUILD_DIR)

examples/bring_your_own_fips202/Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# (SPDX-License-Identifier: CC-BY-4.0)
22

3-
.PHONY: build run clean
3+
.PHONY: build run clean size
44
.DEFAULT_GOAL := all
55

66
# Append cross-prefix for cross compilation
77
# Remove or ignore for native builds
88
CC ?= gcc
9+
SIZE ?= size
910
# When called from the root Makefile, CROSS_PREFIX has already been added here
1011
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
1112
CC := $(CROSS_PREFIX)$(CC)
1213
endif
1314

15+
ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
16+
SIZE := $(CROSS_PREFIX)$(SIZE)
17+
endif
18+
1419
# Part A:
1520
#
1621
# mlkem-native source and header files
@@ -87,7 +92,7 @@ $(BINARIES_FULL): $(ALL_SOURCE)
8792
mkdir -p $(BUILD_DIR)
8893
$(CC) $(CFLAGS) $(INC) $^ -o $@
8994

90-
all: build
95+
all: build size
9196

9297
build: $(BINARIES_FULL)
9398

@@ -96,5 +101,13 @@ run: $(BINARIES_FULL)
96101
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_768)
97102
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_1024)
98103

104+
size: build
105+
@echo "=== Size info for binaries $(BINARY_NAME_FULL_512) ==="
106+
@$(SIZE) $(BINARY_NAME_FULL_512)
107+
@echo "=== Size info for binaries $(BINARY_NAME_FULL_768) ==="
108+
@$(SIZE) $(BINARY_NAME_FULL_768)
109+
@echo "=== Size info for binaries $(BINARY_NAME_FULL_1024) ==="
110+
@$(SIZE) $(BINARY_NAME_FULL_1024)
111+
99112
clean:
100113
rm -rf $(BUILD_DIR)

examples/custom_backend/Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# (SPDX-License-Identifier: CC-BY-4.0)
22

3-
.PHONY: build run clean
3+
.PHONY: build run clean size
44
.DEFAULT_GOAL := all
55

66
# Append cross-prefix for cross compilation
77
# Remove or ignore for native builds
88
CC ?= gcc
9+
SIZE ?= size
910
# When called from the root Makefile, CROSS_PREFIX has already been added here
1011
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
1112
CC := $(CROSS_PREFIX)$(CC)
1213
endif
1314

15+
ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
16+
SIZE := $(CROSS_PREFIX)$(SIZE)
17+
endif
18+
1419
# Part A:
1520
#
1621
# mlkem-native source and header files
@@ -83,7 +88,7 @@ $(BINARIES_FULL): $(ALL_SOURCE)
8388
mkdir -p $(BUILD_DIR)
8489
$(CC) $(CFLAGS) $(INC) $^ -o $@
8590

86-
all: build
91+
all: build size
8792

8893
build: $(BINARIES_FULL)
8994

@@ -92,5 +97,13 @@ run: $(BINARIES_FULL)
9297
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_768)
9398
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL_1024)
9499

100+
size: build
101+
@echo "=== Size info for binaries $(BINARY_NAME_FULL_512) ==="
102+
@$(SIZE) $(BINARY_NAME_FULL_512)
103+
@echo "=== Size info for binaries $(BINARY_NAME_FULL_768) ==="
104+
@$(SIZE) $(BINARY_NAME_FULL_768)
105+
@echo "=== Size info for binaries $(BINARY_NAME_FULL_1024) ==="
106+
@$(SIZE) $(BINARY_NAME_FULL_1024)
107+
95108
clean:
96109
rm -rf $(BUILD_DIR)

examples/monolithic_build/Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# (SPDX-License-Identifier: CC-BY-4.0)
22

3-
.PHONY: build run clean
3+
.PHONY: build run clean size
44
.DEFAULT_GOAL := all
55

66
# Append cross-prefix for cross compilation
77
# Remove or ignore for native builds
88
CC ?= gcc
99
AR ?= ar
10+
SIZE ?= size
1011
# When called from the root Makefile, CROSS_PREFIX has already been added here
1112
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
1213
CC := $(CROSS_PREFIX)$(CC)
@@ -16,6 +17,10 @@ ifeq (,$(findstring $(CROSS_PREFIX),$(AR)))
1617
AR := $(CROSS_PREFIX)$(AR)
1718
endif
1819

20+
ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
21+
SIZE := $(CROSS_PREFIX)$(SIZE)
22+
endif
23+
1924
Q ?= @
2025

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

119-
all: build
124+
all: build size
120125

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

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

133+
size: build
134+
@echo "=== Size info for static libs ==="
135+
@$(Q)$(SIZE) $(LIB512_FULL)
136+
@$(Q)$(SIZE) $(LIB768_FULL)
137+
@$(Q)$(SIZE) $(LIB1024_FULL)
138+
128139
clean:
129140
rm -rf $(BUILD_DIR)

examples/monolithic_build_multilevel/Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# (SPDX-License-Identifier: CC-BY-4.0)
22

3-
.PHONY: build run clean
3+
.PHONY: build run clean size
44
.DEFAULT_GOAL := all
55

66
# Append cross-prefix for cross compilation
77
# Remove or ignore for native builds
88
CC ?= gcc
99
AR ?= ar
10+
SIZE ?= size
11+
Q ?= @
1012
# When called from the root Makefile, CROSS_PREFIX has already been added here
1113
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
1214
CC := $(CROSS_PREFIX)$(CC)
@@ -16,6 +18,11 @@ ifeq (,$(findstring $(CROSS_PREFIX),$(AR)))
1618
AR := $(CROSS_PREFIX)$(AR)
1719
endif
1820

21+
ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
22+
SIZE := $(CROSS_PREFIX)$(SIZE)
23+
endif
24+
25+
1926
# Part A:
2027
#
2128
# mlkem-native source and header files
@@ -80,12 +87,16 @@ $(BINARY_NAME_FULL): $(APP_SOURCE) $(LIB_NAME_FULL)
8087
mkdir -p $(BUILD_DIR)
8188
$(CC) $(CFLAGS) $(INC) $^ -o $@
8289

83-
all: build
90+
all: build size
8491

8592
build: $(BINARY_NAME_FULL)
8693

8794
run: $(BINARY_NAME_FULL)
8895
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL)
8996

97+
size: build
98+
$(Q)echo "=== Size info for static lib ==="
99+
$(Q)$(SIZE) ${LIB_NAME_FULL}
100+
90101
clean:
91102
rm -rf $(BUILD_DIR)

examples/monolithic_build_multilevel_native/Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# (SPDX-License-Identifier: CC-BY-4.0)
22

3-
.PHONY: build run clean
3+
.PHONY: build run clean size
44
.DEFAULT_GOAL := all
55

66
# Append cross-prefix for cross compilation
77
# Remove or ignore for native builds
88
CC ?= gcc
99
AR ?= ar
10+
SIZE ?= size
1011
# When called from the root Makefile, CROSS_PREFIX has already been added here
1112
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
1213
CC := $(CROSS_PREFIX)$(CC)
@@ -16,6 +17,10 @@ ifeq (,$(findstring $(CROSS_PREFIX),$(AR)))
1617
AR := $(CROSS_PREFIX)$(AR)
1718
endif
1819

20+
ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
21+
SIZE := $(CROSS_PREFIX)$(SIZE)
22+
endif
23+
1924
# Part A:
2025
#
2126
# mlkem-native source and header files
@@ -123,12 +128,18 @@ $(BINARY_NAME_FULL): $(APP_SOURCE) $(MLK_OBJ_ASM)
123128
$(Q)$(CC) $(CFLAGS) $(INC) $^ -o $@
124129
$(Q)strip -S $@
125130

126-
all: build
131+
all: build size
127132

128133
build: $(BINARY_NAME_FULL)
129134

130135
run: $(BINARY_NAME_FULL)
131136
$(EXEC_WRAPPER) ./$(BINARY_NAME_FULL)
132137

138+
size: build
139+
$(Q)echo "=== Size info for binaries $(BINARY_NAME_FULL)==="
140+
$(Q)$(SIZE) $(BINARY_NAME_FULL)
141+
$(Q)echo " "
142+
143+
133144
clean:
134145
rm -rf $(BUILD_DIR)

examples/monolithic_build_native/Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# (SPDX-License-Identifier: CC-BY-4.0)
22

3-
.PHONY: build run clean
3+
.PHONY: build run clean size
44
.DEFAULT_GOAL := all
55

66
# Append cross-prefix for cross compilation
77
# Remove or ignore for native builds
88
CC ?= gcc
99
AR ?= ar
10+
SIZE ?= size
1011
# When called from the root Makefile, CROSS_PREFIX has already been added here
1112
ifeq (,$(findstring $(CROSS_PREFIX),$(CC)))
1213
CC := $(CROSS_PREFIX)$(CC)
@@ -16,8 +17,11 @@ ifeq (,$(findstring $(CROSS_PREFIX),$(AR)))
1617
AR := $(CROSS_PREFIX)$(AR)
1718
endif
1819

19-
Q ?= @
20+
ifeq (,$(findstring $(CROSS_PREFIX),$(SIZE)))
21+
SIZE := $(CROSS_PREFIX)$(SIZE)
22+
endif
2023

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

132-
all: build
136+
all: build size
133137

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

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

145+
size: build
146+
@echo "=== Size info for static libs ==="
147+
$(Q)$(SIZE) $(LIB512_FULL) | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)
148+
$(Q)$(SIZE) $(LIB768_FULL) | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)
149+
$(Q)$(SIZE) $(LIB1024_FULL) | (read header; echo "$$header"; awk '$$5 != 0' | sort -k5 -n -r)
150+
141151
clean:
142152
rm -rf $(BUILD_DIR)

0 commit comments

Comments
 (0)