mirror of
https://github.com/TomHarte/CLK.git
synced 2026-03-11 04:42:20 +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 {
|
||||
public:
|
||||
/*!
|
||||
Constructs an LFSR with a random initial value.
|
||||
*/
|
||||
LFSR() {
|
||||
// Randomise the value, ensuring it doesn't end up being 0.
|
||||
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,
|
||||
determining the bit that was just shifted out.
|
||||
|
||||
Reference in New Issue
Block a user