mirror of https://github.com/AxioDL/metaforce.git
CCRC32: Move table declaration into the cpp file
This can be moved entirely into the cpp file, making it an implementation detail.
This commit is contained in:
parent
4a4781de76
commit
f430a00314
|
@ -1,8 +1,10 @@
|
||||||
#include "CCRC32.hpp"
|
#include "Runtime/CCRC32.hpp"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
namespace {
|
||||||
const uint32_t CCRC32::crc32Table[256] = {
|
constexpr std::array<uint32_t, 256> crc32Table{
|
||||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832,
|
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832,
|
||||||
0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
|
0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
|
||||||
0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A,
|
0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A,
|
||||||
|
@ -31,14 +33,19 @@ const uint32_t CCRC32::crc32Table[256] = {
|
||||||
0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
|
0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
|
||||||
0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330,
|
0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330,
|
||||||
0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
|
0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
|
||||||
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D};
|
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr uint32_t permute(uint32_t checksum, uint8_t b) { return (checksum >> 8) ^ crc32Table[(checksum & 0xFF) ^ b]; }
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
uint32_t CCRC32::Calculate(const void* data, uint32_t length) {
|
uint32_t CCRC32::Calculate(const void* data, uint32_t length) {
|
||||||
if (!data || length == 0)
|
if (data == nullptr || length == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t checksum = 0xFFFFFFFF;
|
uint32_t checksum = 0xFFFFFFFF;
|
||||||
const uint8_t* buf = reinterpret_cast<const uint8_t*>(data);
|
const uint8_t* buf = static_cast<const uint8_t*>(data);
|
||||||
uint32_t words = length / 4;
|
uint32_t words = length / 4;
|
||||||
while ((words--) > 0) {
|
while ((words--) > 0) {
|
||||||
checksum = permute(checksum, *buf++);
|
checksum = permute(checksum, *buf++);
|
||||||
|
@ -48,8 +55,9 @@ uint32_t CCRC32::Calculate(const void* data, uint32_t length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t rem = length % 4;
|
uint32_t rem = length % 4;
|
||||||
while ((rem--) > 0)
|
while ((rem--) > 0) {
|
||||||
checksum = permute(checksum, *buf++);
|
checksum = permute(checksum, *buf++);
|
||||||
|
}
|
||||||
|
|
||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
|
||||||
class CCRC32 {
|
class CCRC32 {
|
||||||
static const uint32_t crc32Table[256];
|
|
||||||
static uint32_t permute(uint32_t checksum, uint8_t b) {
|
|
||||||
return (checksum >> 8) ^ crc32Table[(checksum & 0xFF) ^ b];
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static uint32_t Calculate(const void* data, uint32_t length);
|
static uint32_t Calculate(const void* data, uint32_t length);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue