1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-01 22:41:32 +00:00

Allow LFSR to be instantiated with a given value.

This commit is contained in:
Thomas Harte 2020-04-05 22:58:09 -04:00
parent db4b71fc9a
commit 027af5acca

View File

@ -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.