Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
adler32.c File Reference
#include "zutil.h"

Go to the source code of this file.

Macros

#define BASE   65521U /* 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

uLong adler32_combine_ OF ((uLong adler1, uLong adler2, z_off64_t len2))
 
uLong ZEXPORT adler32_z (uLong adler, const Bytef *buf, z_size_t len)
 
uLong ZEXPORT adler32 (uLong adler, const Bytef *buf, uInt len)
 
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

◆ BASE

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

Definition at line 11 of file adler32.c.

◆ DO1

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

Definition at line 15 of file adler32.c.

◆ DO16

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

Definition at line 19 of file adler32.c.

◆ DO2

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

Definition at line 16 of file adler32.c.

◆ DO4

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

Definition at line 17 of file adler32.c.

◆ DO8

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

Definition at line 18 of file adler32.c.

◆ MOD

#define MOD (   a)    a %= BASE

Definition at line 56 of file adler32.c.

◆ MOD28

#define MOD28 (   a)    a %= BASE

Definition at line 57 of file adler32.c.

◆ MOD63

#define MOD63 (   a)    a %= BASE

Definition at line 58 of file adler32.c.

◆ NMAX

#define NMAX   5552

Definition at line 12 of file adler32.c.

Function Documentation

◆ adler32()

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

Definition at line 133 of file adler32.c.

137{
138 return adler32_z(adler, buf, len);
139}
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len)
Definition: adler32.c:62

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

◆ adler32_combine()

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

Definition at line 171 of file adler32.c.

175{
176 return adler32_combine_(adler1, adler2, len2);
177}
uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2)
Definition: adler32.c:142

◆ adler32_combine64()

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

Definition at line 179 of file adler32.c.

183{
184 return adler32_combine_(adler1, adler2, len2);
185}

◆ adler32_combine_()

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

Definition at line 142 of file adler32.c.

146{
147 unsigned long sum1;
148 unsigned long sum2;
149 unsigned rem;
150
151 /* for negative len, return invalid adler32 as a clue for debugging */
152 if (len2 < 0)
153 return 0xffffffffUL;
154
155 /* the derivation of this formula is left as an exercise for the reader */
156 MOD63(len2); /* assumes len2 >= 0 */
157 rem = (unsigned)len2;
158 sum1 = adler1 & 0xffff;
159 sum2 = rem * sum1;
160 MOD(sum2);
161 sum1 += (adler2 & 0xffff) + BASE - 1;
162 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
163 if (sum1 >= BASE) sum1 -= BASE;
164 if (sum1 >= BASE) sum1 -= BASE;
165 if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
166 if (sum2 >= BASE) sum2 -= BASE;
167 return sum1 | (sum2 << 16);
168}
#define BASE
Definition: adler32.c:11
#define MOD63(a)
Definition: adler32.c:58
#define MOD(a)
Definition: adler32.c:56

Referenced by adler32_combine(), and adler32_combine64().

◆ adler32_z()

uLong ZEXPORT adler32_z ( uLong  adler,
const Bytef *  buf,
z_size_t  len 
)

Definition at line 62 of file adler32.c.

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}
#define MOD28(a)
Definition: adler32.c:57
#define NMAX
Definition: adler32.c:12
#define DO16(buf)
Definition: adler32.c:19
#define Z_NULL
Definition: zlib.h:212

Referenced by adler32().

◆ OF()

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