67
|
1 /* adler32.c -- compute the Adler-32 checksum of a data stream
|
|
2 * Copyright (C) 1995 Mark Adler
|
|
3 * For conditions of distribution and use, see copyright notice in zlib.h
|
|
4 */
|
|
5
|
|
6 #include "common.h"
|
|
7 #include "adler32.h"
|
|
8
|
|
9 #define BASE 65521L /* largest prime smaller than 65536 */
|
|
10
|
|
11 #define DO1(buf) {s1 += *buf++; s2 += s1;}
|
83
|
12 #define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf);
|
|
13 #define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);
|
67
|
14
|
|
15 unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len)
|
|
16 {
|
|
17 unsigned long s1 = adler & 0xffff;
|
85
|
18 unsigned long s2 = adler >> 16;
|
67
|
19
|
85
|
20 while (len>0) {
|
|
21 #ifdef CONFIG_SMALL
|
|
22 while(len>4 && s2 < (1U<<31)){
|
|
23 DO4(buf); len-=4;
|
|
24 #else
|
|
25 while(len>16 && s2 < (1U<<31)){
|
|
26 DO16(buf); len-=16;
|
|
27 #endif
|
67
|
28 }
|
85
|
29 DO1(buf); len--;
|
67
|
30 s1 %= BASE;
|
|
31 s2 %= BASE;
|
|
32 }
|
|
33 return (s2 << 16) | s1;
|
|
34 }
|
85
|
35
|
|
36 #ifdef TEST
|
|
37 #include "log.h"
|
|
38 #define LEN 7001
|
|
39 volatile int checksum;
|
|
40 int main(){
|
|
41 int i;
|
|
42 char data[LEN];
|
|
43 av_log_level = AV_LOG_DEBUG;
|
|
44 for(i=0; i<LEN; i++)
|
|
45 data[i]= ((i*i)>>3) + 123*i;
|
|
46 for(i=0; i<1000; i++){
|
|
47 START_TIMER
|
|
48 checksum= av_adler32_update(1, data, LEN);
|
|
49 STOP_TIMER("adler")
|
|
50 }
|
|
51 av_log(NULL, AV_LOG_DEBUG, "%X == 50E6E508\n", checksum);
|
|
52 }
|
|
53 #endif
|