You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NextLFSR(std::bitset<k>& lfsr, const std::array<uint16_t, nTaps> taps, constbool left = true)
51
-
{
52
-
static_assert(k <= 32, "For the moment, only supported until k == 32.");
53
-
static_assert(k > 0, "Non-zero degree is needed for the LFSR.");
54
-
static_assert(nTaps > 0, "At least one tap is needed for the LFSR.");
55
-
static_assert(nTaps <= k, "Cannot use more taps than polynomial order");
56
-
57
-
// First, calculate the XOR (^) of all selected bits (marked by the taps)
58
-
bool newBit = lfsr[taps.at(0) - 1]; // the exponent E of the polynomial correspond to index E - 1 in the bitset
59
-
for(uint16_t j = 1; j < nTaps ; ++j)
60
-
{
61
-
newBit ^= lfsr[taps.at(j) - 1];
62
-
}
63
-
64
-
//Apply the shift to the register in the right direction, and overwrite the empty one with newBit
65
-
if(left)
66
-
{
67
-
lfsr <<= 1;
68
-
lfsr[0] = newBit;
69
-
}
70
-
else
71
-
{
72
-
lfsr >>= 1;
73
-
lfsr[k-1] = newBit;
74
-
}
48
+
template <size_t k, size_t nTaps>
49
+
staticboolNextLFSR(std::bitset<k> &lfsr, std::array<uint16_t, nTaps> taps, bool left = true)
50
+
{
51
+
static_assert(k <= 32, "For the moment, only supported until k == 32.");
52
+
static_assert(k > 0, "Non-zero degree is needed for the LFSR.");
53
+
static_assert(nTaps > 0, "At least one tap is needed for the LFSR.");
54
+
static_assert(nTaps <= k, "Cannot use more taps than polynomial order");
55
+
56
+
// First, calculate the XOR (^) of all selected bits (marked by the taps)
57
+
bool newBit = lfsr[taps[0] - 1]; // the exponent E of the polynomial correspond to index E - 1 in the bitset
58
+
for (uint16_t j = 1; j < nTaps; ++j) {
59
+
newBit ^= lfsr[taps[j] - 1];
60
+
}
75
61
76
-
return newBit;
62
+
// Apply the shift to the register in the right direction, and overwrite the empty one with newBit
63
+
if (left) {
64
+
lfsr <<= 1;
65
+
lfsr[0] = newBit;
66
+
} else {
67
+
lfsr >>= 1;
68
+
lfsr[k - 1] = newBit;
77
69
}
78
70
79
-
/**
80
-
* @brief Generation of a sequence of pseudo-random bits using a linear feedback shift register (LFSR), until a register value is repeated (or maxPeriod is reached)
81
-
* @tparam k the length of the LFSR, usually also the order of the monic polynomial PRBS-k (last exponent)
82
-
* @tparam nTaps the number of taps
83
-
* @param start the start value (seed) of the LFSR
84
-
* @param taps the taps that will be XOR-ed to calculate the new bit. They are the exponents of the monic polynomial. Ordering is unimportant. Note that an exponent E in the polynom maps to bit index E-1 in the LFSR.
85
-
* @param left if true, the direction of the register shift is to the left <<, the newBit is set on lfsr at bit position 0 (right). If false, shift is to the right and the newBit is stored at bit position (k-1)
86
-
* @param wrapping if true, allow repetition of values in the LFSRhistory, until maxPeriod is reached or the repeated value == start. Enabling this option saves memory as no history is kept
87
-
* @param oppositeBit if true, use the high/low bit of the LFSR to store output (for left=true/false, respectively) instead of the newBit returned by ::NextLFSR
88
-
* @return the array of pseudo random bits, or an empty array if input was incorrect
0 commit comments