Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constexpr CRC for C++23 #907

Prev Previous commit
Next Next commit
crc: add constexpr for C++23
Jan Dorniak committed Jun 25, 2024
commit 741187a0fcc25fde0ec20dd819be3f529056bd87
12 changes: 6 additions & 6 deletions include/etl/frame_check_sequence.h
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
ETL_CONSTEXPR frame_check_sequence()
ETL_CONSTEXPR14 frame_check_sequence()
{
reset();
}
@@ -118,7 +118,7 @@ namespace etl
/// \param end End of the range.
//*************************************************************************
template<typename TIterator>
ETL_CONSTEXPR frame_check_sequence(TIterator begin, const TIterator end)
ETL_CONSTEXPR14 frame_check_sequence(TIterator begin, const TIterator end)
{
ETL_STATIC_ASSERT(sizeof(typename etl::iterator_traits<TIterator>::value_type) == 1, "Type not supported");

@@ -129,7 +129,7 @@ namespace etl
//*************************************************************************
/// Resets the FCS to the initial state.
//*************************************************************************
ETL_CONSTEXPR void reset()
ETL_CONSTEXPR14 void reset()
{
frame_check = policy.initial();
}
@@ -140,7 +140,7 @@ namespace etl
/// \param end
//*************************************************************************
template<typename TIterator>
ETL_CONSTEXPR void add(TIterator begin, const TIterator end)
ETL_CONSTEXPR23 void add(TIterator begin, const TIterator end)
{
ETL_STATIC_ASSERT(sizeof(typename etl::iterator_traits<TIterator>::value_type) == 1, "Type not supported");

@@ -154,15 +154,15 @@ namespace etl
//*************************************************************************
/// \param value The uint8_t to add to the FCS.
//*************************************************************************
ETL_CONSTEXPR void add(uint8_t value_)
ETL_CONSTEXPR23 void add(uint8_t value_)
{
frame_check = policy.add(frame_check, value_);
}

//*************************************************************************
/// Gets the FCS value.
//*************************************************************************
ETL_CONSTEXPR value_type value() const
ETL_CONSTEXPR14 value_type value() const
{
return policy.final(frame_check);
}
10 changes: 5 additions & 5 deletions include/etl/private/crc_implementation.h
Original file line number Diff line number Diff line change
@@ -241,7 +241,7 @@ namespace etl
struct crc_table<TAccumulator, Accumulator_Bits, Chunk_Bits, Chunk_Mask, Polynomial, Reflect, 4U>
{
//*************************************************************************
TAccumulator add(TAccumulator crc, uint8_t value) const
ETL_CONSTEXPR23 TAccumulator add(TAccumulator crc, uint8_t value) const
{
static ETL_CONSTANT TAccumulator table[4U] =
{
@@ -276,7 +276,7 @@ namespace etl
struct crc_table<TAccumulator, Accumulator_Bits, Chunk_Bits, Chunk_Mask, Polynomial, Reflect, 16U>
{
//*************************************************************************
TAccumulator add(TAccumulator crc, uint8_t value) const
ETL_CONSTEXPR23 TAccumulator add(TAccumulator crc, uint8_t value) const
{
static ETL_CONSTANT TAccumulator table[16U] =
{
@@ -319,7 +319,7 @@ namespace etl
struct crc_table<TAccumulator, Accumulator_Bits, Chunk_Bits, Chunk_Mask, Polynomial, Reflect, 256U>
{
//*************************************************************************
ETL_CONSTEXPR TAccumulator add(TAccumulator crc, uint8_t value) const
ETL_CONSTEXPR23 TAccumulator add(TAccumulator crc, uint8_t value) const
{
static ETL_CONSTANT TAccumulator table[256U] =
{
@@ -691,7 +691,7 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
ETL_CONSTEXPR crc_type()
ETL_CONSTEXPR14 crc_type()
{
this->reset();
}
@@ -702,7 +702,7 @@ namespace etl
/// \param end End of the range.
//*************************************************************************
template<typename TIterator>
ETL_CONSTEXPR crc_type(TIterator begin, const TIterator end)
ETL_CONSTEXPR14 crc_type(TIterator begin, const TIterator end)
{
this->reset();
this->add(begin, end);