crc32_braid_comb.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* crc32_braid_comb.c -- compute the CRC-32 of a data stream
  2. * Copyright (C) 1995-2022 Mark Adler
  3. * For conditions of distribution and use, see copyright notice in zlib.h
  4. *
  5. * This interleaved implementation of a CRC makes use of pipelined multiple
  6. * arithmetic-logic units, commonly found in modern CPU cores. It is due to
  7. * Kadatch and Jenkins (2010). See doc/crc-doc.1.0.pdf in this distribution.
  8. */
  9. #include "zutil.h"
  10. #include "crc32_braid_p.h"
  11. #include "crc32_braid_tbl.h"
  12. #include "crc32_braid_comb_p.h"
  13. /* ========================================================================= */
  14. static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2) {
  15. return multmodp(x2nmodp(len2, 3), crc1) ^ crc2;
  16. }
  17. static uint32_t crc32_combine_gen_(z_off64_t len2) {
  18. return x2nmodp(len2, 3);
  19. }
  20. static uint32_t crc32_combine_op_(uint32_t crc1, uint32_t crc2, const uint32_t op) {
  21. return multmodp(op, crc1) ^ crc2;
  22. }
  23. /* ========================================================================= */
  24. #ifdef ZLIB_COMPAT
  25. unsigned long Z_EXPORT PREFIX(crc32_combine)(unsigned long crc1, unsigned long crc2, z_off_t len2) {
  26. return (unsigned long)crc32_combine_((uint32_t)crc1, (uint32_t)crc2, len2);
  27. }
  28. unsigned long Z_EXPORT PREFIX4(crc32_combine)(unsigned long crc1, unsigned long crc2, z_off64_t len2) {
  29. return (unsigned long)crc32_combine_((uint32_t)crc1, (uint32_t)crc2, len2);
  30. }
  31. unsigned long Z_EXPORT PREFIX(crc32_combine_gen)(z_off_t len2) {
  32. return crc32_combine_gen_(len2);
  33. }
  34. unsigned long Z_EXPORT PREFIX4(crc32_combine_gen)(z_off64_t len2) {
  35. return crc32_combine_gen_(len2);
  36. }
  37. unsigned long Z_EXPORT PREFIX(crc32_combine_op)(unsigned long crc1, unsigned long crc2, const unsigned long op) {
  38. return (unsigned long)crc32_combine_op_((uint32_t)crc1, (uint32_t)crc2, (uint32_t)op);
  39. }
  40. #else
  41. uint32_t Z_EXPORT PREFIX4(crc32_combine)(uint32_t crc1, uint32_t crc2, z_off64_t len2) {
  42. return crc32_combine_(crc1, crc2, len2);
  43. }
  44. uint32_t Z_EXPORT PREFIX(crc32_combine_gen)(z_off64_t len2) {
  45. return crc32_combine_gen_(len2);
  46. }
  47. uint32_t Z_EXPORT PREFIX(crc32_combine_op)(uint32_t crc1, uint32_t crc2, const uint32_t op) {
  48. return crc32_combine_op_(crc1, crc2, op);
  49. }
  50. #endif
  51. /* ========================================================================= */