Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

  1. /* 7zCrcOpt.c -- CRC32 calculation
  2. 2013-11-12 : Igor Pavlov : Public domain */
  3. #include "Precomp.h"
  4. #include "CpuArch.h"
  5. #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
  6. #ifndef MY_CPU_BE
  7. UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table)
  8. {
  9. const Byte *p = (const Byte *)data;
  10. for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
  11. v = CRC_UPDATE_BYTE_2(v, *p);
  12. for (; size >= 4; size -= 4, p += 4)
  13. {
  14. v ^= *(const UInt32 *)p;
  15. v =
  16. table[0x300 + (v & 0xFF)] ^
  17. table[0x200 + ((v >> 8) & 0xFF)] ^
  18. table[0x100 + ((v >> 16) & 0xFF)] ^
  19. table[0x000 + ((v >> 24))];
  20. }
  21. for (; size > 0; size--, p++)
  22. v = CRC_UPDATE_BYTE_2(v, *p);
  23. return v;
  24. }
  25. UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table)
  26. {
  27. return CrcUpdateT4(v, data, size, table);
  28. }
  29. #endif
  30. #ifndef MY_CPU_LE
  31. #define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24))
  32. UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table)
  33. {
  34. const Byte *p = (const Byte *)data;
  35. for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
  36. v = CRC_UPDATE_BYTE_2(v, *p);
  37. v = CRC_UINT32_SWAP(v);
  38. table += 0x100;
  39. for (; size >= 4; size -= 4, p += 4)
  40. {
  41. v ^= *(const UInt32 *)p;
  42. v =
  43. table[0x000 + (v & 0xFF)] ^
  44. table[0x100 + ((v >> 8) & 0xFF)] ^
  45. table[0x200 + ((v >> 16) & 0xFF)] ^
  46. table[0x300 + ((v >> 24))];
  47. }
  48. table -= 0x100;
  49. v = CRC_UINT32_SWAP(v);
  50. for (; size > 0; size--, p++)
  51. v = CRC_UPDATE_BYTE_2(v, *p);
  52. return v;
  53. }
  54. #endif