1
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
5
COPYING CONDITIONS NOTICE:
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of version 2 of the GNU General Public License as
9
published by the Free Software Foundation, and provided that the
10
following conditions are met:
12
* Redistributions of source code must retain this COPYING
13
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
14
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
15
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
18
* Redistributions in binary form must reproduce this COPYING
19
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
20
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
21
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
22
GRANT (below) in the documentation and/or other materials
23
provided with the distribution.
25
You should have received a copy of the GNU General Public License
26
along with this program; if not, write to the Free Software
27
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32
TokuDB, Tokutek Fractal Tree Indexing Library.
33
Copyright (C) 2007-2013 Tokutek, Inc.
37
This program is distributed in the hope that it will be useful, but
38
WITHOUT ANY WARRANTY; without even the implied warranty of
39
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40
General Public License for more details.
42
UNIVERSITY PATENT NOTICE:
44
The technology is licensed by the Massachusetts Institute of
45
Technology, Rutgers State University of New Jersey, and the Research
46
Foundation of State University of New York at Stony Brook under
47
United States of America Serial No. 11/760379 and to the patents
48
and/or patent applications resulting from it.
50
PATENT MARKING NOTICE:
52
This software is covered by US Patent No. 8,185,551.
53
This software is covered by US Patent No. 8,489,638.
57
"THIS IMPLEMENTATION" means the copyrightable works distributed by
58
Tokutek as part of the Fractal Tree project.
60
"PATENT CLAIMS" means the claims of patents that are owned or
61
licensable by Tokutek, both currently or in the future; and that in
62
the absence of this license would be infringed by THIS
63
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
65
"PATENT CHALLENGE" shall mean a challenge to the validity,
66
patentability, enforceability and/or non-infringement of any of the
67
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
69
Tokutek hereby grants to you, for the term and geographical scope of
70
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
71
irrevocable (except as stated in this section) patent license to
72
make, have made, use, offer to sell, sell, import, transfer, and
73
otherwise run, modify, and propagate the contents of THIS
74
IMPLEMENTATION, where such license applies only to the PATENT
75
CLAIMS. This grant does not include claims that would be infringed
76
only as a consequence of further modifications of THIS
77
IMPLEMENTATION. If you or your agent or licensee institute or order
78
or agree to the institution of patent litigation against any entity
79
(including a cross-claim or counterclaim in a lawsuit) alleging that
80
THIS IMPLEMENTATION constitutes direct or contributory patent
81
infringement, or inducement of patent infringement, then any rights
82
granted to you under this License shall terminate as of the date
83
such litigation is filed. If you or your agent or exclusive
84
licensee institute or order or agree to the institution of a PATENT
85
CHALLENGE, then Tokutek may terminate any rights granted to you
89
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
90
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
92
#include <toku_stdlib.h>
93
#include <toku_include/toku_portability.h>
99
uint32_t x1764_memory_simple (const void *buf, int len)
101
const uint64_t *CAST_FROM_VOIDP(lbuf, buf);
105
if (PRINT) printf("%d: c=%016" PRIx64 " sum=%016" PRIx64 "\n", __LINE__, *lbuf, c);
110
const uint8_t *cbuf=(uint8_t*)lbuf;
113
for (i=0; i<len; i++) {
114
input |= ((uint64_t)(cbuf[i]))<<(8*i);
118
return ~((c&0xFFFFFFFF) ^ (c>>32));
121
uint32_t x1764_memory (const void *vbuf, int len)
123
const uint8_t *CAST_FROM_VOIDP(buf, vbuf);
124
int len_4_words = 4*sizeof(uint64_t);
125
uint64_t suma=0, sumb=0, sumc=0, sumd=0;
126
while (len >= len_4_words) {
127
suma = suma*(17LL*17LL*17LL*17LL) + *(uint64_t*)(buf +0*sizeof(uint64_t));
128
sumb = sumb*(17LL*17LL*17LL*17LL) + *(uint64_t*)(buf +1*sizeof(uint64_t));
129
sumc = sumc*(17LL*17LL*17LL*17LL) + *(uint64_t*)(buf +2*sizeof(uint64_t));
130
sumd = sumd*(17LL*17LL*17LL*17LL) + *(uint64_t*)(buf +3*sizeof(uint64_t));
134
uint64_t sum = suma*17L*17L*17L + sumb*17L*17L + sumc*17L + sumd;
136
while ((uint64_t)len>=sizeof(uint64_t)) {
137
sum = sum*17 + *(uint64_t*)buf;
138
buf+=sizeof(uint64_t);
139
len-=sizeof(uint64_t);
142
uint64_t tailsum = 0;
143
for (int i=0; i<len; i++) {
144
tailsum |= ((uint64_t)(buf[i]))<<(8*i);
146
sum = sum*17 + tailsum;
148
return ~((sum&0xFFFFFFFF) ^ (sum>>32));
152
void x1764_init(struct x1764 *l) {
158
void x1764_add (struct x1764 *l, const void *vbuf, int len) {
159
if (PRINT) printf("%d: n_input_bytes=%d len=%d\n", __LINE__, l->n_input_bytes, len);
160
int n_input_bytes = l->n_input_bytes;
161
const unsigned char *CAST_FROM_VOIDP(cbuf, vbuf);
162
// Special case short inputs
164
uint64_t input = l->input | ((uint64_t)(*cbuf))<<(8*n_input_bytes);
166
if (n_input_bytes==8) {
167
l->sum = l->sum*17 + input;
168
l->n_input_bytes = 0;
172
l->n_input_bytes = n_input_bytes;
176
uint64_t input = l->input;
177
uint64_t thisv = ((uint64_t)(*(uint16_t*)cbuf));
178
if (n_input_bytes==7) {
179
l->sum = l->sum*17 + (input | (thisv<<(8*7)));
181
l->n_input_bytes = 1;
182
} else if (n_input_bytes==6) {
183
l->sum = l->sum*17 + (input | (thisv<<(8*6)));
185
l->n_input_bytes = 0;
187
l->input = input | (thisv<<(8*n_input_bytes));
188
l->n_input_bytes += 2;
196
uint64_t input = l->input;
200
uint64_t thisv = *(uint64_t*)cbuf;
201
input |= thisv<<(8*n_input_bytes);
202
sum = sum*17 + input;
203
if (PRINT) printf("%d: input=%016" PRIx64 " sum=%016" PRIx64 "\n", __LINE__, input, sum);
204
input = thisv>>(8*(8-n_input_bytes));
205
if (PRINT) printf("%d: input=%016" PRIx64 "\n", __LINE__, input);
208
// n_input_bytes remains unchanged
209
if (PRINT) printf("%d: n_input_bytes=%d len=%d\n", __LINE__, l->n_input_bytes, len);
214
uint64_t thisv = *(uint32_t*)cbuf;
215
if (n_input_bytes<4) {
216
input |= thisv<<(8*n_input_bytes);
217
if (PRINT) printf("%d: input=%016" PRIx64 "\n", __LINE__, input);
220
input |= thisv<<(8*n_input_bytes);
221
l->sum = l->sum*17 + input;
222
if (PRINT) printf("%d: input=%016" PRIx64 " sum=%016" PRIx64 "\n", __LINE__, input, l->sum);
223
input = thisv>>(8*(8-n_input_bytes));
225
if (PRINT) printf("%d: input=%016" PRIx64 " n_input_bytes=%d\n", __LINE__, input, n_input_bytes);
229
if (PRINT) printf("%d: len=%d\n", __LINE__, len);
231
//assert(n_input_bytes<=8);
232
while (n_input_bytes<8 && len) {
233
input |= ((uint64_t)(*cbuf))<<(8*n_input_bytes);
239
if (n_input_bytes<8) {
242
l->n_input_bytes = n_input_bytes;
243
if (PRINT) printf("%d: n_input_bytes=%d\n", __LINE__, l->n_input_bytes);
246
sum = l->sum*17 + input;
253
sum = sum*17 + *(uint64_t*)cbuf;
260
l->n_input_bytes = len;
261
// Surprisingly, the loop is the fastest on bradley's laptop.
265
for (i=0; i<len; i++) {
266
input |= ((uint64_t)(cbuf[i]))<<(8*i);
270
case 7: input = ((uint64_t)(*(uint32_t*)(cbuf))) | (((uint64_t)(*(uint16_t*)(cbuf+4)))<<32) | (((uint64_t)(*(cbuf+4)))<<48); break;
271
case 6: input = ((uint64_t)(*(uint32_t*)(cbuf))) | (((uint64_t)(*(uint16_t*)(cbuf+4)))<<32); break;
272
case 5: input = ((uint64_t)(*(uint32_t*)(cbuf))) | (((uint64_t)(*(cbuf+4)))<<32); break;
273
case 4: input = ((uint64_t)(*(uint32_t*)(cbuf))); break;
274
case 3: input = ((uint64_t)(*(uint16_t*)(cbuf))) | (((uint64_t)(*(cbuf+2)))<<16); break;
275
case 2: input = ((uint64_t)(*(uint16_t*)(cbuf))); break;
276
case 1: input = ((uint64_t)(*cbuf)); break;
277
case 0: input = 0; break;
283
if (len>=4) { input = ((uint64_t)(*(uint32_t*)(cbuf))); cbuf+=4; len-=4; i=4;}
284
if (len>=2) { input |= ((uint64_t)(*(uint16_t*)(cbuf)))<<(i*8); cbuf+=2; len-=2; i+=2; }
285
if (len>=1) { input |= ((uint64_t)(*(uint8_t *)(cbuf)))<<(i*8); /*cbuf+=1; len-=1; i++;*/ }
288
if (PRINT) printf("%d: n_input_bytes=%d\n", __LINE__, l->n_input_bytes);
290
uint32_t x1764_finish (struct x1764 *l) {
291
if (PRINT) printf("%d: n_input_bytes=%d\n", __LINE__, l->n_input_bytes);
292
int len = l->n_input_bytes;
294
l->sum = l->sum*17 + l->input;
296
return ~((l->sum &0xffffffff) ^ (l->sum>>32));