diff options
Diffstat (limited to 'adler32.c')
-rw-r--r-- | adler32.c | 31 |
1 files changed, 28 insertions, 3 deletions
@@ -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 | /* ========================================================================= */ |
22 | uLong ZEXPORT adler32(adler, buf, len) | 47 | uLong 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 | } |