From 49dab5622b31421eb6af84eae376d73fae1cd4a0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 16 Sep 2022 15:39:48 -0400 Subject: Switch to meson build system --- .gitignore | 1 + Makefile | 99 ------ benchmark/bench_bitvec.cpp | 352 ++++++++++++++++++++ benchmark/bench_hilbert.cpp | 113 +++++++ benchmark/bench_utils.hpp | 64 ++++ bin/chilbert_obj.cpp | 54 ---- bin/chilbert_svg.cpp | 63 ---- chilbert/BoundedBitVec.hpp | 125 ------- chilbert/DynamicBitVec.hpp | 157 --------- chilbert/SmallBitVec.hpp | 378 ---------------------- chilbert/StaticBitVec.hpp | 120 ------- chilbert/chilbert.hpp | 96 ------ chilbert/chilbert.ipp | 502 ----------------------------- chilbert/detail/BitVecIndex.hpp | 51 --- chilbert/detail/BitVecIterator.hpp | 100 ------ chilbert/detail/BitVecMask.hpp | 74 ----- chilbert/detail/MultiBitVec.hpp | 387 ---------------------- chilbert/detail/gray_code_rank.hpp | 182 ----------- chilbert/detail/operations.hpp | 169 ---------- chilbert/detail/traits.hpp | 39 --- chilbert/operators.hpp | 96 ------ include/chilbert/BoundedBitVec.hpp | 125 +++++++ include/chilbert/DynamicBitVec.hpp | 157 +++++++++ include/chilbert/SmallBitVec.hpp | 378 ++++++++++++++++++++++ include/chilbert/StaticBitVec.hpp | 120 +++++++ include/chilbert/chilbert.hpp | 96 ++++++ include/chilbert/chilbert.ipp | 502 +++++++++++++++++++++++++++++ include/chilbert/detail/BitVecIndex.hpp | 51 +++ include/chilbert/detail/BitVecIterator.hpp | 100 ++++++ include/chilbert/detail/BitVecMask.hpp | 74 +++++ include/chilbert/detail/MultiBitVec.hpp | 387 ++++++++++++++++++++++ include/chilbert/detail/gray_code_rank.hpp | 182 +++++++++++ include/chilbert/detail/operations.hpp | 169 ++++++++++ include/chilbert/detail/traits.hpp | 39 +++ include/chilbert/operators.hpp | 96 ++++++ meson.build | 150 +++++++++ meson/warnings/meson.build | 196 +++++++++++ meson_options.txt | 8 + src/chilbert_obj.cpp | 54 ++++ src/chilbert_svg.cpp | 63 ++++ test/bench_bitvec.cpp | 352 -------------------- test/bench_hilbert.cpp | 113 ------- test/bench_utils.hpp | 64 ---- 43 files changed, 3477 insertions(+), 3221 deletions(-) create mode 100644 .gitignore delete mode 100644 Makefile create mode 100644 benchmark/bench_bitvec.cpp create mode 100644 benchmark/bench_hilbert.cpp create mode 100644 benchmark/bench_utils.hpp delete mode 100644 bin/chilbert_obj.cpp delete mode 100644 bin/chilbert_svg.cpp delete mode 100644 chilbert/BoundedBitVec.hpp delete mode 100644 chilbert/DynamicBitVec.hpp delete mode 100644 chilbert/SmallBitVec.hpp delete mode 100644 chilbert/StaticBitVec.hpp delete mode 100644 chilbert/chilbert.hpp delete mode 100644 chilbert/chilbert.ipp delete mode 100644 chilbert/detail/BitVecIndex.hpp delete mode 100644 chilbert/detail/BitVecIterator.hpp delete mode 100644 chilbert/detail/BitVecMask.hpp delete mode 100644 chilbert/detail/MultiBitVec.hpp delete mode 100644 chilbert/detail/gray_code_rank.hpp delete mode 100644 chilbert/detail/operations.hpp delete mode 100644 chilbert/detail/traits.hpp delete mode 100644 chilbert/operators.hpp create mode 100644 include/chilbert/BoundedBitVec.hpp create mode 100644 include/chilbert/DynamicBitVec.hpp create mode 100644 include/chilbert/SmallBitVec.hpp create mode 100644 include/chilbert/StaticBitVec.hpp create mode 100644 include/chilbert/chilbert.hpp create mode 100644 include/chilbert/chilbert.ipp create mode 100644 include/chilbert/detail/BitVecIndex.hpp create mode 100644 include/chilbert/detail/BitVecIterator.hpp create mode 100644 include/chilbert/detail/BitVecMask.hpp create mode 100644 include/chilbert/detail/MultiBitVec.hpp create mode 100644 include/chilbert/detail/gray_code_rank.hpp create mode 100644 include/chilbert/detail/operations.hpp create mode 100644 include/chilbert/detail/traits.hpp create mode 100644 include/chilbert/operators.hpp create mode 100644 meson.build create mode 100644 meson/warnings/meson.build create mode 100644 meson_options.txt create mode 100644 src/chilbert_obj.cpp create mode 100644 src/chilbert_svg.cpp delete mode 100644 test/bench_bitvec.cpp delete mode 100644 test/bench_hilbert.cpp delete mode 100644 test/bench_utils.hpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 3a8b625..0000000 --- a/Makefile +++ /dev/null @@ -1,99 +0,0 @@ -################# -# Configuration # -################# - -# User variables -DEBUG ?= 0 -TEST ?= 0 - -prefix ?= /usr/local -includedir ?= $(prefix)/include -bindir ?= $(prefix)/bin - -# Wipe user flags if DEBUG is on -ifeq ($(DEBUG), 1) -CXXFLAGS = -O0 -g -endif - -# Append mandatory flags -CXXFLAGS += -I. -std=c++14 - -# Set strict debugging flags for known compilers -ifeq ($(DEBUG), 1) - -ifeq ($(findstring clang,$(CXX)),clang) - CXXFLAGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -else ifeq ($(findstring g++,$(CXX)),g++) - CXXFLAGS += -ftree-vrp -ftrapv -Waddress -Wall -Warray-bounds=2 -Wbool-compare -Wc++14-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wchkp -Wclobbered -Wcomment -Wconditionally-supported -Wconversion -Wcoverage-mismatch -Wdate-time -Wdelete-incomplete -Wdisabled-optimization -Wdouble-promotion -Wduplicated-cond -Wempty-body -Wenum-compare -Werror=pedantic -Wextra -Wfloat-conversion -Wfloat-equal -Wformat -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-y2k -Wformat=2 -Wframe-address -Whsa -Wignored-attributes -Wignored-qualifiers -Winit-self -Winline -Winvalid-memory-model -Winvalid-pch -Wlogical-not-parentheses -Wlogical-op -Wmain -Wmaybe-uninitialized -Wmemset-transposed-args -Wmisleading-indentation -Wmissing-declarations -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wno-aggressive-loop-optimizations -Wno-attributes -Wno-builtin-macro-redefined -Wno-cpp -Wno-deprecated -Wno-deprecated-declarations -Wno-div-by-zero -Wno-endif-labels -Wno-format-contains-nul -Wno-format-extra-args -Wno-free-nonheap-object -Wno-int-to-pointer-cast -Wno-invalid-offsetof -Wno-multichar -Wno-overflow -Wno-pedantic-ms-format -Wno-pragmas -Wno-return-local-addr -Wno-scalar-storage-order -Wno-undef -Wno-unused-result -Wnonnull -Wnonnull-compare -Wnormalized -Wnull-dereference -Wodr -Wopenmp-simd -Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wparentheses -Wpedantic -Wplacement-new=2 -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value -Wshift-overflow -Wshift-overflow=2 -Wsign-compare -Wsign-conversion -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wstack-protector -Wstrict-aliasing -Wstrict-overflow -Wsubobject-linkage -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsuggest-override -Wswitch -Wswitch-bool -Wswitch-default -Wswitch-enum -Wsync-nand -Wtautological-compare -Wtrampolines -Wtrigraphs -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-const-variable -Wunused-const-variable=2 -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-parameter -Wunused-value -Wunused-variable -Wuseless-cast -Wvariadic-macros -Wvector-operation-performance -Wvla -Wvolatile-register-var -Wwrite-strings -Wzero-as-null-pointer-constant -fstrict-aliasing -fstrict-overflow -pedantic-errors -else -$(info warning: Unknown compiler, not setting strict debugging flags) -$(info ) -endif - -endif # DEBUG - - -############### -# Build Rules # -############### - -HEADERS = $(wildcard chilbert/*.hpp) $(wildcard chilbert/*.ipp) -DETAIL_HEADERS = $(wildcard chilbert/detail/*.hpp) -TESTS = test/test_bitvec test/test_gray_code_rank test/test_hilbert -BENCHMARKS = test/bench_bitvec test/bench_hilbert -PROGS = bin/chilbert_obj bin/chilbert_svg - -ALL_HEADERS = $(HEADERS) $(DETAIL_HEADERS) -PROG_NAMES = $(subst bin/,,$(PROGS)) - -all: $(PROGS) - -tests: $(TESTS) - -benchmarks: $(BENCHMARKS) - -test/%: test/%.cpp $(ALL_HEADERS) - $(CXX) $(CXXFLAGS) -o $@ $@.cpp - -test/test_hilbert: test/test_hilbert.cpp $(ALL_HEADERS) - $(CXX) $(CXXFLAGS) -lgmp -lgmpxx -o $@ $@.cpp - -bin/%: bin/%.cpp $(ALL_HEADERS) - $(CXX) $(CXXFLAGS) -o $@ $@.cpp - - -################## -# Forced Targets # -################## - -FORCE: - -clean: - rm -f $(PROGS) $(TESTS) $(BENCHMARKS) - -%.run: % - $* - -test: tests $(addsuffix .run, $(TESTS)) FORCE - -bench: $(BENCHMARKS) - mkdir -p benchmarks - cd benchmarks && ../test/bench_bitvec - cd benchmarks && ../test/bench_hilbert - cd benchmarks && ./plot.py - -install: FORCE - install -d $(DESTDIR)$(includedir)/chilbert/ - install -d $(DESTDIR)$(includedir)/chilbert/detail/ - install -d $(DESTDIR)$(bindir)/ - - install -m 755 -t $(DESTDIR)$(includedir)/chilbert/ $(HEADERS) - install -m 755 -t $(DESTDIR)$(includedir)/chilbert/detail/ $(DETAIL_HEADERS) - install -m 755 -t $(DESTDIR)$(bindir)/ $(PROGS) - -uninstall: FORCE - rm -f $(subst bin/,$(DESTDIR)$(bindir)/,$(PROGS)) - rm -f $(subst chilbert/,$(DESTDIR)$(includedir)/chilbert/,$(ALL_HEADERS)) - - -rmdir $(DESTDIR)$(bindir)/ - -rmdir -p $(DESTDIR)$(includedir)/chilbert/detail/ diff --git a/benchmark/bench_bitvec.cpp b/benchmark/bench_bitvec.cpp new file mode 100644 index 0000000..6580af9 --- /dev/null +++ b/benchmark/bench_bitvec.cpp @@ -0,0 +1,352 @@ +/* + Copyright (C) 2018 David Robillard + + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . +*/ + +#include "bench_utils.hpp" +#include "test_utils.hpp" + +#include "chilbert/BoundedBitVec.hpp" // IWYU pragma: keep +#include "chilbert/DynamicBitVec.hpp" // IWYU pragma: keep +#include "chilbert/SmallBitVec.hpp" +#include "chilbert/StaticBitVec.hpp" // IWYU pragma: keep + +#include +#include +#include +#include +#include + +template +struct BenchAnd +{ + Duration operator()(Context& ctx) + { + const T v = make_random_bitvec(ctx); + T r = make_random_bitvec(ctx); + + return run_bench([&](auto) { r &= v; }); + } +}; + +template +struct BenchOr +{ + Duration operator()(Context& ctx) + { + const T v = make_random_bitvec(ctx); + T r = make_random_bitvec(ctx); + + return run_bench([&](auto) { r |= v; }); + } +}; + +template +struct BenchXor +{ + Duration operator()(Context& ctx) + { + const T v = make_random_bitvec(ctx); + T r = make_random_bitvec(ctx); + + return run_bench([&](auto) { r ^= v; }); + } +}; + +template +struct BenchSetOne +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + return run_bench([&](const auto i) { v.set(i % N); }); + } +}; + +template +struct BenchSetAll +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + return run_bench([&](auto) { v.set(); }); + } +}; + +template +struct BenchResetOne +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + return run_bench([&](const auto i) { v.reset(i % N); }); + } +}; + +template +struct BenchResetAll +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + return run_bench([&](auto) { v.reset(); }); + } +}; + +template +struct BenchFlipOne +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + return run_bench([&](const auto i) { v.flip(i % N); }); + } +}; + +template +struct BenchFlipAll +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + return run_bench([&](auto) { v.flip(); }); + } +}; + +template +struct BenchNone +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + bool r = false; + (void)r; + + return run_bench([&](auto) { r = v.none(); }); + } +}; + +template +struct BenchCount +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + volatile size_t r = 0; + (void)r; + + return run_bench([&](auto) { r = v.count(); }); + } +}; + +template +struct BenchLeftShift +{ + Duration operator()(Context& ctx) + { + const T v = make_random_bitvec(ctx); + T r = v; + return run_bench([&](const auto i) { r <<= (i % N); }); + } +}; + +template +struct BenchRightShift +{ + Duration operator()(Context& ctx) + { + const T v = make_random_bitvec(ctx); + T r = v; + return run_bench([&](const auto i) { r >>= (i % N); }); + } +}; + +template +struct BenchLeftRotate +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + return run_bench([&](const auto i) { v.rotl(i % N); }); + } +}; + +template +struct BenchRightRotate +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + volatile bool r = false; + (void)r; + + return run_bench([&](const auto i) { + v.rotr(i % N); + r = v.test(0); + }); + } +}; + +template +struct BenchFindFirst +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + volatile size_t r = 0; + (void)r; + + return run_bench([&](auto) { r = v.find_first(); }); + } +}; + +template +struct BenchGrayCode +{ + Duration operator()(Context& ctx) + { + const T v = make_random_bitvec(ctx); + T r = v; + + return run_bench([&](auto) { chilbert::detail::gray_code(r); }); + } +}; + +template +struct BenchGrayCodeInv +{ + Duration operator()(Context& ctx) + { + const T v = make_random_bitvec(ctx); + T r = v; + + return run_bench([&](auto) { chilbert::detail::gray_code_inv(r); }); + } +}; + +template +struct BenchComparison +{ + Duration operator()(Context& ctx) + { + std::vector vecs; + for (size_t i = 0; i < 32; ++i) { + vecs.emplace_back(make_random_bitvec(ctx)); + } + + volatile bool r = false; + + return run_bench([&](const auto i) { + r |= vecs[i % vecs.size()] < vecs[(i + 1) % vecs.size()]; + }); + } +}; + +template +struct BenchIteration +{ + Duration operator()(Context& ctx) + { + T v = make_random_bitvec(ctx); + auto i = v.begin(); + volatile bool r = false; + return run_bench([&](const auto) { + r = (++i == v.end()); + if (r) { + i = v.begin(); + } + }); + } +}; + +/// Run benchmark for size N +template