aboutsummaryrefslogtreecommitdiff
path: root/adler32.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:23:14 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:23:14 -0700
commita2506218cd8c32416d0d15260834f3c23d910fc8 (patch)
tree25bbd63d92473c8ae02a27cce3fc7c04a6aba64a /adler32.c
parentb97ec631c6f7dd9cff2e3caf3b38e70b006e1b2d (diff)
downloadzlib-a2506218cd8c32416d0d15260834f3c23d910fc8.tar.gz
zlib-a2506218cd8c32416d0d15260834f3c23d910fc8.tar.bz2
zlib-a2506218cd8c32416d0d15260834f3c23d910fc8.zip
zlib 1.2.0.8v1.2.0.8
Diffstat (limited to 'adler32.c')
-rw-r--r--adler32.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/adler32.c b/adler32.c
index 4d52399..bad930e 100644
--- a/adler32.c
+++ b/adler32.c
@@ -8,7 +8,7 @@
8#define ZLIB_INTERNAL 8#define ZLIB_INTERNAL
9#include "zlib.h" 9#include "zlib.h"
10 10
11#define BASE 65521L /* largest prime smaller than 65536 */ 11#define BASE 65521UL /* largest prime smaller than 65536 */
12#define NMAX 5552 12#define NMAX 5552
13/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 13/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
14 14
@@ -18,6 +18,31 @@
18#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 18#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
19#define DO16(buf) DO8(buf,0); DO8(buf,8); 19#define DO16(buf) DO8(buf,0); DO8(buf,8);
20 20
21#ifdef NO_DIVIDE
22# define MOD(a) \
23 do { \
24 if (a > (BASE << 16)) a -= (BASE << 16); \
25 if (a > (BASE << 15)) a -= (BASE << 15); \
26 if (a > (BASE << 14)) a -= (BASE << 14); \
27 if (a > (BASE << 13)) a -= (BASE << 13); \
28 if (a > (BASE << 12)) a -= (BASE << 12); \
29 if (a > (BASE << 11)) a -= (BASE << 11); \
30 if (a > (BASE << 10)) a -= (BASE << 10); \
31 if (a > (BASE << 9)) a -= (BASE << 9); \
32 if (a > (BASE << 8)) a -= (BASE << 8); \
33 if (a > (BASE << 7)) a -= (BASE << 7); \
34 if (a > (BASE << 6)) a -= (BASE << 6); \
35 if (a > (BASE << 5)) a -= (BASE << 5); \
36 if (a > (BASE << 4)) a -= (BASE << 4); \
37 if (a > (BASE << 3)) a -= (BASE << 3); \
38 if (a > (BASE << 2)) a -= (BASE << 2); \
39 if (a > (BASE << 1)) a -= (BASE << 1); \
40 if (a > BASE) a -= BASE; \
41 } while (0)
42#else
43# define MOD(a) a %= BASE
44#endif
45
21/* ========================================================================= */ 46/* ========================================================================= */
22uLong ZEXPORT adler32(adler, buf, len) 47uLong ZEXPORT adler32(adler, buf, len)
23 uLong adler; 48 uLong adler;
@@ -42,8 +67,8 @@ uLong ZEXPORT adler32(adler, buf, len)
42 s1 += *buf++; 67 s1 += *buf++;
43 s2 += s1; 68 s2 += s1;
44 } while (--k); 69 } while (--k);
45 s1 %= BASE; 70 MOD(s1);
46 s2 %= BASE; 71 MOD(s2);
47 } 72 }
48 return (s2 << 16) | s1; 73 return (s2 << 16) | s1;
49} 74}