mirror of
https://github.com/TomHarte/CLK.git
synced 2025-08-09 05:25:01 +00:00
Allow LFSR to be instantiated with a given value.
This commit is contained in:
@@ -37,6 +37,9 @@ template <> struct LSFRPolynomial<uint8_t> {
|
|||||||
*/
|
*/
|
||||||
template <typename IntType = uint64_t, IntType polynomial = LSFRPolynomial<IntType>::value> class LFSR {
|
template <typename IntType = uint64_t, IntType polynomial = LSFRPolynomial<IntType>::value> class LFSR {
|
||||||
public:
|
public:
|
||||||
|
/*!
|
||||||
|
Constructs an LFSR with a random initial value.
|
||||||
|
*/
|
||||||
LFSR() {
|
LFSR() {
|
||||||
// Randomise the value, ensuring it doesn't end up being 0.
|
// Randomise the value, ensuring it doesn't end up being 0.
|
||||||
while(!value_) {
|
while(!value_) {
|
||||||
@@ -48,6 +51,13 @@ template <typename IntType = uint64_t, IntType polynomial = LSFRPolynomial<IntTy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Constructs an LFSR with the specified initial value.
|
||||||
|
|
||||||
|
An initial value of 0 is invalid.
|
||||||
|
*/
|
||||||
|
LFSR(IntType initial_value) : value_(initial_value) {}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Advances the LSFR, returning either an @c IntType of value @c 1 or @c 0,
|
Advances the LSFR, returning either an @c IntType of value @c 1 or @c 0,
|
||||||
determining the bit that was just shifted out.
|
determining the bit that was just shifted out.
|
||||||
|
Reference in New Issue
Block a user