Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
crc32.cc File Reference
#include "zutil.h"
#include "crc32.h"

Go to the source code of this file.

Macros

#define local   static
 
#define TBLS   1
 
#define DO1   crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
 
#define DO8   DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
 
#define GF2_DIM   32 /* dimension of GF(2) vectors (length of CRC) */
 

Functions

local unsigned long
gf2_matrix_times 
OF ((unsigned long *mat, unsigned long vec))
 
local void gf2_matrix_square OF ((unsigned long *square, unsigned long *mat))
 
local uLong crc32_combine_ OF ((uLong crc1, uLong crc2, z_off64_t len2))
 
const z_crc_t FAR *ZEXPORT get_crc_table ()
 
unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, uInt len)
 
local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
 
local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
 
local uLong crc32_combine_ (uLong crc1, uLong crc2, z_off64_t len2)
 
uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
 
uLong ZEXPORT crc32_combine64 (uLong crc1, uLong crc2, z_off64_t len2)
 

Macro Definition Documentation

#define DO1   crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)

Definition at line 198 of file crc32.cc.

Referenced by crc32().

#define DO8   DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1

Definition at line 199 of file crc32.cc.

Referenced by crc32().

#define GF2_DIM   32 /* dimension of GF(2) vectors (length of CRC) */

Definition at line 313 of file crc32.cc.

Referenced by crc32_combine_(), and gf2_matrix_square().

#define local   static

Definition at line 33 of file crc32.cc.

#define TBLS   1

Definition at line 46 of file crc32.cc.

Function Documentation

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

Definition at line 202 of file crc32.cc.

References DO1, DO8, and Z_NULL.

Referenced by deflate(), deflateResetKeep(), inflate(), and read_buf().

203 {
204  if (buf == Z_NULL) return 0UL;
205 
206 #ifdef DYNAMIC_CRC_TABLE
207  if (crc_table_empty)
208  make_crc_table();
209 #endif /* DYNAMIC_CRC_TABLE */
210 
211 #ifdef BYFOUR
212  if (sizeof(void *) == sizeof(ptrdiff_t)) {
213  z_crc_t endian;
214 
215  endian = 1;
216  if (*((unsigned char *)(&endian)))
217  return crc32_little(crc, buf, len);
218  else
219  return crc32_big(crc, buf, len);
220  }
221 #endif /* BYFOUR */
222  crc = crc ^ 0xffffffffUL;
223  while (len >= 8) {
224  DO8;
225  len -= 8;
226  }
227  if (len) do {
228  DO1;
229  } while (--len);
230  return crc ^ 0xffffffffUL;
231 }
#define DO8
Definition: crc32.cc:199
const XML_Char int len
#define Z_NULL
Definition: zlib.h:208
#define DO1
Definition: crc32.cc:198
uLong ZEXPORT crc32_combine ( uLong  crc1,
uLong  crc2,
z_off_t  len2 
)

Definition at line 393 of file crc32.cc.

References crc32_combine_().

394 {
395  return crc32_combine_(crc1, crc2, len2);
396 }
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
Definition: crc32.cc:340
uLong ZEXPORT crc32_combine64 ( uLong  crc1,
uLong  crc2,
z_off64_t  len2 
)

Definition at line 398 of file crc32.cc.

References crc32_combine_().

399 {
400  return crc32_combine_(crc1, crc2, len2);
401 }
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2)
Definition: crc32.cc:340
local uLong crc32_combine_ ( uLong  crc1,
uLong  crc2,
z_off64_t  len2 
)

Definition at line 340 of file crc32.cc.

References GF2_DIM, gf2_matrix_square(), gf2_matrix_times(), and n.

Referenced by crc32_combine(), and crc32_combine64().

341 {
342  int n;
343  unsigned long row;
344  unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
345  unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
346 
347  /* degenerate case (also disallow negative lengths) */
348  if (len2 <= 0)
349  return crc1;
350 
351  /* put operator for one zero bit in odd */
352  odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
353  row = 1;
354  for (n = 1; n < GF2_DIM; n++) {
355  odd[n] = row;
356  row <<= 1;
357  }
358 
359  /* put operator for two zero bits in even */
360  gf2_matrix_square(even, odd);
361 
362  /* put operator for four zero bits in odd */
363  gf2_matrix_square(odd, even);
364 
365  /* apply len2 zeros to crc1 (first square will put the operator for one
366  zero byte, eight zero bits, in even) */
367  do {
368  /* apply zeros operator for this bit of len2 */
369  gf2_matrix_square(even, odd);
370  if (len2 & 1)
371  crc1 = gf2_matrix_times(even, crc1);
372  len2 >>= 1;
373 
374  /* if no more bits set, then done */
375  if (len2 == 0)
376  break;
377 
378  /* another iteration of the loop with odd and even swapped */
379  gf2_matrix_square(odd, even);
380  if (len2 & 1)
381  crc1 = gf2_matrix_times(odd, crc1);
382  len2 >>= 1;
383 
384  /* if no more bits set, then done */
385  } while (len2 != 0);
386 
387  /* return combined crc */
388  crc1 ^= crc2;
389  return crc1;
390 }
#define GF2_DIM
Definition: crc32.cc:313
local void gf2_matrix_square(unsigned long *square, unsigned long *mat)
Definition: crc32.cc:331
const G4int n
local unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)
Definition: crc32.cc:316
const z_crc_t FAR* ZEXPORT get_crc_table ( )

Definition at line 188 of file crc32.cc.

References crc_table.

189 {
190 #ifdef DYNAMIC_CRC_TABLE
191  if (crc_table_empty)
192  make_crc_table();
193 #endif /* DYNAMIC_CRC_TABLE */
194  return (const z_crc_t FAR *)crc_table;
195 }
local const z_crc_t FAR crc_table[TBLS][256]
Definition: crc32.h:5
local void gf2_matrix_square ( unsigned long *  square,
unsigned long *  mat 
)

Definition at line 331 of file crc32.cc.

References GF2_DIM, gf2_matrix_times(), and n.

Referenced by crc32_combine_().

332 {
333  int n;
334 
335  for (n = 0; n < GF2_DIM; n++)
336  square[n] = gf2_matrix_times(mat, mat[n]);
337 }
#define GF2_DIM
Definition: crc32.cc:313
const G4int n
local unsigned long gf2_matrix_times(unsigned long *mat, unsigned long vec)
Definition: crc32.cc:316
local unsigned long gf2_matrix_times ( unsigned long *  mat,
unsigned long  vec 
)

Definition at line 316 of file crc32.cc.

Referenced by crc32_combine_(), and gf2_matrix_square().

317 {
318  unsigned long sum;
319 
320  sum = 0;
321  while (vec) {
322  if (vec & 1)
323  sum ^= *mat;
324  vec >>= 1;
325  mat++;
326  }
327  return sum;
328 }
local unsigned long gf2_matrix_times OF ( (unsigned long *mat, unsigned long vec)  )
local void gf2_matrix_square OF ( (unsigned long *square, unsigned long *mat)  )
local uLong crc32_combine_ OF ( (uLong crc1, uLong crc2, z_off64_t len2)  )