From 83a710b5f2c1ee78b99d46366fce8b2ff0f30a38 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 28 Dec 2023 14:04:28 +0100 Subject: [PATCH 1/3] use the C++11 alignof operator instead of compiler specific code This should give the same result https://en.cppreference.com/w/cpp/language/alignof --- ebml/EbmlCrc32.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ebml/EbmlCrc32.h b/ebml/EbmlCrc32.h index 2bd37e58..434a2256 100644 --- a/ebml/EbmlCrc32.h +++ b/ebml/EbmlCrc32.h @@ -71,13 +71,7 @@ DECLARE_EBML_BINARY(EbmlCrc32) template inline unsigned int GetAlignment(T * /* dummy */=nullptr) // VC60 workaround { -#if defined(_MSC_VER) && (_MSC_VER >= 1300) - return __alignof(T); -#elif defined(__GNUC__) - return __alignof__(T); -#else - return sizeof(T); -#endif + return alignof(T); } template From b4b56a618a3df6752d1c94a6f4b2666e8c082a31 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 28 Dec 2023 14:08:30 +0100 Subject: [PATCH 2/3] don't export the CRC32 table It was not exported properly when building a DLL. We it's not necessary for other classes. It can be restrictued to that C++ compilation unit that noone else will see. --- ebml/EbmlCrc32.h | 1 - src/EbmlCrc32.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ebml/EbmlCrc32.h b/ebml/EbmlCrc32.h index 434a2256..8b8d720c 100644 --- a/ebml/EbmlCrc32.h +++ b/ebml/EbmlCrc32.h @@ -61,7 +61,6 @@ DECLARE_EBML_BINARY(EbmlCrc32) void ResetCRC(); void UpdateByte(binary b); - static const std::array m_tab; std::uint32_t m_crc; std::uint32_t m_crc_final{0}; diff --git a/src/EbmlCrc32.cpp b/src/EbmlCrc32.cpp index 848231a6..5fe25390 100644 --- a/src/EbmlCrc32.cpp +++ b/src/EbmlCrc32.cpp @@ -27,7 +27,7 @@ namespace libebml { DEFINE_EBML_CLASS_GLOBAL(EbmlCrc32, 0xBF, 1, "EBMLCrc32\0ratamadabapa") -constexpr std::array EbmlCrc32::m_tab { +static constexpr std::array m_tab { #ifdef WORDS_BIGENDIAN 0x00000000L, 0x96300777L, 0x2c610eeeL, 0xba510999L, 0x19c46d07L, 0x8ff46a70L, 0x35a563e9L, 0xa395649eL, 0x3288db0eL, 0xa4b8dc79L, From 1f43ee317d34567710fb7928f1aa0d4f9966d833 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 28 Dec 2023 15:52:25 +0100 Subject: [PATCH 3/3] crc32: rename m_tab to s_tab as it's a static local table --- src/EbmlCrc32.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/EbmlCrc32.cpp b/src/EbmlCrc32.cpp index 5fe25390..9e38a985 100644 --- a/src/EbmlCrc32.cpp +++ b/src/EbmlCrc32.cpp @@ -27,7 +27,7 @@ namespace libebml { DEFINE_EBML_CLASS_GLOBAL(EbmlCrc32, 0xBF, 1, "EBMLCrc32\0ratamadabapa") -static constexpr std::array m_tab { +static constexpr std::array s_tab { #ifdef WORDS_BIGENDIAN 0x00000000L, 0x96300777L, 0x2c610eeeL, 0xba510999L, 0x19c46d07L, 0x8ff46a70L, 0x35a563e9L, 0xa395649eL, 0x3288db0eL, 0xa4b8dc79L, @@ -154,7 +154,7 @@ void EbmlCrc32::ResetCRC() void EbmlCrc32::UpdateByte(binary b) { - m_crc = m_tab.at(CRC32_INDEX(m_crc) ^ b) ^ CRC32_SHIFTED(m_crc); + m_crc = s_tab.at(CRC32_INDEX(m_crc) ^ b) ^ CRC32_SHIFTED(m_crc); } void EbmlCrc32::AddElementCRC32(EbmlElement &ElementToCRC) @@ -228,20 +228,20 @@ bool EbmlCrc32::CheckCRC(std::uint32_t inputCRC, const binary *input, std::uint3 std::uint32_t crc = CRC32_NEGL; for(; !IsAligned(input) && length > 0; length--) - crc = m_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); while (length >= 4) { crc ^= *reinterpret_cast(input); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); length -= 4; input += 4; } while (length--) - crc = m_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); //Now we finalize the CRC32 crc ^= CRC32_NEGL; @@ -258,21 +258,21 @@ void EbmlCrc32::FillCRC32(const binary *input, std::uint32_t length) /*std::uint32_t crc = CRC32_NEGL; for(; !IsAligned(s) && n > 0; n--) - crc = m_tab.at(CRC32_INDEX(crc) ^ *s++) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc) ^ *s++) ^ CRC32_SHIFTED(crc); while (n >= 4) { crc ^= *(const std::uint32_t *)s; - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); n -= 4; s += 4; } while (n--) - crc = m_tab.at(CRC32_INDEX(crc) ^ *s++) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc) ^ *s++) ^ CRC32_SHIFTED(crc); m_crc = crc; @@ -288,20 +288,20 @@ void EbmlCrc32::Update(const binary *input, std::uint32_t length) std::uint32_t crc = m_crc; for(; !IsAligned(input) && length > 0; length--) - crc = m_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); while (length >= 4) { crc ^= *reinterpret_cast(input); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); - crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); length -= 4; input += 4; } while (length--) - crc = m_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); + crc = s_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); m_crc = crc; }