iodine 0.4.19 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of iodine might be problematic. Click here for more details.

Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -2
  3. data/CHANGELOG.md +22 -0
  4. data/LIMITS.md +19 -9
  5. data/README.md +92 -77
  6. data/SPEC-PubSub-Draft.md +113 -0
  7. data/SPEC-Websocket-Draft.md +127 -143
  8. data/bin/http-hello +0 -1
  9. data/bin/raw-rbhttp +1 -1
  10. data/bin/raw_broadcast +8 -10
  11. data/bin/updated api +2 -2
  12. data/bin/ws-broadcast +2 -4
  13. data/bin/ws-echo +2 -2
  14. data/examples/config.ru +13 -13
  15. data/examples/echo.ru +5 -6
  16. data/examples/hello.ru +2 -3
  17. data/examples/info.md +316 -0
  18. data/examples/pubsub_engine.ru +81 -0
  19. data/examples/redis.ru +9 -9
  20. data/examples/shootout.ru +45 -11
  21. data/ext/iodine/defer.c +194 -297
  22. data/ext/iodine/defer.h +61 -53
  23. data/ext/iodine/evio.c +0 -260
  24. data/ext/iodine/evio.h +50 -22
  25. data/ext/iodine/evio_callbacks.c +26 -0
  26. data/ext/iodine/evio_epoll.c +251 -0
  27. data/ext/iodine/evio_kqueue.c +193 -0
  28. data/ext/iodine/extconf.rb +1 -1
  29. data/ext/iodine/facil.c +1420 -542
  30. data/ext/iodine/facil.h +151 -64
  31. data/ext/iodine/fio_ary.h +418 -0
  32. data/ext/iodine/{base64.c → fio_base64.c} +33 -24
  33. data/ext/iodine/{base64.h → fio_base64.h} +6 -7
  34. data/ext/iodine/{fio_cli_helper.c → fio_cli.c} +77 -58
  35. data/ext/iodine/{fio_cli_helper.h → fio_cli.h} +9 -4
  36. data/ext/iodine/fio_hashmap.h +759 -0
  37. data/ext/iodine/fio_json_parser.h +651 -0
  38. data/ext/iodine/fio_llist.h +257 -0
  39. data/ext/iodine/fio_mem.c +672 -0
  40. data/ext/iodine/fio_mem.h +140 -0
  41. data/ext/iodine/fio_random.c +248 -0
  42. data/ext/iodine/{random.h → fio_random.h} +11 -14
  43. data/ext/iodine/{sha1.c → fio_sha1.c} +28 -24
  44. data/ext/iodine/{sha1.h → fio_sha1.h} +38 -16
  45. data/ext/iodine/{sha2.c → fio_sha2.c} +66 -49
  46. data/ext/iodine/{sha2.h → fio_sha2.h} +57 -26
  47. data/ext/iodine/{fiobj_internal.c → fio_siphash.c} +9 -90
  48. data/ext/iodine/fio_siphash.h +18 -0
  49. data/ext/iodine/fio_tmpfile.h +38 -0
  50. data/ext/iodine/fiobj.h +24 -7
  51. data/ext/iodine/fiobj4sock.h +23 -0
  52. data/ext/iodine/fiobj_ary.c +143 -226
  53. data/ext/iodine/fiobj_ary.h +17 -16
  54. data/ext/iodine/fiobj_data.c +1160 -0
  55. data/ext/iodine/fiobj_data.h +164 -0
  56. data/ext/iodine/fiobj_hash.c +298 -406
  57. data/ext/iodine/fiobj_hash.h +101 -54
  58. data/ext/iodine/fiobj_json.c +478 -601
  59. data/ext/iodine/fiobj_json.h +34 -9
  60. data/ext/iodine/fiobj_numbers.c +383 -51
  61. data/ext/iodine/fiobj_numbers.h +87 -11
  62. data/ext/iodine/fiobj_str.c +423 -184
  63. data/ext/iodine/fiobj_str.h +81 -32
  64. data/ext/iodine/fiobject.c +273 -522
  65. data/ext/iodine/fiobject.h +477 -112
  66. data/ext/iodine/http.c +2243 -83
  67. data/ext/iodine/http.h +842 -121
  68. data/ext/iodine/http1.c +810 -385
  69. data/ext/iodine/http1.h +16 -39
  70. data/ext/iodine/http1_parser.c +146 -74
  71. data/ext/iodine/http1_parser.h +15 -4
  72. data/ext/iodine/http_internal.c +1258 -0
  73. data/ext/iodine/http_internal.h +226 -0
  74. data/ext/iodine/http_mime_parser.h +341 -0
  75. data/ext/iodine/iodine.c +86 -68
  76. data/ext/iodine/iodine.h +26 -11
  77. data/ext/iodine/iodine_helpers.c +8 -7
  78. data/ext/iodine/iodine_http.c +487 -324
  79. data/ext/iodine/iodine_json.c +304 -0
  80. data/ext/iodine/iodine_json.h +6 -0
  81. data/ext/iodine/iodine_protocol.c +107 -45
  82. data/ext/iodine/iodine_pubsub.c +526 -225
  83. data/ext/iodine/iodine_pubsub.h +10 -0
  84. data/ext/iodine/iodine_websockets.c +268 -510
  85. data/ext/iodine/iodine_websockets.h +2 -4
  86. data/ext/iodine/pubsub.c +726 -432
  87. data/ext/iodine/pubsub.h +85 -103
  88. data/ext/iodine/rb-call.c +4 -4
  89. data/ext/iodine/rb-defer.c +46 -22
  90. data/ext/iodine/rb-fiobj2rb.h +117 -0
  91. data/ext/iodine/rb-rack-io.c +73 -238
  92. data/ext/iodine/rb-rack-io.h +2 -2
  93. data/ext/iodine/rb-registry.c +35 -93
  94. data/ext/iodine/rb-registry.h +1 -0
  95. data/ext/iodine/redis_engine.c +742 -304
  96. data/ext/iodine/redis_engine.h +42 -39
  97. data/ext/iodine/resp_parser.h +311 -0
  98. data/ext/iodine/sock.c +627 -490
  99. data/ext/iodine/sock.h +345 -297
  100. data/ext/iodine/spnlock.inc +15 -4
  101. data/ext/iodine/websocket_parser.h +16 -20
  102. data/ext/iodine/websockets.c +188 -257
  103. data/ext/iodine/websockets.h +24 -133
  104. data/lib/iodine.rb +52 -7
  105. data/lib/iodine/cli.rb +6 -24
  106. data/lib/iodine/json.rb +40 -0
  107. data/lib/iodine/version.rb +1 -1
  108. data/lib/iodine/websocket.rb +5 -3
  109. data/lib/rack/handler/iodine.rb +58 -13
  110. metadata +38 -48
  111. data/bin/ws-shootout +0 -107
  112. data/examples/broadcast.ru +0 -56
  113. data/ext/iodine/bscrypt-common.h +0 -116
  114. data/ext/iodine/bscrypt.h +0 -49
  115. data/ext/iodine/fio2resp.c +0 -60
  116. data/ext/iodine/fio2resp.h +0 -51
  117. data/ext/iodine/fio_dict.c +0 -446
  118. data/ext/iodine/fio_dict.h +0 -99
  119. data/ext/iodine/fio_hash_table.h +0 -370
  120. data/ext/iodine/fio_list.h +0 -111
  121. data/ext/iodine/fiobj_internal.h +0 -280
  122. data/ext/iodine/fiobj_primitives.c +0 -131
  123. data/ext/iodine/fiobj_primitives.h +0 -55
  124. data/ext/iodine/fiobj_sym.c +0 -135
  125. data/ext/iodine/fiobj_sym.h +0 -60
  126. data/ext/iodine/hex.c +0 -124
  127. data/ext/iodine/hex.h +0 -70
  128. data/ext/iodine/http1_request.c +0 -81
  129. data/ext/iodine/http1_request.h +0 -58
  130. data/ext/iodine/http1_response.c +0 -417
  131. data/ext/iodine/http1_response.h +0 -95
  132. data/ext/iodine/http_request.c +0 -111
  133. data/ext/iodine/http_request.h +0 -102
  134. data/ext/iodine/http_response.c +0 -1703
  135. data/ext/iodine/http_response.h +0 -250
  136. data/ext/iodine/misc.c +0 -182
  137. data/ext/iodine/misc.h +0 -74
  138. data/ext/iodine/random.c +0 -208
  139. data/ext/iodine/redis_connection.c +0 -278
  140. data/ext/iodine/redis_connection.h +0 -86
  141. data/ext/iodine/resp.c +0 -842
  142. data/ext/iodine/resp.h +0 -261
  143. data/ext/iodine/siphash.c +0 -154
  144. data/ext/iodine/siphash.h +0 -22
  145. data/ext/iodine/xor-crypt.c +0 -193
  146. data/ext/iodine/xor-crypt.h +0 -107
