ReactOS 0.4.15-dev-7953-g1f49173
crc32.c File Reference
#include "zutil.h"
#include "crc32.h"
Include dependency graph for crc32.c:

Go to the source code of this file.

Macros

#define N   5
 
#define W   4
 
#define POLY   0xedb88320 /* p(x) reflected, with x^32 implied */
 

Functions

z_crc_t multmodp OF ((z_crc_t a, z_crc_t b))
 
z_crc_t x2nmodp OF ((z_off64_t n, unsigned k))
 
z_crc_t multmodp (z_crc_t a, z_crc_t b)
 
z_crc_t x2nmodp (z_off64_t n, unsigned k)
 
const z_crc_t FAR *ZEXPORT get_crc_table ()
 
unsigned long ZEXPORT crc32_z (unsigned long crc, const unsigned char FAR *buf, z_size_t len)
 
unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, uInt len)
 
uLong ZEXPORT crc32_combine64 (uLong crc1, uLong crc2, z_off64_t len2)
 
uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
 
uLong ZEXPORT crc32_combine_gen64 (z_off64_t len2)
 
uLong ZEXPORT crc32_combine_gen (z_off_t len2)
 
uLong ZEXPORT crc32_combine_op (uLong crc1, uLong crc2, uLong op)
 

Macro Definition Documentation

◆ N

#define N   5

Definition at line 57 of file crc32.c.

◆ POLY

#define POLY   0xedb88320 /* p(x) reflected, with x^32 implied */

Definition at line 150 of file crc32.c.

◆ W

#define W   4

Definition at line 85 of file crc32.c.

Function Documentation

◆ crc32()

unsigned long ZEXPORT crc32 ( unsigned long  crc,
const unsigned char FAR buf,
uInt  len 
)

Definition at line 1072 of file crc32.c.

1076{
1077 return crc32_z(crc, buf, len);
1078}
unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, z_size_t len)
Definition: crc32.c:748
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722

◆ crc32_combine()

uLong ZEXPORT crc32_combine ( uLong  crc1,
uLong  crc2,
z_off_t  len2 
)

Definition at line 1093 of file crc32.c.

1097{
1098 return crc32_combine64(crc1, crc2, (z_off64_t)len2);
1099}
uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2)
Definition: crc32.c:1081
#define z_off64_t
Definition: zconf.h:526

◆ crc32_combine64()

uLong ZEXPORT crc32_combine64 ( uLong  crc1,
uLong  crc2,
z_off64_t  len2 
)

Definition at line 1081 of file crc32.c.

1085{
1086#ifdef DYNAMIC_CRC_TABLE
1087 once(&made, make_crc_table);
1088#endif /* DYNAMIC_CRC_TABLE */
1089 return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
1090}
z_crc_t x2nmodp(z_off64_t n, unsigned k)
Definition: crc32.c:575
z_crc_t multmodp(z_crc_t a, z_crc_t b)
Definition: crc32.c:551

Referenced by crc32_combine().

◆ crc32_combine_gen()

uLong ZEXPORT crc32_combine_gen ( z_off_t  len2)

Definition at line 1112 of file crc32.c.

1114{
1115 return crc32_combine_gen64((z_off64_t)len2);
1116}
uLong ZEXPORT crc32_combine_gen64(z_off64_t len2)
Definition: crc32.c:1102

◆ crc32_combine_gen64()

uLong ZEXPORT crc32_combine_gen64 ( z_off64_t  len2)

Definition at line 1102 of file crc32.c.

1104{
1105#ifdef DYNAMIC_CRC_TABLE
1106 once(&made, make_crc_table);
1107#endif /* DYNAMIC_CRC_TABLE */
1108 return x2nmodp(len2, 3);
1109}

Referenced by crc32_combine_gen().

◆ crc32_combine_op()

uLong ZEXPORT crc32_combine_op ( uLong  crc1,
uLong  crc2,
uLong  op 
)

Definition at line 1119 of file crc32.c.

1123{
1124 return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
1125}
UINT op
Definition: effect.c:236

