annotate src/core/ngx_crc32.h @ 9230:e14debe728b0 radix_with_skip

Closed the radix_with_skip branch. The radix_with_skip branch is an archive of an experiment did in 2008, and it is no longer relevant. It is now closed to avoid cluttering of the branches list. If needed, closed branches still can be seen with "hg branches --closed".
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 23 Mar 2024 04:30:45 +0300
parents d6afb8723155
children d620f497c50f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
790
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4 */
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #ifndef _NGX_CRC32_H_INCLUDED_
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #define _NGX_CRC32_H_INCLUDED_
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11 #include <ngx_config.h>
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12 #include <ngx_core.h>
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
793
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
15 extern uint32_t *ngx_crc32_table_short;
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
16 extern uint32_t ngx_crc32_table256[];
790
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 static ngx_inline uint32_t
793
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
20 ngx_crc32_short(u_char *p, size_t len)
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
21 {
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
22 u_char c;
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
23 uint32_t crc;
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
24
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
25 crc = 0xffffffff;
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
26
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
27 while (len--) {
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
28 c = *p++;
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
29 crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >> 4);
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
30 crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc >> 4);
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
31 }
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
32
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
33 return crc ^ 0xffffffff;
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
34 }
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
35
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
36
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
37 static ngx_inline uint32_t
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
38 ngx_crc32_long(u_char *p, size_t len)
790
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 {
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 uint32_t crc;
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 crc = 0xffffffff;
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 while (len--) {
793
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
45 crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8);
790
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 }
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 return crc ^ 0xffffffff;
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 }
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51
1694
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
52 #define ngx_crc32_init(crc) \
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
53 crc = 0xffffffff
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
54
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
55
1697
d6afb8723155 fix r1695
Igor Sysoev <igor@sysoev.ru>
parents: 1694
diff changeset
56 static ngx_inline void
1694
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
57 ngx_crc32_update(uint32_t *crc, u_char *p, size_t len)
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
58 {
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
59 uint32_t c;
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
60
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
61 c = *crc;
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
62
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
63 while (len--) {
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
64 c = ngx_crc32_table256[(c ^ *p++) & 0xff] ^ (c >> 8);
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
65 }
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
66
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
67 *crc = c;
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
68 }
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
69
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
70
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
71 #define ngx_crc32_final(crc) \
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
72 crc ^= 0xffffffff
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
73
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
74
8c696afe46b3 rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents: 930
diff changeset
75 ngx_int_t ngx_crc32_table_init(void);
793
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
76
8d39da951bbd split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents: 790
diff changeset
77
790
f9a971440614 ngx_crc32()
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 #endif /* _NGX_CRC32_H_INCLUDED_ */