2020-11-25 14:49:23 +00:00
|
|
|
// Copyright 2020 Mobilinkd LLC.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-03-12 13:57:01 +00:00
|
|
|
#include <bit>
|
2020-11-25 14:49:23 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
namespace mobilinkd
|
|
|
|
{
|
|
|
|
|
|
|
|
inline constexpr uint32_t convolve_bit(uint32_t poly, uint32_t memory)
|
|
|
|
{
|
2022-03-12 13:57:01 +00:00
|
|
|
return std::popcount(poly & memory) & 1;
|
2020-11-25 14:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t K, size_t k = 1>
|
|
|
|
inline constexpr uint32_t update_memory(uint32_t memory, uint32_t input)
|
|
|
|
{
|
|
|
|
return (memory << k | input) & ((1 << (K + 1)) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // mobilinkd
|