◆ crc32_z()

unsigned long ZEXPORT crc32_z ( unsigned long  crc,
const unsigned char FAR buf,
z_size_t  len 
)

Definition at line 748 of file crc32.c.

752{
753 /* Return initial CRC, if requested. */
754 if (buf == Z_NULL) return 0;
755
756#ifdef DYNAMIC_CRC_TABLE
757 once(&made, make_crc_table);
758#endif /* DYNAMIC_CRC_TABLE */
759
760 /* Pre-condition the CRC */
761 crc = (~crc) & 0xffffffff;
762
763#ifdef W
764
765 /* If provided enough bytes, do a braided CRC calculation. */
766 if (len >= N * W + W - 1) {
767 z_size_t blks;
768 z_word_t const *words;
769 unsigned endian;
770 int k;
771
772 /* Compute the CRC up to a z_word_t boundary. */
773 while (len && ((z_size_t)buf & (W - 1)) != 0) {
774 len--;
775 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
776 }
777
778 /* Compute the CRC on as many N z_word_t blocks as are available. */
779 blks = len / (N * W);
780 len -= blks * N * W;
781 words = (z_word_t const *)buf;
782
783 /* Do endian check at execution time instead of compile time, since ARM
784 processors can change the endianess at execution time. If the
785 compiler knows what the endianess will be, it can optimize out the
786 check and the unused branch. */
787 endian = 1;
788 if (*(unsigned char *)&endian) {
789 /* Little endian. */
790
791 z_crc_t crc0;
792 z_word_t word0;
793#if N > 1
794 z_crc_t crc1;
795 z_word_t word1;
796#if N > 2
797 z_crc_t crc2;
798 z_word_t word2;
799#if N > 3
800 z_crc_t crc3;
801 z_word_t word3;
802#if N > 4
803 z_crc_t crc4;
804 z_word_t word4;
805#if N > 5
806 z_crc_t crc5;
807 z_word_t word5;
808#endif
809#endif
810#endif
811#endif
812#endif
813
814 /* Initialize the CRC for each braid. */
815 crc0 = crc;
816#if N > 1
817 crc1 = 0;
818#if N > 2
819 crc2 = 0;
820#if N > 3
821 crc3 = 0;
822#if N > 4
823 crc4 = 0;
824#if N > 5
825 crc5 = 0;
826#endif
827#endif
828#endif
829#endif
830#endif
831
832 /*
833 Process the first blks-1 blocks, computing the CRCs on each braid
834 independently.
835 */
836 while (--blks) {
837 /* Load the word for each braid into registers. */
838 word0 = crc0 ^ words[0];
839#if N > 1
840 word1 = crc1 ^ words[1];
841#if N > 2
842 word2 = crc2 ^ words[2];
843#if N > 3
844 word3 = crc3 ^ words[3];
845#if N > 4
846 word4 = crc4 ^ words[4];
847#if N > 5
848 word5 = crc5 ^ words[5];
849#endif
850#endif
851#endif
852#endif
853#endif
854 words += N;
855
856 /* Compute and update the CRC for each word. The loop should
857 get unrolled. */
858 crc0 = crc_braid_table[0][word0 & 0xff];
859#if N > 1
860 crc1 = crc_braid_table[0][word1 & 0xff];
861#if N > 2
862 crc2 = crc_braid_table[0][word2 & 0xff];
863#if N > 3
864 crc3 = crc_braid_table[0][word3 & 0xff];
865#if N > 4
866 crc4 = crc_braid_table[0][word4 & 0xff];
867#if N > 5
868 crc5 = crc_braid_table[0][word5 & 0xff];
869#endif
870#endif
871#endif
872#endif
873#endif
874 for (k = 1; k < W; k++) {
875 crc0 ^= crc_braid_table[k][(word0 >> (k << 3)) & 0xff];
876#if N > 1
877 crc1 ^= crc_braid_table[k][(word1 >> (k << 3)) & 0xff];
878#if N > 2
879 crc2 ^= crc_braid_table[k][(word2 >> (k << 3)) & 0xff];
880#if N > 3
881 crc3 ^= crc_braid_table[k][(word3 >> (k << 3)) & 0xff];
882#if N > 4
883 crc4 ^= crc_braid_table[k][(word4 >> (k << 3)) & 0xff];
884#if N > 5
885 crc5 ^= crc_braid_table[k][(word5 >> (k << 3)) & 0xff];
886#endif
887#endif
888#endif
889#endif
890#endif
891 }
892 }
893
894 /*
895 Process the last block, combining the CRCs of the N braids at the
896 same time.
897 */
898 crc = crc_word(crc0 ^ words[0]);
899#if N > 1
900 crc = crc_word(crc1 ^ words[1] ^ crc);
901#if N > 2
902 crc = crc_word(crc2 ^ words[2] ^ crc);
903#if N > 3
904 crc = crc_word(crc3 ^ words[3] ^ crc);
905#if N > 4
906 crc = crc_word(crc4 ^ words[4] ^ crc);
907#if N > 5
908 crc = crc_word(crc5 ^ words[5] ^ crc);
909#endif
910#endif
911#endif
912#endif
913#endif
914 words += N;
915 }
916 else {
917 /* Big endian. */
918
919 z_word_t crc0, word0, comb;
920#if N > 1
921 z_word_t crc1, word1;
922#if N > 2
923 z_word_t crc2, word2;
924#if N > 3
925 z_word_t crc3, word3;
926#if N > 4
927 z_word_t crc4, word4;
928#if N > 5
929 z_word_t crc5, word5;
930#endif
931#endif
932#endif
933#endif
934#endif
935
936 /* Initialize the CRC for each braid. */
937 crc0 = byte_swap(crc);
938#if N > 1
939 crc1 = 0;
940#if N > 2
941 crc2 = 0;
942#if N > 3
943 crc3 = 0;
944#if N > 4
945 crc4 = 0;
946#if N > 5
947 crc5 = 0;
948#endif
949#endif
950#endif
951#endif
952#endif
953
954 /*
955 Process the first blks-1 blocks, computing the CRCs on each braid
956 independently.
957 */
958 while (--blks) {
959 /* Load the word for each braid into registers. */
960 word0 = crc0 ^ words[0];
961#if N > 1
962 word1 = crc1 ^ words[1];
963#if N > 2
964 word2 = crc2 ^ words[2];
965#if N > 3
966 word3 = crc3 ^ words[3];
967#if N > 4
968 word4 = crc4 ^ words[4];
969#if N > 5
970 word5 = crc5 ^ words[5];
971#endif
972#endif
973#endif
974#endif
975#endif
976 words += N;
977
978 /* Compute and update the CRC for each word. The loop should
979 get unrolled. */
980 crc0 = crc_braid_big_table[0][word0 & 0xff];
981#if N > 1
982 crc1 = crc_braid_big_table[0][word1 & 0xff];
983#if N > 2
984 crc2 = crc_braid_big_table[0][word2 & 0xff];
985#if N > 3
986 crc3 = crc_braid_big_table[0][word3 & 0xff];
987#if N > 4
988 crc4 = crc_braid_big_table[0][word4 & 0xff];
989#if N > 5
990 crc5 = crc_braid_big_table[0][word5 & 0xff];
991#endif
992#endif
993#endif
994#endif
995#endif
996 for (k = 1; k < W; k++) {
997 crc0 ^= crc_braid_big_table[k][(word0 >> (k << 3)) & 0xff];
998#if N > 1
999 crc1 ^= crc_braid_big_table[k][(word1 >> (k << 3)) & 0xff];
1000#if N > 2
1001 crc2 ^= crc_braid_big_table[k][(word2 >> (k << 3)) & 0xff];
1002#if N > 3
1003 crc3 ^= crc_braid_big_table[k][(word3 >> (k << 3)) & 0xff];
1004#if N > 4
1005 crc4 ^= crc_braid_big_table[k][(word4 >> (k << 3)) & 0xff];
1006#if N > 5
1007 crc5 ^= crc_braid_big_table[k][(word5 >> (k << 3)) & 0xff];
1008#endif
1009#endif
1010#endif
1011#endif
1012#endif
1013 }
1014 }
1015
1016 /*
1017 Process the last block, combining the CRCs of the N braids at the
1018 same time.
1019 */
1020 comb = crc_word_big(crc0 ^ words[0]);
1021#if N > 1
1022 comb = crc_word_big(crc1 ^ words[1] ^ comb);
1023#if N > 2
1024 comb = crc_word_big(crc2 ^ words[2] ^ comb);
1025#if N > 3
1026 comb = crc_word_big(crc3 ^ words[3] ^ comb);
1027#if N > 4
1028 comb = crc_word_big(crc4 ^ words[4] ^ comb);
1029#if N > 5
1030 comb = crc_word_big(crc5 ^ words[5] ^ comb);
1031#endif
1032#endif
1033#endif
1034#endif
1035#endif
1036 words += N;
1037 crc = byte_swap(comb);
1038 }
1039
1040 /*
1041 Update the pointer to the remaining bytes to process.
1042 */
1043 buf = (unsigned char const *)words;
1044 }
1045
1046#endif /* W */
1047
1048 /* Complete the computation of the CRC on any remaining bytes. */
1049 while (len >= 8) {
1050 len -= 8;
1051 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1052 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1053 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1054 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1055 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1056 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1057 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1058 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1059 }
1060 while (len) {
1061 len--;
1062 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1063 }
1064
1065 /* Return the CRC, post-conditioned. */
1066 return crc ^ 0xffffffff;
1067}
#define N
Definition: crc32.c:57
#define W
Definition: crc32.c:85
const z_crc_t FAR crc_table[]
Definition: crc32.h:5
#define Z_NULL
Definition: zlib.h:149
int k
Definition: mpi.c:3369
Definition: polytest.cpp:36
unsigned long z_crc_t
Definition: zconf.h:437
unsigned long z_size_t
Definition: zconf.h:253

