Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adler32.cc File Reference
#include "zutil.h"
Include dependency graph for adler32.cc:

Go to the source code of this file.

Macros

#define local   static
 
#define BASE   65521 /* largest prime smaller than 65536 */
 
#define NMAX   5552
 
#define DO1(buf, i)   {adler += (buf)[i]; sum2 += adler;}
 
#define DO2(buf, i)   DO1(buf,i); DO1(buf,i+1);
 
#define DO4(buf, i)   DO2(buf,i); DO2(buf,i+2);
 
#define DO8(buf, i)   DO4(buf,i); DO4(buf,i+4);
 
#define DO16(buf)   DO8(buf,0); DO8(buf,8);
 
#define MOD(a)   a %= BASE
 
#define MOD28(a)   a %= BASE
 
#define MOD63(a)   a %= BASE
 

Functions

local uLong adler32_combine_ OF ((uLong adler1, uLong adler2, z_off64_t len2))
 
uLong ZEXPORT adler32 (uLong adler, const Bytef *buf, uInt len)
 
local uLong adler32_combine_ (uLong adler1, uLong adler2, z_off64_t len2)
 
uLong ZEXPORT adler32_combine (uLong adler1, uLong adler2, z_off_t len2)
 
uLong ZEXPORT adler32_combine64 (uLong adler1, uLong adler2, z_off64_t len2)
 

Macro Definition Documentation

#define BASE   65521 /* largest prime smaller than 65536 */

Definition at line 14 of file adler32.cc.

#define DO1 (   buf,
 
)    {adler += (buf)[i]; sum2 += adler;}

Definition at line 18 of file adler32.cc.

#define DO16 (   buf)    DO8(buf,0); DO8(buf,8);

Definition at line 22 of file adler32.cc.

#define DO2 (   buf,
 
)    DO1(buf,i); DO1(buf,i+1);

Definition at line 19 of file adler32.cc.

#define DO4 (   buf,
 
)    DO2(buf,i); DO2(buf,i+2);

Definition at line 20 of file adler32.cc.

#define DO8 (   buf,
 
)    DO4(buf,i); DO4(buf,i+4);

Definition at line 21 of file adler32.cc.

#define local   static

Definition at line 10 of file adler32.cc.

#define MOD (   a)    a %= BASE

Definition at line 59 of file adler32.cc.

#define MOD28 (   a)    a %= BASE

Definition at line 60 of file adler32.cc.

#define MOD63 (   a)    a %= BASE

Definition at line 61 of file adler32.cc.

#define NMAX   5552

Definition at line 15 of file adler32.cc.

Function Documentation

uLong ZEXPORT adler32 ( uLong  adler,
const Bytef *  buf,
uInt  len 
)

Definition at line 65 of file adler32.cc.

66 {
67  unsigned long sum2;
68  unsigned n;
69 
70  /* split Adler-32 into component sums */
71  sum2 = (adler >> 16) & 0xffff;
72  adler &= 0xffff;
73 
74  /* in case user likes doing a byte at a time, keep it fast */
75  if (len == 1) {
76  adler += buf[0];
77  if (adler >= BASE)
78  adler -= BASE;
79  sum2 += adler;
80  if (sum2 >= BASE)
81  sum2 -= BASE;
82  return adler | (sum2 << 16);
83  }
84 
85  /* initial Adler-32 value (deferred check for len == 1 speed) */
86  if (buf == Z_NULL)
87  return 1L;
88 
89  /* in case short lengths are provided, keep it somewhat fast */
90  if (len < 16) {
91  while (len--) {
92  adler += *buf++;
93  sum2 += adler;
94  }
95  if (adler >= BASE)
96  adler -= BASE;
97  MOD28(sum2); /* only added so many BASE's */
98  return adler | (sum2 << 16);
99  }
100 
101  /* do length NMAX blocks -- requires just one modulo operation */
102  while (len >= NMAX) {
103  len -= NMAX;
104  n = NMAX / 16; /* NMAX is divisible by 16 */
105  do {
106  DO16(buf); /* 16 sums unrolled */
107  buf += 16;
108  } while (--n);
109  MOD(adler);
110  MOD(sum2);
111  }
112 
113  /* do remaining bytes (less than NMAX, still just one modulo) */
114  if (len) { /* avoid modulos if none remaining */
115  while (len >= 16) {
116  len -= 16;
117  DO16(buf);
118  buf += 16;
119  }
120  while (len--) {
121  adler += *buf++;
122  sum2 += adler;
123  }
124  MOD(adler);
125  MOD(sum2);
126  }
127 
128  /* return recombined sums */
129  return adler | (sum2 << 16);
130 }
const XML_Char int len
Definition: expat.h:262
#define MOD(a)
Definition: adler32.cc:59
#define DO16(buf)
Definition: adler32.cc:22
#define NMAX
Definition: adler32.cc:15
const G4int n
#define BASE
Definition: adler32.cc:14
#define MOD28(a)
Definition: adler32.cc:60
#define Z_NULL
Definition: zlib.h:208
static constexpr double L
Definition: G4SIunits.hh:124

Here is the caller graph for this function:

uLong ZEXPORT adler32_combine ( uLong  adler1,
uLong  adler2,
z_off_t  len2 
)

Definition at line 159 of file adler32.cc.

160 {
161  return adler32_combine_(adler1, adler2, len2);
162 }
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2)
Definition: adler32.cc:133

Here is the call graph for this function:

uLong ZEXPORT adler32_combine64 ( uLong  adler1,
uLong  adler2,
z_off64_t  len2 
)

Definition at line 164 of file adler32.cc.

165 {
166  return adler32_combine_(adler1, adler2, len2);
167 }
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2)
Definition: adler32.cc:133

Here is the call graph for this function:

local uLong adler32_combine_ ( uLong  adler1,
uLong  adler2,
z_off64_t  len2 
)

Definition at line 133 of file adler32.cc.

134 {
135  unsigned long sum1;
136  unsigned long sum2;
137  unsigned rem;
138 
139  /* for negative len, return invalid adler32 as a clue for debugging */
140  if (len2 < 0)
141  return 0xffffffffUL;
142 
143  /* the derivation of this formula is left as an exercise for the reader */
144  MOD63(len2); /* assumes len2 >= 0 */
145  rem = (unsigned)len2;
146  sum1 = adler1 & 0xffff;
147  sum2 = rem * sum1;
148  MOD(sum2);
149  sum1 += (adler2 & 0xffff) + BASE - 1;
150  sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
151  if (sum1 >= BASE) sum1 -= BASE;
152  if (sum1 >= BASE) sum1 -= BASE;
153  if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
154  if (sum2 >= BASE) sum2 -= BASE;
155  return sum1 | (sum2 << 16);
156 }
#define MOD(a)
Definition: adler32.cc:59
#define MOD63(a)
Definition: adler32.cc:61
#define BASE
Definition: adler32.cc:14

Here is the caller graph for this function:

local uLong adler32_combine_ OF ( (uLong adler1, uLong adler2, z_off64_t len2)  )