src/core/ngx_crc.h - nginx-1.7.10

Functions defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_CRC_H_INCLUDED_
  6. #define _NGX_CRC_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>


  9. /* 32-bit crc16 */

  10. static ngx_inline uint32_t
  11. ngx_crc(u_char *data, size_t len)
  12. {
  13.     uint32_t  sum;

  14.     for (sum = 0; len; len--) {

  15.         /*
  16.          * gcc 2.95.2 x86 and icc 7.1.006 compile
  17.          * that operator into the single "rol" opcode,
  18.          * msvc 6.0sp2 compiles it into four opcodes.
  19.          */
  20.         sum = sum >> 1 | sum << 31;

  21.         sum += *data++;
  22.     }

  23.     return sum;
  24. }


  25. #endif /* _NGX_CRC_H_INCLUDED_ */