Referenced by crc32().

◆ get_crc_table()

const z_crc_t FAR *ZEXPORT get_crc_table ( )

Definition at line 595 of file crc32.c.

596{
597#ifdef DYNAMIC_CRC_TABLE
598 once(&made, make_crc_table);
599#endif /* DYNAMIC_CRC_TABLE */
600 return (const z_crc_t FAR *)crc_table;
601}
#define FAR
Definition: zlib.h:34

Referenced by unzOpenCurrentFile3(), and zipOpenNewFileInZip4_64().

◆ multmodp()

z_crc_t multmodp ( z_crc_t  a,
z_crc_t  b 
)

Definition at line 551 of file crc32.c.

554{
555 z_crc_t m, p;
556
557 m = (z_crc_t)1 << 31;
558 p = 0;
559 for (;;) {
560 if (a & m) {
561 p ^= b;
562 if ((a & (m - 1)) == 0)
563 break;
564 }
565 m >>= 1;
566 b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
567 }
568 return p;
569}
#define POLY
Definition: crc32.c:150
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLfloat GLfloat p
Definition: glext.h:8902
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
const GLfloat * m
Definition: glext.h:10848
#define b
Definition: ke_i.h:79

Referenced by crc32_combine64(), crc32_combine_op(), and x2nmodp().

◆ OF() [1/2]

◆ OF() [2/2]

◆ x2nmodp()

z_crc_t x2nmodp ( z_off64_t  n,
unsigned  k 
)

Definition at line 575 of file crc32.c.

578{
579 z_crc_t p;
580
581 p = (z_crc_t)1 << 31; /* x^0 == 1 */
582 while (n) {
583 if (n & 1)
584 p = multmodp(x2n_table[k & 31], p);
585 n >>= 1;
586 k++;
587 }
588 return p;
589}
const z_crc_t FAR x2n_table[]
Definition: crc32.h:9439
GLdouble n
Definition: glext.h:7729

Referenced by crc32_combine64(), and crc32_combine_gen64().