Skip to content

Commit

Permalink
gitbak
Browse files Browse the repository at this point in the history
  • Loading branch information
floyd committed May 26, 2024
1 parent d08e93e commit 6b95fa5
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 131 deletions.
33 changes: 4 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ check_cxx_compiler_flag(-march=native COMPILER_SUPPORTS_MARCH_NATIVE)
check_cxx_compiler_flag(-fno-inline COMPILER_SUPPORTS_NO_INLINE)
check_cxx_compiler_flag(-fsanitize=address COMPILER_SUPPORTS_SANITIZE_ADDRESS) # TODO support not recognized
check_cxx_compiler_flag(-fsanitize=memory COMPILER_SUPPORTS_SANITIZE_MEMORY)
check_cxx_compiler_flag(-fconstexpr-steps=91 COMPILER_SUPPORTS_CONSTEXPR_COST)
check_cxx_compiler_flag(-fconstexpr-steps=9999999 COMPILER_SUPPORTS_CONSTEXPR_COST)
check_cxx_compiler_flag(-fno-exceptions COMPILER_SUPPORTS_NO_EXCEPTION)
check_ipo_supported(RESULT lto_supported OUTPUT error)
check_cxx_compiler_flag(-latomic LINKER_SUPPORTS_ATOMIC) # TODO
Expand All @@ -68,23 +68,6 @@ find_package(GTest)
find_package(benchmark)
find_package(Git QUIET)

# init the submodules
#if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# execute_process(COMMAND ${GIT_EXECUTABLE} submodule sync
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# RESULT_VARIABLE GIT_SUBMOD_RESULT)
# if(NOT GIT_SUBMOD_RESULT EQUAL "0")
# message(FATAL_ERROR "git submodule update sync failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
# endif()
#
# execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# RESULT_VARIABLE GIT_SUBMOD_RESULT)
# if(NOT GIT_SUBMOD_RESULT EQUAL "0")
# message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
# endif()
#endif()