@@ -1,99 +0,0 @@
1
- /*
2
- Copyright: Boaz segev, 2016-2017
3
- License: MIT
4
-
5
- Feel free to copy, use and enjoy according to the license provided.
6
- */
7
- #ifndef H_FIO_DICT_H
8
- /**
9
- `fio_dict_s` Is based on a 4-bit trie structure, allowing for fast no-collisions
10
- key-value matching while avoiding any hashing.
11
-
12
- It's memory intensive... very memory intensive... but it has 0 collision risk
13
- and offers fairly high performance.
14
-
15
- Just to offer some insight, a single key-value pair for the key "hello" will
16
- require ~1,360 bytes. Add the key "bye!" ad you'll add ~1,088 bytes more... but
17
- the key "hello1" will cost only 272 bytes... brrr.
18
- */
19
- #define H_FIO_DICT_H
20
-
21
- #include <stdint.h>
22
- #include <stdlib.h>
23
-
24
- /* support C++ */
25
- #ifdef __cplusplus
26
- extern "C" {
27
- #endif
28
-
29
- typedef struct fio_dict_s {
30
- struct fio_dict_s *parent;
31
- struct fio_dict_s *trie[16];
32
- unsigned used : 1;
33
- unsigned trie_val : 4;
34
- } fio_dict_s;
35
-
36
- #define FIO_DICT_INIT \
37
- (fio_dict_s) { .parent = NULL }
38
- #define FIO_DICT_INIT_STATIC \
39
- { .parent = NULL }
40
-
41
- #ifndef fio_node2obj
42
- #define fio_node2obj(type, member, ptr) \
43
- ((type *)((uintptr_t)(ptr) - (uintptr_t)(&(((type *)0)->member))))
44
- #endif
45
-
46
- /* *****************************************************************************
47
- API
48
- ***************************************************************************** */
49
-
50
- /** Returns the `fio_dict_s *` object associated with the key, NULL if none. */
51
- fio_dict_s *fio_dict_get(fio_dict_s *dict, void *key, size_t key_len);
52
-
53
- /** Returns the old `fio_dict_s *` object associated with the key, if any.*/
54
- fio_dict_s *fio_dict_set(fio_dict_s *dict, void *key, size_t key_len,
55
- fio_dict_s *node);
56
-
57
- /** Removes and returns the specified `fio_dict_s *` object.*/
58
- fio_dict_s *fio_dict_remove(fio_dict_s *node);
59
-
60
- /** Returns a `fio_dict_s *` dictionary (or NULL) of all `prefix` children. */
61
- fio_dict_s *fio_dict_step(fio_dict_s *dict, uint8_t prefix);
62
-
63
- /** Returns a `fio_dict_s *` dictionary (or NULL) of all `prefix` children. */
64
- fio_dict_s *fio_dict_prefix(fio_dict_s *dict, void *prefix, size_t len);
65
-
66
- /**
67
- * Creates a `fio_dict_s *` dictionary (if missing) for the `prefix`...
68
- *
69
- * After calling this function a node MUST be added to this dictionary, or
70
- * memory leaks will occure.
71
- */
72
- fio_dict_s *fio_dict_ensure_prefix(fio_dict_s *dict, void *prefix, size_t len);
73
-
74
- /** Traverses a dictionary, performing an action for each item. */
75
- void fio_dict_each(fio_dict_s *dict,
76
- void (*action)(fio_dict_s *node, void *arg), void *arg);
77
-
78
- /** Performing an action for each item matching the glob pattern. */
79
- void fio_dict_each_match_glob(fio_dict_s *dict, void *pattern, size_t len,
80
- void (*action)(fio_dict_s *node, void *arg),
81
- void *arg);
82
-
83
- /** A binary glob matching helper. Returns 1 on match, otherwise returns 0. */
84
- int fio_glob_match(uint8_t *data, size_t data_len, uint8_t *pattern,
85
- size_t pat_len);
86
-
87
- #define fio_dict_isempty(dict) \
88
- (!((dict)->trie[0] || (dict)->trie[1] || (dict)->trie[2] || \
89
- (dict)->trie[3] || (dict)->trie[4] || (dict)->trie[5] || \
90
- (dict)->trie[6] || (dict)->trie[7] || (dict)->trie[8] || \
91
- (dict)->trie[9] || (dict)->trie[10] || (dict)->trie[11] || \
92
- (dict)->trie[12] || (dict)->trie[13] || (dict)->trie[14] || \
93
- (dict)->trie[15]))
94
-
95
- #ifdef __cplusplus
96
- } /* extern "C" */
97
- #endif
98
-
99
- #endif
@@ -1,370 +0,0 @@
1
- #ifndef H_FIO_HASH_TABLE_H
2
- /**
3
- The facil.io hash table imeplementation tries to balance performance with memory
4
- footprint and collision risks.
5
-
6
- It might be a good implementation and it might suck. Test it out and descide for
7
- yourself.
8
-
9
- */
10
- #define H_FIO_HASH_TABLE_H
11
- #include "fio_list.h"
12
-
13
- #include <stdint.h>
14
- #include <stdlib.h>
15
-
16
- /* *****************************************************************************
17
- Data Types and API
18
- ***************************************************************************** */
19
-
20
- #define FIO_FUNC static __attribute__((unused))
21
-
22
- typedef struct {
23
- fio_list_s items;
24
- uint64_t count;
25
- uint64_t bin_count;
26
- uint64_t mask;
27
- struct fio_list_s *bins;
28
- } fio_ht_s;
29
-
30
- /** Used to initialize an empty `fio_ht_s`. */
31
- #define FIO_HASH_TABLE_INIT(name) \
32
- (fio_ht_s) { .items = FIO_LIST_INIT_STATIC(name.items) }
33
-
34
- /** Used to initialize an empty `fio_ht_s`. */
35
- #define FIO_HASH_TABLE_STATIC(name) \
36
- { .items = FIO_LIST_INIT_STATIC(name.items) }
37
-
38
- typedef struct {
39
- fio_list_s items;
40
- fio_list_s siblings;
41
- fio_ht_s *parent;
42
- uint64_t hash;
43
- } fio_ht_node_s;
44
-
45
- #ifndef fio_node2obj
46
- /** Takes a node pointer (list/hash/dict, etc') and returns it's container. */
47
- #define fio_node2obj(type, member, ptr) \
48
- ((type *)((uintptr_t)(ptr) - (uintptr_t)(&(((type *)0)->member))))
49
- #endif
50
-
51
- /** Takes a list pointer and returns a pointer to it's container. */
52
- #define fio_ht_object(type, member, pht) fio_node2obj(type, member, (pht))
53
-
54
- /** A simple SipHash2/4 function implementation that can be used for hashing. */
55
- FIO_FUNC uint64_t fio_ht_hash(const void *data, size_t len);
56
-
57
- /** A simple SipHash2/4 function for when a string's length is unknown. */
58
- FIO_FUNC uint64_t fio_ht_hash_cstr(const void *data);
59
-
60
- /**
61
- * Adds a new item to the hash table.
62
- *
63
- * If a hash collision occurs, the old item is replaced and returned.
64
- */
65
- inline FIO_FUNC fio_ht_node_s *fio_ht_add(fio_ht_s *table, fio_ht_node_s *item,
66
- uint64_t hash_value);
67
-
68
- /** Finds an item in the hash table. */
69
- inline FIO_FUNC fio_ht_node_s *fio_ht_find(fio_ht_s *table,
70
- uint64_t hash_value);
71
- /** Removes the item from the hash table, returning the removed item. */
72
- inline FIO_FUNC fio_ht_node_s *fio_ht_remove(fio_ht_node_s *item);
73
-
74
- /** Finds, removes and returns the matching item from the hash table. */
75
- inline FIO_FUNC fio_ht_node_s *fio_ht_pop(fio_ht_s *table, uint64_t hash);
76
-
77
- /**
78
- * Re-hashes the hash table. This is automatically when growth is required.
79
- *
80
- * `bin_count` MUST be a power of 2 or 0 (0,1,2,4,8,16,32,64,128...).
81
- *
82
- * If `bin_count`, the hash table's memory is released and it will behave like a
83
- * list (until an item is added).
84
- */
85
- inline FIO_FUNC void fio_ht_rehash(fio_ht_s *table, uint64_t bin_count);
86
-
87
- /** iterates through all Hash Table members. */
88
- #define fio_ht_for_each(type, member, var, table) \
89
- fio_list_for_each(type, member.items, var, (table).items)
90
-
91
- /**
92
- * Frees any internal memory used by the hash table.
93
- *
94
- * This soes **NOT** free any items in the table or the table object itself.
95
- */
96
- #define fio_ht_free(table) fio_ht_rehash(table, 0)
97
-
98
- /* *****************************************************************************
99
- Implementations
100
- ***************************************************************************** */
101
-
102
- /** Adds a new item to the hash table. If a hash collision occurs, the old item
103
- * is removed and replaced. */
104
- inline FIO_FUNC fio_ht_node_s *fio_ht_add(fio_ht_s *table, fio_ht_node_s *item,
105
- uint64_t hash) {
106
- fio_ht_node_s *old = fio_ht_find(table, hash);
107
- if (old == item)
108
- return NULL;
109
- /* initialize item */
110
- item->parent = table;
111
- item->hash = hash;
112
- if (old)
113
- goto found_old;
114
- fio_list_add(table->items.prev, &item->items);
115
- table->count++;
116
- if (table->count >= ((table->bin_count >> 2) * 3)) {
117
- fio_ht_rehash(table, (table->bin_count ? (table->bin_count << 1) : 32));
118
- return NULL;
119
- }
120
- fio_list_add(table->bins[item->hash & table->mask].prev, &item->siblings);
121
- return NULL;
122
- found_old:
123
- /* replace inplace. */
124
- *item = *old;
125
- old->parent = NULL;
126
- old->items = FIO_LIST_INIT(old->items);
127
- old->siblings = FIO_LIST_INIT(old->siblings);
128
- item->items.prev->next = &item->items;
129
- item->items.next->prev = &item->items;
130
- item->siblings.prev->next = &item->siblings;
131
- item->siblings.next->prev = &item->siblings;
132
- return old;
133
- }
134
-
135
- /** Finds an item in the hash table. */
136
- inline FIO_FUNC fio_ht_node_s *fio_ht_find(fio_ht_s *table,
137
- uint64_t hash_value) {
138
- fio_ht_node_s *item;
139
- if (!table || !table->bins)
140
- return NULL;
141
- fio_list_for_each(fio_ht_node_s, siblings, item,
142
- table->bins[hash_value & (table->mask)]) {
143
- if (hash_value == item->hash) {
144
- return item;
145
- }
146
- }
147
- return NULL;
148
- }
149
-
150
- /** Removes an item to the hash table. */
151
- inline FIO_FUNC fio_ht_node_s *fio_ht_remove(fio_ht_node_s *item) {
152
- if (!item || !item->parent)
153
- return item;
154
- fio_list_remove(&item->siblings);
155
- fio_list_remove(&item->items);
156
- item->parent->count--;
157
- /* ** memory shrinkage? not really... ** */
158
- /*
159
- if (item->parent->bin_count > 1024 &&
160
- (item->parent->bin_count >> 3) >= item->parent->count)
161
- fio_ht_rehash(item->parent, item->parent->bin_count >> 2);
162
- */
163
- item->parent = NULL;
164
- return item;
165
- }
166
-
167
- /** Finds, removes and returns the matching item from the hash table. */
168
- inline FIO_FUNC fio_ht_node_s *fio_ht_pop(fio_ht_s *table, uint64_t hash) {
169
- fio_ht_node_s *item = fio_ht_find(table, hash);
170
- if (!item)
171
- return NULL;
172
- fio_ht_remove(item);
173
- return item;
174
- }
175
-
176
- /** Re-hashes the hash table. This is usually automatically called. */
177
- inline FIO_FUNC void fio_ht_rehash(fio_ht_s *table, uint64_t bin_count) {
178
- if (!table)
179
- return;
180
- if (!bin_count) {
181
- if (table->bins) {
182
- free(table->bins);
183
- table->bins = NULL;
184
- }
185
- return;
186
- }
187
- void *mem = realloc(table->bins, bin_count * sizeof(*table->bins));
188
- if (!mem)
189
- return;
190
- table->bin_count = bin_count;
191
- table->bins = mem;
192
- table->mask = bin_count - 1;
193
- while (bin_count) {
194
- bin_count--;
195
- table->bins[bin_count] = FIO_LIST_INIT(table->bins[bin_count]);
196
- }
197
- fio_ht_node_s *item;
198
- fio_list_for_each(fio_ht_node_s, items, item, table->items) {
199
- fio_list_add(table->bins[item->hash & table->mask].prev, &item->siblings);
200
- }
201
- }
202
-
203
- /* *****************************************************************************
204
- The Hash Function
205
- ***************************************************************************** */
206
-
207
- #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) && \
208
- __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
209
- /* the algorithm was designed as little endian... so, byte swap 64 bit. */
210
- #define sip_local64(i) \
211
- (((i)&0xFFULL) << 56) | (((i)&0xFF00ULL) << 40) | \
212
- (((i)&0xFF0000ULL) << 24) | (((i)&0xFF000000ULL) << 8) | \
213
- (((i)&0xFF00000000ULL) >> 8) | (((i)&0xFF0000000000ULL) >> 24) | \
214
- (((i)&0xFF000000000000ULL) >> 40) | (((i)&0xFF00000000000000ULL) >> 56)
215
- #else
216
- /* no need */
217
- #define sip_local64(i) (i)
218
- #endif
219
-
220
- /* 64Bit left rotation, inlined. */
221
- #define lrot64(i, bits) \
222
- (((uint64_t)(i) << (bits)) | ((uint64_t)(i) >> (64 - (bits))))
223
-
224
- FIO_FUNC uint64_t fio_ht_hash(const void *data, size_t len) {
225
- /* initialize the 4 words */
226
- uint64_t v0 = (0x0706050403020100ULL ^ 0x736f6d6570736575ULL);
227
- uint64_t v1 = (0x0f0e0d0c0b0a0908ULL ^ 0x646f72616e646f6dULL);
228
- uint64_t v2 = (0x0706050403020100ULL ^ 0x6c7967656e657261ULL);
229
- uint64_t v3 = (0x0f0e0d0c0b0a0908ULL ^ 0x7465646279746573ULL);
230
- const uint64_t *w64 = data;
231
- uint8_t len_mod = len & 255;
232
- union {
233
- uint64_t i;
234
- uint8_t str[8];
235
- } word;
236
-
237
- #define hash_map_SipRound \
238
- do { \
239
- v2 += v3; \
240
- v3 = lrot64(v3, 16) ^ v2; \
241
- v0 += v1; \
242
- v1 = lrot64(v1, 13) ^ v0; \
243
- v0 = lrot64(v0, 32); \
244
- v2 += v1; \
245
- v0 += v3; \
246
- v1 = lrot64(v1, 17) ^ v2; \
247
- v3 = lrot64(v3, 21) ^ v0; \
248
- v2 = lrot64(v2, 32); \
249
- } while (0);
250
-
251
- while (len >= 8) {
252
- word.i = sip_local64(*w64);
253
- v3 ^= word.i;
254
- /* Sip Rounds */
255
- hash_map_SipRound;
256
- hash_map_SipRound;
257
- v0 ^= word.i;
258
- w64 += 1;
259
- len -= 8;
260
- }
261
- word.i = 0;
262
- uint8_t *pos = word.str;
263
- uint8_t *w8 = (void *)w64;
264
- switch (len) { /* fallthrough is intentional */
265
- case 7:
266
- pos[6] = w8[6];
267
- case 6:
268
- pos[5] = w8[5];
269
- case 5:
270
- pos[4] = w8[4];
271
- case 4:
272
- pos[3] = w8[3];
273
- case 3:
274
- pos[2] = w8[2];
275
- case 2:
276
- pos[1] = w8[1];
277
- case 1:
278
- pos[0] = w8[0];
279
- }
280
- word.str[7] = len_mod;
281
-
282
- /* last round */
283
- v3 ^= word.i;
284
- hash_map_SipRound;
285
- hash_map_SipRound;
286
- v0 ^= word.i;
287
- /* Finalization */
288
- v2 ^= 0xff;
289
- /* d iterations of SipRound */
290
- hash_map_SipRound;
291
- hash_map_SipRound;
292
- hash_map_SipRound;
293
- hash_map_SipRound;
294
- /* XOR it all together */
295
- v0 ^= v1 ^ v2 ^ v3;
296
- #undef hash_map_SipRound
297
- return v0;
298
- }
299
-
300
- FIO_FUNC uint64_t fio_ht_hash_cstr(const void *data) {
301
- /* initialize the 4 words */
302
- uint64_t v0 = (0x0706050403020100ULL ^ 0x736f6d6570736575ULL);
303
- uint64_t v1 = (0x0f0e0d0c0b0a0908ULL ^ 0x646f72616e646f6dULL);
304
- uint64_t v2 = (0x0706050403020100ULL ^ 0x6c7967656e657261ULL);
305
- uint64_t v3 = (0x0f0e0d0c0b0a0908ULL ^ 0x7465646279746573ULL);
306
- const uint64_t *w64 = data;
307
- uint8_t len = 0;
308
- union {
309
- uint64_t i;
310
- uint8_t str[8];
311
- } word;
312
-
313
- #define hash_map_SipRound \
314
- do { \
315
- v2 += v3; \
316
- v3 = lrot64(v3, 16) ^ v2; \
317
- v0 += v1; \
318
- v1 = lrot64(v1, 13) ^ v0; \
319
- v0 = lrot64(v0, 32); \
320
- v2 += v1; \
321
- v0 += v3; \
322
- v1 = lrot64(v1, 17) ^ v2; \
323
- v3 = lrot64(v3, 21) ^ v0; \
324
- v2 = lrot64(v2, 32); \
325
- } while (0);
326
-
327
- while ((*w64 & 0xFFULL) && (*w64 & 0xFF00ULL) && (*w64 & 0xFF0000ULL) &&
328
- (*w64 & 0xFF000000ULL) && (*w64 & 0xFF00000000ULL) &&
329
- (*w64 & 0xFF0000000000ULL) && (*w64 & 0xFF000000000000ULL) &&
330
- (*w64 & 0xFF00000000000000ULL)) {
331
- word.i = sip_local64(*w64);
332
- v3 ^= word.i;
333
- /* Sip Rounds */
334
- hash_map_SipRound;
335
- hash_map_SipRound;
336
- v0 ^= word.i;
337
- w64 += 1;
338
- len += 8;
339
- }
340
- word.i = 0;
341
- uint8_t *pos = word.str;
342
- uint8_t *w8 = (void *)w64;
343
- while (*w8) {
344
- *(pos++) = *(w8++);
345
- len++;
346
- }
347
- word.str[7] = len & 255;
348
-
349
- /* last round */
350
- v3 ^= word.i;
351
- hash_map_SipRound;
352
- hash_map_SipRound;
353
- v0 ^= word.i;
354
- /* Finalization */
355
- v2 ^= 0xff;
356
- /* d iterations of SipRound */
357
- hash_map_SipRound;
358
- hash_map_SipRound;
359
- hash_map_SipRound;
360
- hash_map_SipRound;
361
- /* XOR it all together */
362
- v0 ^= v1 ^ v2 ^ v3;
363
- #undef hash_map_SipRound
364
- return v0;
365
- }
366
-
367
- #undef sip_local64
368
- #undef lrot64
369
- #undef FIO_FUNC
370
- #endif