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.

69 lines
1.8 KiB

  1. /* XzCrc64Opt.c -- CRC64 calculation
  2. 2011-06-28 : 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. UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *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. UInt32 d = (UInt32)v ^ *(const UInt32 *)p;
  15. v = (v >> 32) ^
  16. table[0x300 + ((d ) & 0xFF)] ^
  17. table[0x200 + ((d >> 8) & 0xFF)] ^
  18. table[0x100 + ((d >> 16) & 0xFF)] ^
  19. table[0x000 + ((d >> 24))];
  20. }
  21. for (; size > 0; size--, p++)
  22. v = CRC_UPDATE_BYTE_2(v, *p);
  23. return v;
  24. }
  25. #endif
  26. #ifndef MY_CPU_LE
  27. #define CRC_UINT64_SWAP(v) \
  28. ((v >> 56) | \
  29. ((v >> 40) & ((UInt64)0xFF << 8)) | \
  30. ((v >> 24) & ((UInt64)0xFF << 16)) | \
  31. ((v >> 8) & ((UInt64)0xFF << 24)) | \
  32. ((v << 8) & ((UInt64)0xFF << 32)) | \
  33. ((v << 24) & ((UInt64)0xFF << 40)) | \
  34. ((v << 40) & ((UInt64)0xFF << 48)) | \
  35. (v << 56))
  36. UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table)
  37. {
  38. const Byte *p = (const Byte *)data;
  39. for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
  40. v = CRC_UPDATE_BYTE_2(v, *p);
  41. v = CRC_UINT64_SWAP(v);
  42. table += 0x100;
  43. for (; size >= 4; size -= 4, p += 4)
  44. {
  45. UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)p;
  46. v = (v << 32) ^
  47. table[0x000 + ((d ) & 0xFF)] ^
  48. table[0x100 + ((d >> 8) & 0xFF)] ^
  49. table[0x200 + ((d >> 16) & 0xFF)] ^
  50. table[0x300 + ((d >> 24))];
  51. }
  52. table -= 0x100;
  53. v = CRC_UINT64_SWAP(v);
  54. for (; size > 0; size--, p++)
  55. v = CRC_UPDATE_BYTE_2(v, *p);
  56. return v;
  57. }
  58. #endif