# global include directories
include_directories("deps/b63/include/b63")
include_directories("src")
Expand Down Expand Up @@ -119,18 +102,18 @@ if(lto_supported AND USE_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

set(ALLOWED_WARNINGS " -Wno-c99-designator -Wno-invalid-constexpr -Wno-unused-function -Wno-zero-length-array")
set(ALLOWED_WARNINGS " -Wno-unknown-pragmas -Wno-c99-designator -Wno-invalid-constexpr -Wno-unused-function -Wno-zero-length-array")

message(STATUS "System Processor: ${CMAKE_SYSTEM_PROCESSOR}")

IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
message(STATUS "ARM CPU detected")
set(ADDITIONAL_FLAGS "-DUSE_ARM -flax-vector-conversions -march=native")
set(DEBUG_FLAGS "-g -Wall -Wextra -Wpedantic -fpermissive -DDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${SANITIZER_FLAGS} ${ADDITIONAL_FLAGS}")
set(DEBUG_FLAGS "-g -Wall -Wextra -fpermissive -DDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${SANITIZER_FLAGS} ${ADDITIONAL_FLAGS}")
set(OPTIMIZE_FLAGS "-O3 -DNDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${ADDITIONAL_FLAGS}")
else()

set(DEBUG_FLAGS "-g -O0 -Wall -Wextra -Wpedantic -DDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${SANITIZER_FLAGS} ${ADDITIONAL_FLAGS}")
set(DEBUG_FLAGS "-g -O0 -Wall -Wextra -DDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${SANITIZER_FLAGS} ${ADDITIONAL_FLAGS}")
set(OPTIMIZE_FLAGS "-g -march=native -DNDEBUG ${INLINE_FLAGS} ${ALLOWED_WARNINGS} ${ADDITIONAL_FLAGS}")
endif()

Expand Down Expand Up @@ -190,7 +173,6 @@ if(CMAKE_CUDA_COMPILER)
# again only for arch... fuck NVIDIA
include_directories(/opt/cuda/samples/cuda-samples/Common)
include_directories(/usr/local/cuda/samples/cuda-samples/Common)
include_directories(/home/floyd.zweydinger/cuda-samples/Common)
include_directories(/opt/cuda/include)
include_directories(deps/cudacommon)
include_directories(deps/cuCollections/include)
Expand Down Expand Up @@ -226,21 +208,14 @@ if(CMAKE_CUDA_COMPILER)
endif()

# include every subpackage which is included in `cryptanalysislib`
include_directories("deps/cryptanalysislib/deps/fplll/")
include_directories("deps/cryptanalysislib/deps/b63/include/b63")
include_directories("deps/cryptanalysislib/deps/m4ri/m4ri")
include_directories("deps/cryptanalysislib/deps/m4ri")
include_directories("deps/cryptanalysislib/deps/ska_sort")
include_directories("deps/cryptanalysislib/deps/Static-Sort/include")
include_directories("deps/cryptanalysislib/src")

include_directories("src")
include_directories("test/decoding/challenges")
include_directories("test/mceliece/challenges")
include_directories("/usr/local/include")

link_directories("deps/cryptanalysislib/build")
link_directories("deps/cryptanalysislib/deps/m4ri/.libs")
link_directories("/usr/local/lib")

#TODO
Expand Down
2 changes: 1 addition & 1 deletion deps/cryptanalysislib
Submodule cryptanalysislib updated 91 files
+20 −19 CMakeLists.txt
+6 −8 README.md
+2 −2 bench/CMakeLists.txt
+50 −0 bench/container/ctrie.cpp
+1 −1 bench/container/hashmap.cpp
+48 −0 bench/container/hashmap2.cpp
+1 −1 bench/enumeration/CMakeLists.txt
+2 −3 bench/enumeration/chaseg.cpp
+6 −6 bench/matrix/fq_permute.cpp
+1 −0 bench/mem/CMakeLists.txt
+28 −0 bench/mem/memcpy.cpp
+4 −4 bench/nn/opt.cpp
+44 −52 bench/search/binarysearch.cpp
+1 −1 deps/cmake_optimize_for_architecture
+1 −1 shell.nix
+7 −7 src/alloc/alloc.h
+1 −1 src/atomic_primitives.h
+85 −0 src/binary.h
+66 −1 src/combination/chase.h
+12 −0 src/container/binary_packed_vector.h
+85 −0 src/container/bk_tree.h
+2,043 −0 src/container/ctrie.h
+4 −0 src/container/hashmap.h
+10 −9 src/container/hashmap/avx2.h
+318 −0 src/container/hashmap/growth_policy.h
+833 −0 src/container/hashmap/hopscotch.h
+1,827 −0 src/container/hashmap/hopscotch_hash.h
+514 −0 src/container/hashmap/lock_free_hopscotch.h
+1 −1 src/container/hashmap/simple.h
+1 −1 src/container/hashmap/simple2.h
+1,422 −0 src/container/hashmap/ska_flat.h
+1 −1 src/container/linkedlist/linkedlist.h
+386 −0 src/container/rb_tree.h
+580 −0 src/hash/cityhash.h
+60 −0 src/hash/fnv1a.h
+9 −0 src/hash/hash.h
+336 −0 src/hash/sha3/common.h
+93 −0 src/hash/sha3/keccak.h
+4 −0 src/hash/sha3/sha3.h
+6 −1 src/hash/xxh3.h
+46 −5 src/math/bc.h
+5 −2 src/matrix/binary_matrix.h
+0 −165 src/mem/memcpy.S
+0 −24 src/mem/memcpy.h
+0 −188 src/mem/memset.S
+0 −39 src/mem/memset.h
+13 −0 src/memory/common.h
+168 −0 src/memory/memcpy.h
+7 −0 src/memory/memory.h
+162 −0 src/memory/memset.h
+24 −24 src/nn/nn.h
+32 −30 src/popcount/avx2.h
+3 −9 src/popcount/popcount.h
+156 −0 src/reflection/field.h
+98 −0 src/reflection/flatten.h
+1,514 −0 src/reflection/internal.h
+319 −0 src/reflection/literal.h
+607 −0 src/reflection/name_tuple.h
+1,234 −0 src/reflection/reflection.h
+133 −0 src/reflection/rename.h
+2 −2 src/search/binary.h
+2 −2 src/search/interpolation.h
+2 −2 src/search/linear.h
+1 −1 src/simd/README.md
+287 −18 src/simd/avx2.h
+195 −35 src/simd/avx512.h
+312 −8 src/simd/neon.h
+305 −3 src/simd/simd.h
+64 −0 src/string/stringliteral.h
+481 −0 src/uin128t.h
+2 −1 tests/CMakeLists.txt
+25 −22 tests/binary/sort.cpp
+45 −0 tests/container/bk_tree.cpp
+129 −0 tests/container/ctrie.cpp
+63 −0 tests/container/hashmap/hopscotch.cpp
+31 −0 tests/container/rb_tree.cpp
+1,319 −0 tests/hash/cityhash.cpp
+0 −242 tests/hash/constexpr-xxh3-test.cc
+45 −0 tests/list/enumeration/biject.cpp
+42 −0 tests/list/enumeration/binary.cpp
+4 −4 tests/matrix/CMakeLists.txt
+0 −324 tests/matrix/binary.cpp
+438 −0 tests/matrix/simple.cpp
+9 −0 tests/memory/CMakeLists.txt
+51 −0 tests/memory/simple.cpp
+9 −9 tests/nn/bruteforce.cpp
+181 −0 tests/nn/parameters.cpp
+4 −446 tests/nn/simd.cpp
+287 −0 tests/nn/simd_bruteforce.cpp
+103 −0 tests/test_reflection.cpp
+21 −0 tests/test_uint128t.cpp
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ stdenv.mkDerivation {
]++ (lib.optionals pkgs.stdenv.isLinux ([
flamegraph
gdb
linuxKernel.packages.linux_6_5.perf
linuxKernel.packages.linux_6_1.perf
pprof
valgrind
massif-visualizer
Expand Down
37 changes: 26 additions & 11 deletions src/bjmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ class BJMM : public ISDInstance<uint64_t, isd> {
constexpr static uint32_t gaus_c = config.c;

using ISD = ISDInstance<uint64_t, isd>;
using PCMatrixOrg = ISD::PCMatrixOrg;
using PCMatrixOrg_T = ISD::PCMatrixOrg_T;
using PCMatrix = ISD::PCMatrix;
using PCMatrix_T = ISD::PCMatrix_T;
using PCSubMatrix = ISD::PCSubMatrix;
using PCSubMatrix_T = ISD::PCSubMatrix_T;
using Syndrome = ISD::Syndrome;
using Error = ISD::Error;
using Label = ISD::Label;
using PCMatrixOrg = typename ISD::PCMatrixOrg;
using PCMatrixOrg_T = typename ISD::PCMatrixOrg_T;
using PCMatrix = typename ISD::PCMatrix;
using PCMatrix_T = typename ISD::PCMatrix_T;
using PCSubMatrix = typename ISD::PCSubMatrix;
using PCSubMatrix_T = typename ISD::PCSubMatrix_T;
using Syndrome = typename ISD::Syndrome;
using Error = typename ISD::Error;
using Label = typename ISD::Label;
using ISD::A,ISD::H,ISD::wA,ISD::wAT,ISD::HT,ISD::s,ISD::ws,ISD::e,ISD::syndrome,ISD::P,ISD::not_found,ISD::loops,ISD::ghz;
using ISD::cycles,ISD::periodic_print,ISD::packed,ISD::simd;

using l_type = ISD::l_type;
using l_type = typename ISD::l_type;
using keyType = LogTypeTemplate<l>;
// using valueType = TypeTemplate<bc(n, p)>[1];

Expand Down Expand Up @@ -125,7 +125,7 @@ class BJMM : public ISDInstance<uint64_t, isd> {
HM1 *hm1; HM2 *hm2;

constexpr static ConfigEnumHashMap configEnum{config};
constexpr static ConfigEnumHashMapD2 configEnumD2{config, .l1=l1, .l2=l2};
constexpr static ConfigEnumHashMapD2 configEnumD2{config, l1, l2};
EnumHashMap<configEnum, HM1> *bEnum;
CollisionHashMap<configEnum, HM1> *cEnum;
CollisionHashMapD2<configEnumD2, HM1, HM2> *cEnumD2;
Expand Down Expand Up @@ -257,10 +257,19 @@ class BJMM : public ISDInstance<uint64_t, isd> {
ISD::extract_pHT(pHT);


/// TODO describe the parameters
/// \param a1
/// \param a2
/// \param index1
/// \param index2
/// \param nr_cols
auto f1 = [&, this](const l_type a1, const l_type a2,
const uint16_t *index1, const uint16_t *index2,
const uint32_t nr_cols) __attribute__((always_inline)) {
// NOTE: iT1 curently unknown in the global scope
// ASSERT(bEnum->check_hashmap2(iT1, index1, 2*p, l1));
(void) index2;
(void) nr_cols;
const l_type a = a1 ^ a2;
hm2->insert(a>>l1, V2::create(a, index1));
};
Expand All @@ -269,6 +278,11 @@ class BJMM : public ISDInstance<uint64_t, isd> {
const uint16_t *index1, const uint16_t *index2,
const uint32_t nr_cols) __attribute__((always_inline)) {
ASSERT(bEnum->check_hashmap2(syndrome, index1, 4*p, l));
(void) index2;
(void) nr_cols;
(void) a1;
(void) a2;

for (uint32_t i = 0; i < 4; ++i) {
final_list[final_list_current_size][i] = index1[i];
}
Expand All @@ -294,6 +308,7 @@ class BJMM : public ISDInstance<uint64_t, isd> {
while ((iT1 ^ syndrome) < iT1) {
iT1 += 1;
}

const l_type iT2 = iT1 ^ syndrome;

cEnum->step(iT1, f1, tid, simd);
Expand Down
4 changes: 2 additions & 2 deletions src/fq/sieving.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class FqSieving : public ISDInstance<uint64_t, isd>{

/// NOTE: the compressor negates the data, needed to be able
/// to search for exact matches.
l_type data1 = this->NegateCompress
l_type data1 = this->template NegateCompress
<lower_l>(L1->at(i).label);
IndexType pos1 = hm1->find(data1, load1);

Expand Down Expand Up @@ -277,7 +277,7 @@ class FqSieving : public ISDInstance<uint64_t, isd>{
HM_LoadType load1;

/// NOTE: the compressor negates the data
l_type data1 = this->NegateCompress
l_type data1 = this->template NegateCompress
<lower_l_bit>(L1->at(i).label);

/// NOTE: maybe I can prepare data1 before hand?
Expand Down
30 changes: 15 additions & 15 deletions src/mitm.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,10 @@ class CollisionHashMap {
constexpr static size_t enumeration_size = bc(enumeration_length, enumeration_weight);
constexpr static size_t enumeration_size_per_thread = enumeration_size/threads;

using HM_LoadType = HashMap::load_type;
using HM_DataType = HashMap::data_type;

using HM_DataType_IndexType = HM_DataType::index_type;
using l_type = HM_DataType::data_type;
using HM_LoadType = typename HashMap::load_type;
using HM_DataType = typename HashMap::data_type;
using HM_DataType_IndexType = typename HM_DataType::index_type;
using l_type = typename HM_DataType::data_type;
constexpr static size_t HM1_BUCKETSIZE = HashMap::bucketsize;

using cle = std::pair<uint16_t, uint16_t>;
Expand All @@ -395,8 +394,8 @@ class CollisionHashMap {
*lHTr = nullptr;

public:
constexpr CollisionHashMap(const l_type *lHT, HashMap *hm, cle *cL = nullptr) noexcept :
cL(cL), hm(hm), lHT(lHT), lHTr(lHT + n_half - config.epsilon) {
constexpr CollisionHashMap(const l_type *_lHT, HashMap *hm, cle *cL = nullptr) noexcept :
cL(cL), hm(hm), lHT(_lHT), lHTr(_lHT + n_half - config.epsilon) {
}

///
Expand Down Expand Up @@ -600,26 +599,27 @@ class CollisionHashMapD2 {
constexpr static size_t enumeration_size = bc(enumeration_length,enumeration_weigth);
constexpr static size_t enumeration_size_per_thread = enumeration_size/threads;

using HM_LoadType = HashMap2::load_type;
using HM_DataType = HashMap2::data_type;
using HM_DataType_IndexType = HM_DataType::index_type;
using l_type = HM_DataType::data_type;
using HM_LoadType = typename HashMap2::load_type;
using HM_DataType = typename HashMap2::data_type;
using HM_DataType_IndexType = typename HM_DataType::index_type;
using l_type = typename HM_DataType::data_type;

const l_type *lHT, *lHTr;
HashMap1 *hm1;
HashMap2 *hm2;
const l_type *lHT = nullptr, *lHTr = nullptr;


public:
CollisionHashMapD2(const l_type *lHT,
CollisionHashMapD2(const l_type *_lHT,
HashMap1 *hm1,
HashMap2 *hm2) noexcept :
lHT(lHT), lHTr(lHT + n_half - config.epsilon), hm1(hm1), hm2(hm2) {
}
lHT(_lHT), lHTr(_lHT + n_half - config.epsilon),
hm1(hm1), hm2(hm2) {}

template<typename F>
bool step(const l_type iT, F &&f, const uint32_t tid = 0, const bool simd=true) {
/// TODO simd
(void)simd;
return coll_hashmap_simple(iT, tid, f);
}

Expand Down
10 changes: 5 additions & 5 deletions src/stern.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ConfigStern : public ConfigISD {


// returns the expected number of iterations
[[nodiscard]] consteval uint64_t compute_loops() const noexcept {
[[nodiscard]] constexpr uint64_t compute_loops() const noexcept {
#ifdef EXPECTED_PERMUTATIONS
return EXPECTED_PERMUTATIONS;
#else
Expand Down Expand Up @@ -60,15 +60,15 @@ class Stern : public ISDInstance<uint64_t, isd> {
static_assert(config.HM_bucketsize > 0);

using ISD = ISDInstance<uint64_t, isd>;
using Error = ISD::Error;
using Label = ISD::Label;
using limb_type = ISD::limb_type;
using Error = typename ISD::Error;
using Label = typename ISD::Label;
using limb_type = typename ISD::limb_type;
using ISD::A,ISD::H,ISD::wA,ISD::wAT,ISD::HT,ISD::s,ISD::ws,ISD::e,ISD::syndrome,ISD::P,ISD::not_found,ISD::loops,ISD::ghz,ISD::expected_loops;
using ISD::cycles,ISD::periodic_print,ISD::packed,ISD::simd;


// base datatype of the hashmap
using l_type = ISD::l_type;
using l_type = typename ISD::l_type;

constexpr static uint32_t kl_half = (k+l)/2;

Expand Down
5 changes: 2 additions & 3 deletions tests/fq/sieving/50.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <gtest/gtest.h>
#include <iostream>

#include "../challenges/50_20_4.h"
#include "fq/sieving.h"
Expand All @@ -15,7 +14,7 @@ using ::testing::UnitTest;

TEST(Sieving, t1p2) {
static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=q,.w=w,.p=2,.l=3,.c=0,.threads=1};
static constexpr ConfigFqSieving config{isdConfig, .HM_bs=20, .sieving_steps=5, .enumeration_q=3};
static constexpr ConfigFqSieving config{isdConfig, 20, 5, 3};

FqSieving<isdConfig, config> sieve{};
sieve.from_string(h, s);
Expand All @@ -31,4 +30,4 @@ int main(int argc, char **argv) {
srand(time(NULL));
random_seed(rand());
return RUN_ALL_TESTS();
}
}
4 changes: 2 additions & 2 deletions tests/mceliece/bjmm/1284.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using ::testing::UnitTest;

TEST(BJMM, t1284t1p1) {
static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=19,.c=0,.threads=1};
static constexpr ConfigBJMM config{isdConfig, .l1=2, .HM1_bucketsize=1<<6, .HM2_bucketsize=4};
static constexpr ConfigBJMM config{isdConfig, 2, 1<<6, 4};

BJMM<isdConfig, config> bjmm{};
bjmm.from_string(h, s);
Expand All @@ -29,4 +29,4 @@ int main(int argc, char **argv) {
srand(time(NULL));
random_seed(rand());
return RUN_ALL_TESTS();
}
}
5 changes: 2 additions & 3 deletions tests/mceliece/bjmm/240.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "../challenges/mce240.h"
#include "bjmm.h"
#include "eb.h"

using ::testing::EmptyTestEventListener;
using ::testing::InitGoogleTest;
Expand All @@ -20,7 +19,7 @@ TEST(Bjmm, t240) {
constexpr uint32_t bucketsize2 = 8;

static constexpr ConfigISD isdConfig{.n=n,.k=k,.q=2,.w=w,.p=1,.l=10,.c=0,.threads=1};
static constexpr ConfigBJMM config{isdConfig, .l1=4, .HM1_bucketsize=bucketsize1, .HM2_bucketsize=bucketsize2};
static constexpr ConfigBJMM config{isdConfig, 4, bucketsize1, bucketsize2};

BJMM<isdConfig, config> bjmm{};
bjmm.from_string(h, s);
Expand All @@ -33,4 +32,4 @@ int main(int argc, char **argv) {
srand(time(NULL));
random_seed(rand());
return RUN_ALL_TESTS();
}
}
Loading

0 comments on commit 6b95fa5

Please sign in to comment.