Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: third_party/zlib/adler32.c

Issue 2690623003: Update zlib to 1.2.11 (Closed)
Patch Set: Drop the inflater change, improve the deflater comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/zlib/README.chromium ('k') | third_party/zlib/compress.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* adler32.c -- compute the Adler-32 checksum of a data stream 1 /* adler32.c -- compute the Adler-32 checksum of a data stream
2 * Copyright (C) 1995-2011 Mark Adler 2 * Copyright (C) 1995-2011, 2016 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6 /* @(#) $Id$ */ 6 /* @(#) $Id$ */
7 7
8 #include "zutil.h" 8 #include "zutil.h"
9 9
10 #define local static
11
12 local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); 10 local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
13 11
14 #define BASE 65521 /* largest prime smaller than 65536 */ 12 #define BASE 65521U /* largest prime smaller than 65536 */
15 #define NMAX 5552 13 #define NMAX 5552
16 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 14 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
17 15
18 #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 16 #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
19 #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 17 #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
20 #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 18 #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
21 #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 19 #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
22 #define DO16(buf) DO8(buf,0); DO8(buf,8); 20 #define DO16(buf) DO8(buf,0); DO8(buf,8);
23 21
24 /* use NO_DIVIDE if your processor does not do division in hardware -- 22 /* use NO_DIVIDE if your processor does not do division in hardware --
(...skipping 30 matching lines...) Expand all
55 a += (tmp << 4) - tmp; \ 53 a += (tmp << 4) - tmp; \
56 if (a >= BASE) a -= BASE; \ 54 if (a >= BASE) a -= BASE; \
57 } while (0) 55 } while (0)
58 #else 56 #else
59 # define MOD(a) a %= BASE 57 # define MOD(a) a %= BASE
60 # define MOD28(a) a %= BASE 58 # define MOD28(a) a %= BASE
61 # define MOD63(a) a %= BASE 59 # define MOD63(a) a %= BASE
62 #endif 60 #endif
63 61
64 /* ========================================================================= */ 62 /* ========================================================================= */
65 uLong ZEXPORT adler32(adler, buf, len) 63 uLong ZEXPORT adler32_z(adler, buf, len)
66 uLong adler; 64 uLong adler;
67 const Bytef *buf; 65 const Bytef *buf;
68 uInt len; 66 z_size_t len;
69 { 67 {
70 unsigned long sum2; 68 unsigned long sum2;
71 unsigned n; 69 unsigned n;
72 70
73 /* split Adler-32 into component sums */ 71 /* split Adler-32 into component sums */
74 sum2 = (adler >> 16) & 0xffff; 72 sum2 = (adler >> 16) & 0xffff;
75 adler &= 0xffff; 73 adler &= 0xffff;
76 74
77 /* in case user likes doing a byte at a time, keep it fast */ 75 /* in case user likes doing a byte at a time, keep it fast */
78 if (len == 1) { 76 if (len == 1) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 124 }
127 MOD(adler); 125 MOD(adler);
128 MOD(sum2); 126 MOD(sum2);
129 } 127 }
130 128
131 /* return recombined sums */ 129 /* return recombined sums */
132 return adler | (sum2 << 16); 130 return adler | (sum2 << 16);
133 } 131 }
134 132
135 /* ========================================================================= */ 133 /* ========================================================================= */
134 uLong ZEXPORT adler32(adler, buf, len)
135 uLong adler;
136 const Bytef *buf;
137 uInt len;
138 {
139 return adler32_z(adler, buf, len);
140 }
141
142 /* ========================================================================= */
136 local uLong adler32_combine_(adler1, adler2, len2) 143 local uLong adler32_combine_(adler1, adler2, len2)
137 uLong adler1; 144 uLong adler1;
138 uLong adler2; 145 uLong adler2;
139 z_off64_t len2; 146 z_off64_t len2;
140 { 147 {
141 unsigned long sum1; 148 unsigned long sum1;
142 unsigned long sum2; 149 unsigned long sum2;
143 unsigned rem; 150 unsigned rem;
144 151
145 /* for negative len, return invalid adler32 as a clue for debugging */ 152 /* for negative len, return invalid adler32 as a clue for debugging */
146 if (len2 < 0) 153 if (len2 < 0)
147 return 0xffffffffUL; 154 return 0xffffffffUL;
148 155
149 /* the derivation of this formula is left as an exercise for the reader */ 156 /* the derivation of this formula is left as an exercise for the reader */
150 MOD63(len2); /* assumes len2 >= 0 */ 157 MOD63(len2); /* assumes len2 >= 0 */
151 rem = (unsigned)len2; 158 rem = (unsigned)len2;
152 sum1 = adler1 & 0xffff; 159 sum1 = adler1 & 0xffff;
153 sum2 = rem * sum1; 160 sum2 = rem * sum1;
154 MOD(sum2); 161 MOD(sum2);
155 sum1 += (adler2 & 0xffff) + BASE - 1; 162 sum1 += (adler2 & 0xffff) + BASE - 1;
156 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 163 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
157 if (sum1 >= BASE) sum1 -= BASE; 164 if (sum1 >= BASE) sum1 -= BASE;
158 if (sum1 >= BASE) sum1 -= BASE; 165 if (sum1 >= BASE) sum1 -= BASE;
159 if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); 166 if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
160 if (sum2 >= BASE) sum2 -= BASE; 167 if (sum2 >= BASE) sum2 -= BASE;
161 return sum1 | (sum2 << 16); 168 return sum1 | (sum2 << 16);
162 } 169 }
163 170
164 /* ========================================================================= */ 171 /* ========================================================================= */
165 uLong ZEXPORT adler32_combine(adler1, adler2, len2) 172 uLong ZEXPORT adler32_combine(adler1, adler2, len2)
166 uLong adler1; 173 uLong adler1;
167 uLong adler2; 174 uLong adler2;
168 z_off_t len2; 175 z_off_t len2;
169 { 176 {
170 return adler32_combine_(adler1, adler2, len2); 177 return adler32_combine_(adler1, adler2, len2);
171 } 178 }
172 179
173 uLong ZEXPORT adler32_combine64(adler1, adler2, len2) 180 uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
174 uLong adler1; 181 uLong adler1;
175 uLong adler2; 182 uLong adler2;
176 z_off64_t len2; 183 z_off64_t len2;
177 { 184 {
178 return adler32_combine_(adler1, adler2, len2); 185 return adler32_combine_(adler1, adler2, len2);
179 } 186 }
OLDNEW
« no previous file with comments | « third_party/zlib/README.chromium ('k') | third_party/zlib/compress.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698