You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3KB

  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. #include "common.h"
  6. #include "adler32.h"
  7. #define BASE 65521L /* largest prime smaller than 65536 */
  8. #define DO1(buf) {s1 += *buf++; s2 += s1;}
  9. #define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf);
  10. #define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);
  11. unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len)
  12. {
  13. unsigned long s1 = adler & 0xffff;
  14. unsigned long s2 = adler >> 16;
  15. while (len>0) {
  16. #ifdef CONFIG_SMALL
  17. while(len>4 && s2 < (1U<<31)){
  18. DO4(buf); len-=4;
  19. #else
  20. while(len>16 && s2 < (1U<<31)){
  21. DO16(buf); len-=16;
  22. #endif
  23. }
  24. DO1(buf); len--;
  25. s1 %= BASE;
  26. s2 %= BASE;
  27. }
  28. return (s2 << 16) | s1;
  29. }
  30. #ifdef TEST
  31. #include "log.h"
  32. #define LEN 7001
  33. volatile int checksum;
  34. int main(){
  35. int i;
  36. char data[LEN];
  37. av_log_level = AV_LOG_DEBUG;
  38. for(i=0; i<LEN; i++)
  39. data[i]= ((i*i)>>3) + 123*i;
  40. for(i=0; i<1000; i++){
  41. START_TIMER
  42. checksum= av_adler32_update(1, data, LEN);
  43. STOP_TIMER("adler")
  44. }
  45. av_log(NULL, AV_LOG_DEBUG, "%X == 50E6E508\n", checksum);
  46. }
  47. #endif