blob: 35981bc15a7c4c24878e25775f06ff695257f09e [file] [log] [blame]
Igor Sysoevd90282d2004-09-28 08:34:51 +00001
2/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Maxim Konovalovf8d59e32012-01-18 15:07:43 +00004 * Copyright (C) Nginx, Inc.
Igor Sysoevd90282d2004-09-28 08:34:51 +00005 */
6
7
Igor Sysoev865c1502003-11-30 20:03:18 +00008#ifndef _NGX_CRC_H_INCLUDED_
9#define _NGX_CRC_H_INCLUDED_
10
11
Igor Sysoeva8503de2006-10-19 08:16:29 +000012#include <ngx_config.h>
13#include <ngx_core.h>
14
15
Igor Sysoev865c1502003-11-30 20:03:18 +000016/* 32-bit crc16 */
17
Igor Sysoev0ab9e432006-10-13 15:09:25 +000018static ngx_inline uint32_t
Igor Sysoev289e3ca2006-10-18 18:43:11 +000019ngx_crc(u_char *data, size_t len)
Igor Sysoev865c1502003-11-30 20:03:18 +000020{
21 uint32_t sum;
Igor Sysoev5f800782003-12-08 20:48:12 +000022
Igor Sysoev865c1502003-11-30 20:03:18 +000023 for (sum = 0; len; len--) {
Igor Sysoevd90282d2004-09-28 08:34:51 +000024
Igor Sysoev865c1502003-11-30 20:03:18 +000025 /*
Igor Sysoev0ab9e432006-10-13 15:09:25 +000026 * gcc 2.95.2 x86 and icc 7.1.006 compile
27 * that operator into the single "rol" opcode,
Igor Sysoev865c1502003-11-30 20:03:18 +000028 * msvc 6.0sp2 compiles it into four opcodes.
29 */
30 sum = sum >> 1 | sum << 31;
31
32 sum += *data++;
33 }
34
35 return sum;
36}
37
38
39#endif /* _NGX_CRC_H_INCLUDED_ */