-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbch_simulator.hpp
More file actions
137 lines (117 loc) · 3.79 KB
/
bch_simulator.hpp
File metadata and controls
137 lines (117 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef BCH_SIMULATOR_HPP
#define BCH_SIMULATOR_HPP
#include <any>
#include <bit>
#include <bitset>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <functional>
#include <memory>
#include <random>
#include <ranges>
#include <thread>
#include <time.h>
#include <unordered_map>
#include <variant>
#include <vector>
#include <sys/mman.h>
#include <sys/stat.h>
#include "bch_utils.hpp"
#include "bch_math.hpp"
#include "bch_logger.hpp"
#define RESERVED_BYTES 71
template <size_t N, size_t K>
struct polynomialData{
union polynomial {
std::bitset<N> codeword;
std::bitset<K> data;
};
polynomial encoded{};
polynomial received{};
polynomial decoded{};
};
std::string bchFirstInit();
size_t resizeMainVectors(
const size_t file_byte_size);
void divideImageBytesToBitsets(
const char* buffer,
const size_t message_bytes_thread_group,
const size_t message_polynomials_thread_group,
const size_t num_threads,
const size_t file_byte_size,
std::vector<std::thread>& threads);
void mathStructInit();
void startMainProcess(
const size_t number_of_message_polynomials,
const size_t message_polynomials_thread_group,
const size_t num_threads,
std::vector<std::thread>& threads);
void divideImageBitsetsToBytes(
const size_t message_bytes_thread_group,
const size_t message_polynomials_thread_group,
const size_t num_threads,
const size_t file_byte_size,
std::vector<std::thread>& threads);
size_t getMainDifferenceCount(
const size_t number_of_message_polynomials);
globalCounters& getFullCounters();
void finalLogsAndCleanup(
const size_t number_of_message_polynomials,
std::string& image_with_errors_path,
std::string& image_fixed_path,
std::chrono::duration<float> main_duration);
class Bch6351 {
public:
static constexpr ssize_t n_ = 63;
static constexpr ssize_t k_ = 51;
static constexpr ssize_t t_ = (n_ - k_) / 6;
explicit Bch6351 (const std::bitset <k_>& data) {
codeword_polynomials_.encoded.data = data;
}
static std::vector <std::bitset <k_>> vector_of_message_polynomials;
polynomialData<n_, k_> codeword_polynomials_{};
};
class Bch6345 {
public:
static constexpr ssize_t n_ = 63;
static constexpr ssize_t k_ = 45;
static constexpr ssize_t t_ = (n_ - k_) / 6;
explicit Bch6345(const std::bitset <k_>& data) {
codeword_polynomials_.encoded.data = data;
}
static std::vector <std::bitset <k_>> vector_of_message_polynomials;
polynomialData<n_, k_> codeword_polynomials_{};
};
class Bch4836 {
public:
static constexpr ssize_t n_ = 48;
static constexpr ssize_t k_ = 36;
static constexpr ssize_t t_ = (n_ - k_) / 6;
explicit Bch4836(const std::bitset <k_>& data) {
codeword_polynomials_.encoded.data = data;
}
static std::vector <std::bitset <k_>> vector_of_message_polynomials;
polynomialData<n_, k_> codeword_polynomials_{};
};
class Bch4830{
public:
static constexpr ssize_t n_ = 48;
static constexpr ssize_t k_ = 30;
static constexpr ssize_t t_ = (n_ - k_) / 6;
explicit Bch4830(const std::bitset <k_>& data) {
codeword_polynomials_.encoded.data = data;
}
static std::vector <std::bitset <k_>> vector_of_message_polynomials;
polynomialData<n_, k_> codeword_polynomials_{};
};
using bchType = std::variant<std::unique_ptr<Bch6351>, std::unique_ptr<Bch6345>,
std::unique_ptr<Bch4836>, std::unique_ptr<Bch4830>>;
namespace bch {
// the big dawg
inline std::vector <bchType> BCH_objects;
inline std::vector <char> decoded_charstream;
inline std::vector <char> received_charstream;
};
#endif /* BCH_SIMULATOR_HPP */