annotate adler32.c @ 846:3942cf6cdad3 libavutil

ARM: change argument/return type of bswap_16() to unsigned 32-bit This avoids unnecessary masking otherwise added by the compilers.
author mru
date Mon, 22 Feb 2010 00:34:08 +0000
parents f23019f8fd69
children 4d9ad0ed07d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
636
c04808220c83 spelling/grammar/consistency review part II
diego
parents: 603
diff changeset
1 /*
c04808220c83 spelling/grammar/consistency review part II
diego
parents: 603
diff changeset
2 * 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
3 * 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
4 *
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
5 * Copyright (C) 1995 Mark Adler
105
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
6 *
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
7 * 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
8 * 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
9 * arising from the use of this software.
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
10 *
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
11 * 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
12 * 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
13 * freely, subject to the following restrictions:
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
14 *
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
15 * 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
16 * 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
17 * 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
18 * appreciated but is not required.
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
19 * 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
20 * misrepresented as being the original software.
f731186c3562 Add license from zlib.h instead of referring to it.
diego
parents: 85
diff changeset
21 * 3. This notice may not be removed or altered from any source distribution.
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) {
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 427
diff changeset
39 #if CONFIG_SMALL
85
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;
404
f9a4c04ebb0e main() --> main(void)
diego
parents: 358
diff changeset
58 int main(void){
85
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];
696
f23019f8fd69 Fix compilation of adler32 test program: Use av_log_set_level()
diego
parents: 636
diff changeset
61 av_log_set_level(AV_LOG_DEBUG);
85
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);
427
e7192ff1857d Fix a couple of 'return type defaults to int' and 'control reaches end of
diego
parents: 404
diff changeset
70 return 0;
85
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
71 }
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
72 #endif