annotate adler32.c @ 294:97f5321b12ad libavutil

make count count bytes not bits (this is simpler and leads to a very slightly smaller object file)
author michael
date Mon, 12 Mar 2007 21:29:39 +0000
parents f731186c3562
children f13e5473611e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
1 /* adler32.c -- compute the Adler-32 checksum of a data stream
105
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
2 * This is a modified version based on adler32.c from the zlib library.
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
3 *
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
4 * Copyright (C) 1995 Mark Adler
105
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
5 *
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
6 * This software is provided 'as-is', without any express or implied
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
7 * warranty. In no event will the authors be held liable for any damages
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
8 * arising from the use of this software.
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
9 *
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
10 * Permission is granted to anyone to use this software for any purpose,
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
11 * including commercial applications, and to alter it and redistribute it
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
12 * freely, subject to the following restrictions:
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
13 *
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
14 * 1. The origin of this software must not be misrepresented; you must not
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
15 * claim that you wrote the original software. If you use this software
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
16 * in a product, an acknowledgment in the product documentation would be
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
17 * appreciated but is not required.
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
18 * 2. Altered source versions must be plainly marked as such, and must not be
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
19 * misrepresented as being the original software.
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
20 * 3. This notice may not be removed or altered from any source distribution.
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
21 *
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
22 */
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
23
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
24 #include "common.h"
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
25 #include "adler32.h"
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
26
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
27 #define BASE 65521L /* largest prime smaller than 65536 */
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
28
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
29 #define DO1(buf) {s1 += *buf++; s2 += s1;}
83
4d16d6abcf65 simplify
michael
parents: 68
diff changeset
30 #define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf);
4d16d6abcf65 simplify
michael
parents: 68
diff changeset
31 #define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
32
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
33 unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len)
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
34 {
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
35 unsigned long s1 = adler & 0xffff;
85
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
36 unsigned long s2 = adler >> 16;
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
37
85
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
38 while (len>0) {
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
39 #ifdef CONFIG_SMALL
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
40 while(len>4 && s2 < (1U<<31)){
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
41 DO4(buf); len-=4;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
42 #else
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
43 while(len>16 && s2 < (1U<<31)){
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
44 DO16(buf); len-=16;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
45 #endif
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
46 }
85
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
47 DO1(buf); len--;
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
48 s1 %= BASE;
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
49 s2 %= BASE;
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
50 }
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
51 return (s2 << 16) | s1;
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
52 }
85
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
53
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
54 #ifdef TEST
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
55 #include "log.h"
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
56 #define LEN 7001
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
57 volatile int checksum;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
58 int main(){
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
59 int i;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
60 char data[LEN];
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
61 av_log_level = AV_LOG_DEBUG;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
62 for(i=0; i<LEN; i++)
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
63 data[i]= ((i*i)>>3) + 123*i;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
64 for(i=0; i<1000; i++){
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
65 START_TIMER
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
66 checksum= av_adler32_update(1, data, LEN);
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
67 STOP_TIMER("adler")
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
68 }
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
69 av_log(NULL, AV_LOG_DEBUG, "%X == 50E6E508\n", checksum);
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
70 }
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
71 #endif