7zCrcT8.c 881 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* 7zCrcT8.c */
  2. #include "7zCrc.h"
  3. #define kCrcPoly 0xEDB88320
  4. #define CRC_NUM_TABLES 8
  5. UInt32 g_CrcTable[256 * CRC_NUM_TABLES];
  6. void MY_FAST_CALL CrcGenerateTable()
  7. {
  8. UInt32 i;
  9. for (i = 0; i < 256; i++)
  10. {
  11. UInt32 r = i;
  12. int j;
  13. for (j = 0; j < 8; j++)
  14. r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
  15. g_CrcTable[i] = r;
  16. }
  17. #if CRC_NUM_TABLES > 1
  18. for (; i < 256 * CRC_NUM_TABLES; i++)
  19. {
  20. UInt32 r = g_CrcTable[i - 256];
  21. g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
  22. }
  23. #endif
  24. }
  25. UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
  26. UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
  27. {
  28. return CrcUpdateT8(v, data, size, g_CrcTable);
  29. }
  30. UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
  31. {
  32. return CrcUpdateT8(CRC_INIT_VAL, data, size, g_CrcTable) ^ 0xFFFFFFFF;
  33. }