-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from itzmeanjan/major-api-refactor
Prefer `std::span` over raw pointer based interfaces
- Loading branch information
Showing
26 changed files
with
823 additions
and
714 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,64 @@ | ||
CXX = g++ | ||
CXX = clang++ | ||
CXX_FLAGS = -std=c++20 | ||
WARN_FLAGS = -Wall -Wextra -pedantic | ||
OPT_FLAGS = -O3 -march=native -mtune=native | ||
IFLAGS = -I ./include | ||
OPT_FLAGS = -O3 -march=native | ||
LINK_FLAGS = -flto | ||
I_FLAGS = -I ./include | ||
DEP_IFLAGS = -I ./sha3/include -I ./subtle/include | ||
|
||
all: test | ||
|
||
tests/test_compression.o: tests/test_compression.cpp include/*.hpp | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(IFLAGS) $(DEP_IFLAGS) -c $< -o $@ | ||
SRC_DIR = include | ||
KYBER_SOURCES := $(wildcard $(SRC_DIR)/*.hpp) | ||
BUILD_DIR = build | ||
|
||
tests/test_field.o: tests/test_field.cpp include/*.hpp | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(IFLAGS) $(DEP_IFLAGS) -c $< -o $@ | ||
TEST_DIR = tests | ||
TEST_SOURCES := $(wildcard $(TEST_DIR)/*.cpp) | ||
TEST_OBJECTS := $(addprefix $(BUILD_DIR)/, $(notdir $(patsubst %.cpp,%.o,$(TEST_SOURCES)))) | ||
TEST_LINK_FLAGS = -lgtest -lgtest_main | ||
TEST_BINARY = $(BUILD_DIR)/test.out | ||
|
||
tests/test_kem_kat.o: tests/test_kem_kat.cpp include/*.hpp | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(IFLAGS) $(DEP_IFLAGS) -c $< -o $@ | ||
BENCHMARK_DIR = benchmarks | ||
BENCHMARK_SOURCES := $(wildcard $(BENCHMARK_DIR)/*.cpp) | ||
BENCHMARK_OBJECTS := $(addprefix $(BUILD_DIR)/, $(notdir $(patsubst %.cpp,%.o,$(BENCHMARK_SOURCES)))) | ||
BENCHMARK_LINK_FLAGS = -lbenchmark -lbenchmark_main -lpthread | ||
BENCHMARK_BINARY = $(BUILD_DIR)/bench.out | ||
PERF_LINK_FLAGS = -lbenchmark -lbenchmark_main -lpfm -lpthread | ||
PERF_BINARY = $(BUILD_DIR)/perf.out | ||
|
||
tests/test_kem.o: tests/test_kem.cpp include/*.hpp | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(IFLAGS) $(DEP_IFLAGS) -c $< -o $@ | ||
all: test | ||
|
||
tests/test_ntt.o: tests/test_ntt.cpp include/*.hpp | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(IFLAGS) $(DEP_IFLAGS) -c $< -o $@ | ||
$(BUILD_DIR): | ||
mkdir -p $@ | ||
|
||
tests/test_serialize.o: tests/test_serialize.cpp include/*.hpp | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(IFLAGS) $(DEP_IFLAGS) -c $< -o $@ | ||
$(BUILD_DIR)/%.o: $(TEST_DIR)/%.cpp $(BUILD_DIR) | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(I_FLAGS) $(DEP_IFLAGS) -c $< -o $@ | ||
|
||
tests/a.out: tests/test_compression.o tests/test_field.o tests/test_kem_kat.o tests/test_kem.o \ | ||
tests/test_ntt.o tests/test_serialize.o | ||
$(CXX) $(OPT_FLAGS) $^ -lgtest -lgtest_main -o $@ | ||
$(TEST_BINARY): $(TEST_OBJECTS) | ||
$(CXX) $(OPT_FLAGS) $(LINK_FLAGS) $^ $(TEST_LINK_FLAGS) -o $@ | ||
|
||
test: tests/a.out | ||
test: $(TEST_BINARY) | ||
./$< | ||
|
||
benchmarks/bench.out: benchmarks/main.cpp include/*.hpp sha3/include/*.hpp subtle/include/*.hpp | ||
# In case you haven't built google-benchmark with libPFM support. | ||
# More @ https://gist.github.com/itzmeanjan/05dc3e946f635d00c5e0b21aae6203a7 | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(IFLAGS) $(DEP_IFLAGS) $< -lbenchmark -lpthread -o $@ | ||
$(BUILD_DIR)/%.o: $(BENCHMARK_DIR)/%.cpp $(BUILD_DIR) | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(I_FLAGS) $(DEP_IFLAGS) -c $< -o $@ | ||
|
||
$(BENCHMARK_BINARY): $(BENCHMARK_OBJECTS) | ||
$(CXX) $(OPT_FLAGS) $(LINK_FLAGS) $^ $(BENCHMARK_LINK_FLAGS) -o $@ | ||
|
||
benchmark: $(BENCHMARK_BINARY) | ||
# Must *not* build google-benchmark with libPFM | ||
./$< --benchmark_time_unit=us --benchmark_min_warmup_time=.5 --benchmark_enable_random_interleaving=true --benchmark_repetitions=8 --benchmark_min_time=0.1s --benchmark_display_aggregates_only=true --benchmark_counters_tabular=true | ||
|
||
benchmark: benchmarks/bench.out | ||
./$< --benchmark_time_unit=us --benchmark_counters_tabular=true | ||
$(PERF_BINARY): $(BENCHMARK_OBJECTS) | ||
$(CXX) $(OPT_FLAGS) $(LINK_FLAGS) $^ $(PERF_LINK_FLAGS) -o $@ | ||
|
||
benchmarks/perf.out: benchmarks/main.cpp include/*.hpp sha3/include/*.hpp subtle/include/*.hpp | ||
# In case you've built google-benchmark with libPFM support. | ||
# More @ https://gist.github.com/itzmeanjan/05dc3e946f635d00c5e0b21aae6203a7 | ||
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(IFLAGS) $(DEP_IFLAGS) $< -lbenchmark -lpthread -lpfm -o $@ | ||
perf: $(PERF_BINARY) | ||
# Must build google-benchmark with libPFM, follow https://gist.github.com/itzmeanjan/05dc3e946f635d00c5e0b21aae6203a7 | ||
./$< --benchmark_time_unit=us --benchmark_min_warmup_time=.5 --benchmark_enable_random_interleaving=true --benchmark_repetitions=8 --benchmark_min_time=0.1s --benchmark_display_aggregates_only=true --benchmark_counters_tabular=true --benchmark_perf_counters=CYCLES | ||
|
||
perf: benchmarks/perf.out | ||
./$< --benchmark_time_unit=us --benchmark_counters_tabular=true --benchmark_perf_counters=CYCLES | ||
.PHONY: format clean | ||
|
||
clean: | ||
find . -name '*.out' -o -name '*.o' -o -name '*.so' -o -name '*.gch' | xargs rm -rf | ||
rm -rf $(BUILD_DIR) | ||
|
||
format: | ||
find . -name '*.hpp' -o -name '*.cpp' -o -name '*.hpp' | xargs clang-format -i --style=Mozilla | ||
format: $(KYBER_SOURCES) $(TEST_SOURCES) $(BENCHMARK_SOURCES) | ||
clang-format -i --style=Mozilla $^ |
Oops, something went wrong.