crc32_braid_p.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef CRC32_BRAID_P_H_
  2. #define CRC32_BRAID_P_H_
  3. #include "zendian.h"
  4. /* Define N */
  5. #ifdef Z_TESTN
  6. # define N Z_TESTN
  7. #else
  8. # define N 5
  9. #endif
  10. #if N < 1 || N > 6
  11. # error N must be in 1..6
  12. #endif
  13. /*
  14. Define W and the associated z_word_t type. If W is not defined, then a
  15. braided calculation is not used, and the associated tables and code are not
  16. compiled.
  17. */
  18. #ifdef Z_TESTW
  19. # if Z_TESTW-1 != -1
  20. # define W Z_TESTW
  21. # endif
  22. #else
  23. # ifndef W
  24. # if defined(__x86_64__) || defined(_M_AMD64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__)
  25. # define W 8
  26. # else
  27. # define W 4
  28. # endif
  29. # endif
  30. #endif
  31. #ifdef W
  32. # if W == 8
  33. typedef uint64_t z_word_t;
  34. # else
  35. # undef W
  36. # define W 4
  37. typedef uint32_t z_word_t;
  38. # endif
  39. #endif
  40. #if BYTE_ORDER == LITTLE_ENDIAN
  41. # define ZSWAPWORD(word) (word)
  42. # define BRAID_TABLE crc_braid_table
  43. #elif BYTE_ORDER == BIG_ENDIAN
  44. # if W == 8
  45. # define ZSWAPWORD(word) ZSWAP64(word)
  46. # elif W == 4
  47. # define ZSWAPWORD(word) ZSWAP32(word)
  48. # endif
  49. # define BRAID_TABLE crc_braid_big_table
  50. #else
  51. # error "No endian defined"
  52. #endif
  53. #define DO1 c = crc_table[(c ^ *buf++) & 0xff] ^ (c >> 8)
  54. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  55. /* CRC polynomial. */
  56. #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */
  57. #endif /* CRC32_BRAID_P_H_ */