-
Notifications
You must be signed in to change notification settings - Fork 25
/
qmx_codec.hpp
6123 lines (6069 loc) · 371 KB
/
qmx_codec.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
qmx_codec.hpp (modified by Matthias Petri)
Taken from COMPRESS_INTEGER_QMX_IMPROVED.CPP
---------------------------------
Copyright (c) 2014-2017 Andrew Trotman
Released under the 2-clause BSD license
(See:https://en.wikipedia.org/wiki/BSD_licenses)
A version of BinPacking where we pack into a 128-bit SSE register the
following:
256 0-bit words
128 1-bit words
64 2-bit words
40 3-bit words
32 4-bit words
24 5-bit words
20 6-bit words
16 8-bit words
12 10-bit words
8 16-bit words
4 32-bit words
or pack into two 128-bit words (i.e. 256 bits) the following:
36 7-bit words
28 9-bit words
20 12-bit words
12 21-bit words
This gives us 15 possible combinations. The combinaton is stored in the
top 4 bits of a selector byte. The
bottom 4-bits of the selector store a run-length (the number of such
sequences seen in a row.
The 128-bit (or 256-bit) packed binary values are stored first. Then we
store the selectors, Finally,
stored variable byte encoded, is a pointer to the start of the selector
(from the end of the sequence).
This way, all reads and writes are 128-bit word aligned, except
addressing the selector (and the pointer
the selector). These reads are byte aligned.
Note: There is curly 1 unused encoding (i.e. 16 unused selecvtor
values). These might in the future be
used for encoding exceptions, much as PForDelta does.
*/
#include <array>
#include <vector>
#include <emmintrin.h>
#include <smmintrin.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
namespace QMX {
namespace constants {
const uint32_t WASTAGE = 512;
struct type_and_integers {
size_t type;
size_t integers;
};
// clang-format off
static const type_and_integers table[] = {
{0, 256}, // size_in_bits == 0;
{1, 128}, // size_in_bits == 1;
{2, 64}, // size_in_bits == 2;
{3, 40}, // size_in_bits == 3;
{4, 32}, // size_in_bits == 4;
{5, 24}, // size_in_bits == 5;
{6, 20}, // size_in_bits == 6;
{7, 36}, // size_in_bits == 7; 256-bits
{8, 16}, // size_in_bits == 8;
{9, 28}, // size_in_bits == 9; 256-bits
{10, 12}, // size_in_bits == 10;
{0, 0},
{11, 20}, // size_in_bits == 12;
{0, 0},
{0, 0},
{0, 0},
{12, 8}, // size_in_bits == 16;
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{13, 12}, // size_in_bits == 21; 256-bits
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{14, 4}, // size_in_bits == 32;
};
alignas(16) static uint32_t static_mask_21[] = {0x1fffff, 0x1fffff, 0x1fffff, 0x1fffff};
alignas(16) static uint32_t static_mask_12[] = {0xfff, 0xfff, 0xfff, 0xfff};
alignas(16) static uint32_t static_mask_10[] = {0x3ff, 0x3ff, 0x3ff, 0x3ff};
alignas(16) static uint32_t static_mask_9[] = {0x1ff, 0x1ff, 0x1ff, 0x1ff};
alignas(16) static uint32_t static_mask_7[] = {0x7f, 0x7f, 0x7f, 0x7f};
alignas(16) static uint32_t static_mask_6[] = {0x3f, 0x3f, 0x3f, 0x3f};
alignas(16) static uint32_t static_mask_5[] = {0x1f, 0x1f, 0x1f, 0x1f};
alignas(16) static uint32_t static_mask_4[] = {0x0f, 0x0f, 0x0f, 0x0f};
alignas(16) static uint32_t static_mask_3[] = {0x07, 0x07, 0x07, 0x07};
alignas(16) static uint32_t static_mask_2[] = {0x03, 0x03, 0x03, 0x03};
alignas(16) static uint32_t static_mask_1[] = {0x01, 0x01, 0x01, 0x01};
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
namespace util {
template <class T> T maximum(T a, T b) { return a > b ? a : b; }
template <class T> T maximum(T a, T b, T c, T d)
{
return maximum(maximum(a, b),maximum(c, d));
}
// How many QMX bits are needed to store and integer of the given value
static uint8_t bits_needed_for(uint32_t value)
{
if (value == 0x01)
return 0;
else if (value <= 0x01)
return 1;
else if (value <= 0x03)
return 2;
else if (value <= 0x07)
return 3;
else if (value <= 0x0F)
return 4;
else if (value <= 0x1F)
return 5;
else if (value <= 0x3F)
return 6;
else if (value <= 0x7F)
return 7;
else if (value <= 0xFF)
return 8;
else if (value <= 0x1FF)
return 9;
else if (value <= 0x3FF)
return 10;
else if (value <= 0xFFF)
return 12;
else if (value <= 0xFFFF)
return 16;
else if (value <= 0x1FFFFF)
return 21;
else
return 32;
}
// clang-format on
}
template <uint32_t block_size> struct codec {
static_assert(block_size % 8 == 0, "Block size must be multiple of 8");
std::vector<uint8_t> length_buffer;
std::vector<uint32_t> full_length_buffer;
codec()
{
length_buffer.resize(block_size + constants::WASTAGE);
full_length_buffer.resize(block_size + constants::WASTAGE);
}
void write_out(uint8_t** buffer, uint32_t* src, uint32_t raw_count, uint32_t size_in_bits, uint8_t** length_buffer)
{
uint32_t cur, batch;
uint8_t* dest = *buffer;
uint8_t* key_store = *length_buffer;
uint32_t sequence_buffer[4];
uint32_t instance, value;
uint8_t type;
uint32_t count;
type = constants::table[size_in_bits].type;
count = (raw_count + constants::table[size_in_bits].integers - 1) / constants::table[size_in_bits].integers;
// 0-pad if there aren't enough integers in the src buffer.
auto flb = full_length_buffer.data();
if (constants::table[size_in_bits].type != 0 && count * constants::table[size_in_bits].integers != raw_count) {
// must 0-pad to prevent read overflow in input buffer
std::copy(src, src + raw_count, flb);
std::fill(flb + raw_count, flb + (count * constants::table[size_in_bits].integers), 0);
src = flb;
}
uint32_t* end = src + raw_count;
while (count > 0) {
batch = count > 16 ? 16 : count;
*key_store++ = (type << 4) | (~(batch - 1) & 0x0F);
count -= batch;
for (cur = 0; cur < batch; cur++) {
switch (size_in_bits) {
case 0: // 0 bits per integer (i.e. a long sequence of zeros)
// we don't need to store a 4 byte integer because its
// implicit
src += 256;
break;
case 1: // 1 bit per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 128; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 1);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 128;
break;
case 2: // 2 bits per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 64; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 2);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 64;
break;
case 3: // 3 bits per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 40; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 3);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 40;
break;
case 4: // 4 bits per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 32; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 4);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 32;
break;
case 5: // 5 bits per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 24; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 5);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 24;
break;
case 6: // 6 bits per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 20; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 6);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 20;
break;
case 7: // 7 bits per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 20; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 7);
memcpy(dest, sequence_buffer, 16);
dest += 16;
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 16; value < 20; value++)
sequence_buffer[value & 0x03] |= src[value] >> 4;
for (value = 20; value < 36; value++)
sequence_buffer[value & 0x03] |= src[value] << (((value - 20) / 4) * 7 + 3);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 36; // 36 in a double 128-bit word
break;
case 8: // 8 bits per integer
for (instance = 0; instance < 16 && src < end; instance++)
*dest++ = (uint8_t)*src++;
break;
case 9: // 9 bits per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 16; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 9);
memcpy(dest, sequence_buffer, 16);
dest += 16;
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 12; value < 16; value++)
sequence_buffer[value & 0x03] |= src[value] >> 5;
for (value = 16; value < 28; value++)
sequence_buffer[value & 0x03] |= src[value] << (((value - 16) / 4) * 9 + 4);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 28; // 28 in a double 128-bit word
break;
case 10: // 10 bits per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 12; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 10);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 12;
break;
case 12: // 12 bit integers
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 12; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 12);
memcpy(dest, sequence_buffer, 16);
dest += 16;
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 8; value < 12; value++)
sequence_buffer[value & 0x03] |= src[value] >> 8;
for (value = 12; value < 20; value++)
sequence_buffer[value & 0x03] |= src[value] << (((value - 12) / 4) * 12 + 8);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 20; // 20 in a double 128-bit word
break;
case 16: // 16 bits per integer
for (instance = 0; instance < 8 && src < end; instance++) {
*(uint16_t*)dest = (uint16_t)*src++;
dest += 2;
}
break;
case 21: // 21 bits per integer
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 0; value < 8; value++)
sequence_buffer[value & 0x03] |= src[value] << ((value / 4) * 21);
memcpy(dest, sequence_buffer, 16);
dest += 16;
memset(sequence_buffer, 0, sizeof(sequence_buffer));
for (value = 4; value < 8; value++)
sequence_buffer[value & 0x03] |= src[value] >> 11;
for (value = 8; value < 12; value++)
sequence_buffer[value & 0x03] |= src[value] << (((value - 8) / 4) * 21 + 11);
memcpy(dest, sequence_buffer, 16);
dest += 16;
src += 12; // 12 in a double 128-bit word
break;
case 32: // 32 bits per integer
for (instance = 0; instance < 4 && src < end; instance++) {
*(uint32_t*)dest = (uint32_t)*src++;
dest += 4;
}
break;
}
}
}
*buffer = dest;
*length_buffer = key_store;
}
size_t encode(void* dest_as_void, const uint32_t* src)
{
uint32_t* dest32 = static_cast<uint32_t*>(dest_as_void);
uint8_t *cur_len, *dest = (uint8_t *)dest32, *keys;
uint32_t rlen, bits, new_needed, wastage;
uint32_t block, largest;
uint8_t* len_buf = length_buffer.data();
const uint32_t* cur;
// (1) Get the lengths of the integers
cur_len = len_buf;
for (cur = src; cur < src + block_size; cur += 8) {
*(cur_len) = util::bits_needed_for(*cur);
*(cur_len + 1) = util::bits_needed_for(*(cur + 1));
*(cur_len + 2) = util::bits_needed_for(*(cur + 2));
*(cur_len + 3) = util::bits_needed_for(*(cur + 3));
*(cur_len + 4) = util::bits_needed_for(*(cur + 4));
*(cur_len + 5) = util::bits_needed_for(*(cur + 5));
*(cur_len + 6) = util::bits_needed_for(*(cur + 6));
*(cur_len + 7) = util::bits_needed_for(*(cur + 7));
cur_len += 8;
}
// (2) Add 0 length integers on the end to allow for overflow
for (wastage = 0; wastage < constants::WASTAGE; wastage++) {
*cur_len++ = 0;
}
/*
(3) Process the lengths. To maximise SSE throughput we need
each write to be 128-bit (4*32-bit) aligned and therefore
we need each compress "block" to be the same size where a
compressed "block" is a set of four encoded integers
starting on a 4-integer boundary.
*/
for (uint8_t* cl = len_buf; cl < len_buf + block_size + 4; cl += 4) {
*cl = *(cl + 1) = *(cl + 2) = *(cl + 3) = util::maximum(*cl, *(cl + 1), *(cl + 2), *(cl + 3));
}
/*
This code makes sure we can do aligned reads, promoting to
larger integers if necessary
*/
cur_len = len_buf;
while (cur_len < len_buf + block_size) {
/*
If there are fewer than 16 values remaining and they all fit
into 8-bits then its smaller than storing stripes
If there are fewer than 8 values remaining and they all fit
into 16-bits then its smaller than storing stripes
If there are fewer than 4 values remaining and they all fit
into 32-bits then its smaller than storing stripes
*/
if (block_size - (cur_len - len_buf) < 4) {
largest = 0;
for (block = 0; block < 8; block++)
largest = util::maximum((uint8_t)largest, *(cur_len + block));
if (largest <= 8)
for (block = 0; block < 8; block++)
*(cur_len + block) = 8;
else if (largest <= 16)
for (block = 0; block < 8; block++)
*(cur_len + block) = 16;
else if (largest <= 32)
for (block = 0; block < 8; block++)
*(cur_len + block) = 32;
} else if (block_size - (cur_len - len_buf) < 8) {
largest = 0;
for (block = 0; block < 8; block++)
largest = util::maximum((uint8_t)largest, *(cur_len + block));
if (largest <= 8)
for (block = 0; block < 8; block++)
*(cur_len + block) = 8;
else if (largest <= 8)
for (block = 0; block < 8; block++)
*(cur_len + block) = 16;
} else if (block_size - (cur_len - len_buf) < 16) {
largest = 0;
for (block = 0; block < 16; block++)
largest = util::maximum((uint8_t)largest, *(cur_len + block));
if (largest <= 8)
for (block = 0; block < 16; block++)
*(cur_len + block) = 8;
}
// Otherwise we have the standard rules for a block
switch (*cur_len) {
case 0:
for (block = 0; block < 256; block += 4)
if (*(cur_len + block) > 0)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 1; // promote
if (*cur_len == 0) {
for (block = 0; block < 256; block++)
cur_len[block] = 0;
cur_len += 256;
}
break;
case 1:
for (block = 0; block < 128; block += 4)
if (*(cur_len + block) > 1)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 2; // promote
if (*cur_len == 1) {
for (block = 0; block < 128; block++)
cur_len[block] = 1;
cur_len += 128;
}
break;
case 2:
for (block = 0; block < 64; block += 4)
if (*(cur_len + block) > 2)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 3; // promote
if (*cur_len == 2) {
for (block = 0; block < 64; block++)
cur_len[block] = 2;
cur_len += 64;
}
break;
case 3:
for (block = 0; block < 40; block += 4)
if (*(cur_len + block) > 3)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 4; // promote
if (*cur_len == 3) {
for (block = 0; block < 40; block++)
cur_len[block] = 3;
cur_len += 40;
}
break;
case 4:
for (block = 0; block < 32; block += 4)
if (*(cur_len + block) > 4)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 5; // promote
if (*cur_len == 4) {
for (block = 0; block < 32; block++)
cur_len[block] = 4;
cur_len += 32;
}
break;
case 5:
for (block = 0; block < 24; block += 4)
if (*(cur_len + block) > 5)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 6; // promote
if (*cur_len == 5) {
for (block = 0; block < 24; block++)
cur_len[block] = 5;
cur_len += 24;
}
break;
case 6:
for (block = 0; block < 20; block += 4)
if (*(cur_len + block) > 6)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 7; // promote
if (*cur_len == 6) {
for (block = 0; block < 20; block++)
cur_len[block] = 6;
cur_len += 20;
}
break;
case 7:
for (block = 0; block < 36; block += 4) // 36 in a double 128-bit word
if (*(cur_len + block) > 7)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 8; // promote
if (*cur_len == 7) {
for (block = 0; block < 36; block++)
cur_len[block] = 7;
cur_len += 36;
}
break;
case 8:
for (block = 0; block < 16; block += 4)
if (*(cur_len + block) > 8)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 9; // promote
if (*cur_len == 8) {
for (block = 0; block < 16; block++)
cur_len[block] = 8;
cur_len += 16;
}
break;
case 9:
for (block = 0; block < 28; block += 4) // 28 in a double 128-bit word
if (*(cur_len + block) > 9)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 10; // promote
if (*cur_len == 9) {
for (block = 0; block < 28; block++)
cur_len[block] = 9;
cur_len += 28;
}
break;
case 10:
for (block = 0; block < 12; block += 4)
if (*(cur_len + block) > 10)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 12; // promote
if (*cur_len == 10) {
for (block = 0; block < 12; block++)
cur_len[block] = 10;
cur_len += 12;
}
break;
case 12:
for (block = 0; block < 20; block += 4) // 20 in a double 128-bit word
if (*(cur_len + block) > 12)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 16; // promote
if (*cur_len == 12) {
for (block = 0; block < 20; block++)
cur_len[block] = 12;
cur_len += 20;
}
break;
case 16:
for (block = 0; block < 8; block += 4)
if (*(cur_len + block) > 16)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 21; // promote
if (*cur_len == 16) {
for (block = 0; block < 8; block++)
cur_len[block] = 16;
cur_len += 8;
}
break;
case 21:
for (block = 0; block < 12; block += 4) // 12 in a double 128-bit word
if (*(cur_len + block) > 21)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 32; // promote
if (*cur_len == 21) {
for (block = 0; block < 12; block++)
cur_len[block] = 21;
cur_len += 12;
}
break;
case 32:
for (block = 0; block < 4; block += 4)
if (*(cur_len + block) > 32)
*cur_len = *(cur_len + 1) = *(cur_len + 2) = *(cur_len + 3) = 64; // promote
if (*cur_len == 32) {
for (block = 0; block < 4; block++)
cur_len[block] = 32;
cur_len += 4;
}
break;
default:
exit(printf("Selecting on a non whole power of 2\n"));
break;
}
}
// We can now compress based on the lengths in len_buf
rlen = 1;
bits = len_buf[0];
// we're going to re-use the len_buf because it can't overlap
keys = len_buf;
for (cur = (uint32_t*)src + 1; cur < src + block_size; cur++) {
new_needed = len_buf[cur - src];
if (new_needed == bits) {
rlen++;
} else {
write_out(&dest, (uint32_t*)cur - rlen, rlen, bits, &keys);
bits = new_needed;
rlen = 1;
}
}
write_out(&dest, (uint32_t*)cur - rlen, rlen, bits, &keys);
// Copy the lengths to the end, backwards
uint8_t* from = len_buf + (keys - len_buf) - 1;
uint8_t* to = dest;
for (uint32_t pos = 0; pos < keys - len_buf; pos++) {
*to++ = *from--;
}
dest += keys - len_buf;
// Compute the length (in bytes) and return length in bytes
return dest - (uint8_t*)dest_as_void;
}
void decode(uint32_t* to, const void* src, size_t len)
{
__m128i byte_stream, byte_stream_2, tmp, tmp2, mask_21, mask_12, mask_10, mask_9, mask_7, mask_6, mask_5,
mask_4, mask_3, mask_2, mask_1;
uint8_t* in = (uint8_t*)src;
uint8_t* keys = ((uint8_t*)src) + len - 1;
mask_21 = _mm_loadu_si128((__m128i*)constants::static_mask_21);
mask_12 = _mm_loadu_si128((__m128i*)constants::static_mask_12);
mask_10 = _mm_loadu_si128((__m128i*)constants::static_mask_10);
mask_9 = _mm_loadu_si128((__m128i*)constants::static_mask_9);
mask_7 = _mm_loadu_si128((__m128i*)constants::static_mask_7);
mask_6 = _mm_loadu_si128((__m128i*)constants::static_mask_6);
mask_5 = _mm_loadu_si128((__m128i*)constants::static_mask_5);
mask_4 = _mm_loadu_si128((__m128i*)constants::static_mask_4);
mask_3 = _mm_loadu_si128((__m128i*)constants::static_mask_3);
mask_2 = _mm_loadu_si128((__m128i*)constants::static_mask_2);
mask_1 = _mm_loadu_si128((__m128i*)constants::static_mask_1);
while (in <= keys) {
switch (*keys--) {
case 0x00:
tmp = _mm_loadu_si128((__m128i*)constants::static_mask_1);
_mm_storeu_si128((__m128i*)to, tmp);
_mm_storeu_si128((__m128i*)to + 1, tmp);
_mm_storeu_si128((__m128i*)to + 2, tmp);
_mm_storeu_si128((__m128i*)to + 3, tmp);
_mm_storeu_si128((__m128i*)to + 4, tmp);
_mm_storeu_si128((__m128i*)to + 5, tmp);
_mm_storeu_si128((__m128i*)to + 6, tmp);
_mm_storeu_si128((__m128i*)to + 7, tmp);
_mm_storeu_si128((__m128i*)to + 8, tmp);
_mm_storeu_si128((__m128i*)to + 9, tmp);
_mm_storeu_si128((__m128i*)to + 10, tmp);
_mm_storeu_si128((__m128i*)to + 11, tmp);
_mm_storeu_si128((__m128i*)to + 12, tmp);
_mm_storeu_si128((__m128i*)to + 13, tmp);
_mm_storeu_si128((__m128i*)to + 14, tmp);
_mm_storeu_si128((__m128i*)to + 15, tmp);
_mm_storeu_si128((__m128i*)to + 16, tmp);
_mm_storeu_si128((__m128i*)to + 17, tmp);
_mm_storeu_si128((__m128i*)to + 18, tmp);
_mm_storeu_si128((__m128i*)to + 19, tmp);
_mm_storeu_si128((__m128i*)to + 20, tmp);
_mm_storeu_si128((__m128i*)to + 21, tmp);
_mm_storeu_si128((__m128i*)to + 22, tmp);
_mm_storeu_si128((__m128i*)to + 23, tmp);
_mm_storeu_si128((__m128i*)to + 24, tmp);
_mm_storeu_si128((__m128i*)to + 25, tmp);
_mm_storeu_si128((__m128i*)to + 26, tmp);
_mm_storeu_si128((__m128i*)to + 27, tmp);
_mm_storeu_si128((__m128i*)to + 28, tmp);
_mm_storeu_si128((__m128i*)to + 29, tmp);
_mm_storeu_si128((__m128i*)to + 30, tmp);
_mm_storeu_si128((__m128i*)to + 31, tmp);
_mm_storeu_si128((__m128i*)to + 32, tmp);
_mm_storeu_si128((__m128i*)to + 33, tmp);
_mm_storeu_si128((__m128i*)to + 34, tmp);
_mm_storeu_si128((__m128i*)to + 35, tmp);
_mm_storeu_si128((__m128i*)to + 36, tmp);
_mm_storeu_si128((__m128i*)to + 37, tmp);
_mm_storeu_si128((__m128i*)to + 38, tmp);
_mm_storeu_si128((__m128i*)to + 39, tmp);
_mm_storeu_si128((__m128i*)to + 40, tmp);
_mm_storeu_si128((__m128i*)to + 41, tmp);
_mm_storeu_si128((__m128i*)to + 42, tmp);
_mm_storeu_si128((__m128i*)to + 43, tmp);
_mm_storeu_si128((__m128i*)to + 44, tmp);
_mm_storeu_si128((__m128i*)to + 45, tmp);
_mm_storeu_si128((__m128i*)to + 46, tmp);
_mm_storeu_si128((__m128i*)to + 47, tmp);
_mm_storeu_si128((__m128i*)to + 48, tmp);
_mm_storeu_si128((__m128i*)to + 49, tmp);
_mm_storeu_si128((__m128i*)to + 50, tmp);
_mm_storeu_si128((__m128i*)to + 51, tmp);
_mm_storeu_si128((__m128i*)to + 52, tmp);
_mm_storeu_si128((__m128i*)to + 53, tmp);
_mm_storeu_si128((__m128i*)to + 54, tmp);
_mm_storeu_si128((__m128i*)to + 55, tmp);
_mm_storeu_si128((__m128i*)to + 56, tmp);
_mm_storeu_si128((__m128i*)to + 57, tmp);
_mm_storeu_si128((__m128i*)to + 58, tmp);
_mm_storeu_si128((__m128i*)to + 59, tmp);
_mm_storeu_si128((__m128i*)to + 60, tmp);
_mm_storeu_si128((__m128i*)to + 61, tmp);
_mm_storeu_si128((__m128i*)to + 62, tmp);
_mm_storeu_si128((__m128i*)to + 63, tmp);
to += 256;
case 0x01:
tmp = _mm_loadu_si128((__m128i*)constants::static_mask_1);
_mm_storeu_si128((__m128i*)to, tmp);
_mm_storeu_si128((__m128i*)to + 1, tmp);
_mm_storeu_si128((__m128i*)to + 2, tmp);
_mm_storeu_si128((__m128i*)to + 3, tmp);
_mm_storeu_si128((__m128i*)to + 4, tmp);
_mm_storeu_si128((__m128i*)to + 5, tmp);
_mm_storeu_si128((__m128i*)to + 6, tmp);
_mm_storeu_si128((__m128i*)to + 7, tmp);
_mm_storeu_si128((__m128i*)to + 8, tmp);
_mm_storeu_si128((__m128i*)to + 9, tmp);
_mm_storeu_si128((__m128i*)to + 10, tmp);
_mm_storeu_si128((__m128i*)to + 11, tmp);
_mm_storeu_si128((__m128i*)to + 12, tmp);
_mm_storeu_si128((__m128i*)to + 13, tmp);
_mm_storeu_si128((__m128i*)to + 14, tmp);
_mm_storeu_si128((__m128i*)to + 15, tmp);
_mm_storeu_si128((__m128i*)to + 16, tmp);
_mm_storeu_si128((__m128i*)to + 17, tmp);
_mm_storeu_si128((__m128i*)to + 18, tmp);
_mm_storeu_si128((__m128i*)to + 19, tmp);
_mm_storeu_si128((__m128i*)to + 20, tmp);
_mm_storeu_si128((__m128i*)to + 21, tmp);
_mm_storeu_si128((__m128i*)to + 22, tmp);
_mm_storeu_si128((__m128i*)to + 23, tmp);
_mm_storeu_si128((__m128i*)to + 24, tmp);
_mm_storeu_si128((__m128i*)to + 25, tmp);
_mm_storeu_si128((__m128i*)to + 26, tmp);
_mm_storeu_si128((__m128i*)to + 27, tmp);
_mm_storeu_si128((__m128i*)to + 28, tmp);
_mm_storeu_si128((__m128i*)to + 29, tmp);
_mm_storeu_si128((__m128i*)to + 30, tmp);
_mm_storeu_si128((__m128i*)to + 31, tmp);
_mm_storeu_si128((__m128i*)to + 32, tmp);
_mm_storeu_si128((__m128i*)to + 33, tmp);
_mm_storeu_si128((__m128i*)to + 34, tmp);
_mm_storeu_si128((__m128i*)to + 35, tmp);
_mm_storeu_si128((__m128i*)to + 36, tmp);
_mm_storeu_si128((__m128i*)to + 37, tmp);
_mm_storeu_si128((__m128i*)to + 38, tmp);
_mm_storeu_si128((__m128i*)to + 39, tmp);
_mm_storeu_si128((__m128i*)to + 40, tmp);
_mm_storeu_si128((__m128i*)to + 41, tmp);
_mm_storeu_si128((__m128i*)to + 42, tmp);
_mm_storeu_si128((__m128i*)to + 43, tmp);
_mm_storeu_si128((__m128i*)to + 44, tmp);
_mm_storeu_si128((__m128i*)to + 45, tmp);
_mm_storeu_si128((__m128i*)to + 46, tmp);
_mm_storeu_si128((__m128i*)to + 47, tmp);
_mm_storeu_si128((__m128i*)to + 48, tmp);
_mm_storeu_si128((__m128i*)to + 49, tmp);
_mm_storeu_si128((__m128i*)to + 50, tmp);
_mm_storeu_si128((__m128i*)to + 51, tmp);
_mm_storeu_si128((__m128i*)to + 52, tmp);
_mm_storeu_si128((__m128i*)to + 53, tmp);
_mm_storeu_si128((__m128i*)to + 54, tmp);
_mm_storeu_si128((__m128i*)to + 55, tmp);
_mm_storeu_si128((__m128i*)to + 56, tmp);
_mm_storeu_si128((__m128i*)to + 57, tmp);
_mm_storeu_si128((__m128i*)to + 58, tmp);
_mm_storeu_si128((__m128i*)to + 59, tmp);
_mm_storeu_si128((__m128i*)to + 60, tmp);
_mm_storeu_si128((__m128i*)to + 61, tmp);
_mm_storeu_si128((__m128i*)to + 62, tmp);
_mm_storeu_si128((__m128i*)to + 63, tmp);
to += 256;
case 0x02:
tmp = _mm_loadu_si128((__m128i*)constants::static_mask_1);
_mm_storeu_si128((__m128i*)to, tmp);
_mm_storeu_si128((__m128i*)to + 1, tmp);
_mm_storeu_si128((__m128i*)to + 2, tmp);
_mm_storeu_si128((__m128i*)to + 3, tmp);
_mm_storeu_si128((__m128i*)to + 4, tmp);
_mm_storeu_si128((__m128i*)to + 5, tmp);
_mm_storeu_si128((__m128i*)to + 6, tmp);
_mm_storeu_si128((__m128i*)to + 7, tmp);
_mm_storeu_si128((__m128i*)to + 8, tmp);
_mm_storeu_si128((__m128i*)to + 9, tmp);
_mm_storeu_si128((__m128i*)to + 10, tmp);
_mm_storeu_si128((__m128i*)to + 11, tmp);
_mm_storeu_si128((__m128i*)to + 12, tmp);
_mm_storeu_si128((__m128i*)to + 13, tmp);
_mm_storeu_si128((__m128i*)to + 14, tmp);
_mm_storeu_si128((__m128i*)to + 15, tmp);
_mm_storeu_si128((__m128i*)to + 16, tmp);
_mm_storeu_si128((__m128i*)to + 17, tmp);
_mm_storeu_si128((__m128i*)to + 18, tmp);
_mm_storeu_si128((__m128i*)to + 19, tmp);
_mm_storeu_si128((__m128i*)to + 20, tmp);
_mm_storeu_si128((__m128i*)to + 21, tmp);
_mm_storeu_si128((__m128i*)to + 22, tmp);
_mm_storeu_si128((__m128i*)to + 23, tmp);
_mm_storeu_si128((__m128i*)to + 24, tmp);
_mm_storeu_si128((__m128i*)to + 25, tmp);
_mm_storeu_si128((__m128i*)to + 26, tmp);
_mm_storeu_si128((__m128i*)to + 27, tmp);
_mm_storeu_si128((__m128i*)to + 28, tmp);
_mm_storeu_si128((__m128i*)to + 29, tmp);
_mm_storeu_si128((__m128i*)to + 30, tmp);
_mm_storeu_si128((__m128i*)to + 31, tmp);
_mm_storeu_si128((__m128i*)to + 32, tmp);
_mm_storeu_si128((__m128i*)to + 33, tmp);
_mm_storeu_si128((__m128i*)to + 34, tmp);
_mm_storeu_si128((__m128i*)to + 35, tmp);
_mm_storeu_si128((__m128i*)to + 36, tmp);
_mm_storeu_si128((__m128i*)to + 37, tmp);
_mm_storeu_si128((__m128i*)to + 38, tmp);
_mm_storeu_si128((__m128i*)to + 39, tmp);
_mm_storeu_si128((__m128i*)to + 40, tmp);
_mm_storeu_si128((__m128i*)to + 41, tmp);
_mm_storeu_si128((__m128i*)to + 42, tmp);
_mm_storeu_si128((__m128i*)to + 43, tmp);
_mm_storeu_si128((__m128i*)to + 44, tmp);
_mm_storeu_si128((__m128i*)to + 45, tmp);
_mm_storeu_si128((__m128i*)to + 46, tmp);
_mm_storeu_si128((__m128i*)to + 47, tmp);
_mm_storeu_si128((__m128i*)to + 48, tmp);
_mm_storeu_si128((__m128i*)to + 49, tmp);
_mm_storeu_si128((__m128i*)to + 50, tmp);
_mm_storeu_si128((__m128i*)to + 51, tmp);
_mm_storeu_si128((__m128i*)to + 52, tmp);
_mm_storeu_si128((__m128i*)to + 53, tmp);
_mm_storeu_si128((__m128i*)to + 54, tmp);
_mm_storeu_si128((__m128i*)to + 55, tmp);
_mm_storeu_si128((__m128i*)to + 56, tmp);
_mm_storeu_si128((__m128i*)to + 57, tmp);
_mm_storeu_si128((__m128i*)to + 58, tmp);
_mm_storeu_si128((__m128i*)to + 59, tmp);
_mm_storeu_si128((__m128i*)to + 60, tmp);
_mm_storeu_si128((__m128i*)to + 61, tmp);
_mm_storeu_si128((__m128i*)to + 62, tmp);
_mm_storeu_si128((__m128i*)to + 63, tmp);
to += 256;
case 0x03:
tmp = _mm_loadu_si128((__m128i*)constants::static_mask_1);
_mm_storeu_si128((__m128i*)to, tmp);
_mm_storeu_si128((__m128i*)to + 1, tmp);
_mm_storeu_si128((__m128i*)to + 2, tmp);
_mm_storeu_si128((__m128i*)to + 3, tmp);
_mm_storeu_si128((__m128i*)to + 4, tmp);
_mm_storeu_si128((__m128i*)to + 5, tmp);
_mm_storeu_si128((__m128i*)to + 6, tmp);
_mm_storeu_si128((__m128i*)to + 7, tmp);
_mm_storeu_si128((__m128i*)to + 8, tmp);
_mm_storeu_si128((__m128i*)to + 9, tmp);
_mm_storeu_si128((__m128i*)to + 10, tmp);
_mm_storeu_si128((__m128i*)to + 11, tmp);
_mm_storeu_si128((__m128i*)to + 12, tmp);
_mm_storeu_si128((__m128i*)to + 13, tmp);
_mm_storeu_si128((__m128i*)to + 14, tmp);
_mm_storeu_si128((__m128i*)to + 15, tmp);
_mm_storeu_si128((__m128i*)to + 16, tmp);
_mm_storeu_si128((__m128i*)to + 17, tmp);
_mm_storeu_si128((__m128i*)to + 18, tmp);
_mm_storeu_si128((__m128i*)to + 19, tmp);
_mm_storeu_si128((__m128i*)to + 20, tmp);
_mm_storeu_si128((__m128i*)to + 21, tmp);
_mm_storeu_si128((__m128i*)to + 22, tmp);
_mm_storeu_si128((__m128i*)to + 23, tmp);
_mm_storeu_si128((__m128i*)to + 24, tmp);
_mm_storeu_si128((__m128i*)to + 25, tmp);
_mm_storeu_si128((__m128i*)to + 26, tmp);
_mm_storeu_si128((__m128i*)to + 27, tmp);
_mm_storeu_si128((__m128i*)to + 28, tmp);
_mm_storeu_si128((__m128i*)to + 29, tmp);
_mm_storeu_si128((__m128i*)to + 30, tmp);
_mm_storeu_si128((__m128i*)to + 31, tmp);
_mm_storeu_si128((__m128i*)to + 32, tmp);
_mm_storeu_si128((__m128i*)to + 33, tmp);
_mm_storeu_si128((__m128i*)to + 34, tmp);
_mm_storeu_si128((__m128i*)to + 35, tmp);
_mm_storeu_si128((__m128i*)to + 36, tmp);
_mm_storeu_si128((__m128i*)to + 37, tmp);
_mm_storeu_si128((__m128i*)to + 38, tmp);
_mm_storeu_si128((__m128i*)to + 39, tmp);
_mm_storeu_si128((__m128i*)to + 40, tmp);
_mm_storeu_si128((__m128i*)to + 41, tmp);
_mm_storeu_si128((__m128i*)to + 42, tmp);
_mm_storeu_si128((__m128i*)to + 43, tmp);
_mm_storeu_si128((__m128i*)to + 44, tmp);
_mm_storeu_si128((__m128i*)to + 45, tmp);
_mm_storeu_si128((__m128i*)to + 46, tmp);
_mm_storeu_si128((__m128i*)to + 47, tmp);
_mm_storeu_si128((__m128i*)to + 48, tmp);
_mm_storeu_si128((__m128i*)to + 49, tmp);
_mm_storeu_si128((__m128i*)to + 50, tmp);
_mm_storeu_si128((__m128i*)to + 51, tmp);
_mm_storeu_si128((__m128i*)to + 52, tmp);
_mm_storeu_si128((__m128i*)to + 53, tmp);
_mm_storeu_si128((__m128i*)to + 54, tmp);
_mm_storeu_si128((__m128i*)to + 55, tmp);
_mm_storeu_si128((__m128i*)to + 56, tmp);
_mm_storeu_si128((__m128i*)to + 57, tmp);
_mm_storeu_si128((__m128i*)to + 58, tmp);
_mm_storeu_si128((__m128i*)to + 59, tmp);
_mm_storeu_si128((__m128i*)to + 60, tmp);
_mm_storeu_si128((__m128i*)to + 61, tmp);
_mm_storeu_si128((__m128i*)to + 62, tmp);
_mm_storeu_si128((__m128i*)to + 63, tmp);
to += 256;
case 0x04:
tmp = _mm_loadu_si128((__m128i*)constants::static_mask_1);
_mm_storeu_si128((__m128i*)to, tmp);
_mm_storeu_si128((__m128i*)to + 1, tmp);
_mm_storeu_si128((__m128i*)to + 2, tmp);
_mm_storeu_si128((__m128i*)to + 3, tmp);
_mm_storeu_si128((__m128i*)to + 4, tmp);
_mm_storeu_si128((__m128i*)to + 5, tmp);
_mm_storeu_si128((__m128i*)to + 6, tmp);
_mm_storeu_si128((__m128i*)to + 7, tmp);
_mm_storeu_si128((__m128i*)to + 8, tmp);
_mm_storeu_si128((__m128i*)to + 9, tmp);
_mm_storeu_si128((__m128i*)to + 10, tmp);
_mm_storeu_si128((__m128i*)to + 11, tmp);
_mm_storeu_si128((__m128i*)to + 12, tmp);
_mm_storeu_si128((__m128i*)to + 13, tmp);
_mm_storeu_si128((__m128i*)to + 14, tmp);
_mm_storeu_si128((__m128i*)to + 15, tmp);
_mm_storeu_si128((__m128i*)to + 16, tmp);
_mm_storeu_si128((__m128i*)to + 17, tmp);
_mm_storeu_si128((__m128i*)to + 18, tmp);
_mm_storeu_si128((__m128i*)to + 19, tmp);
_mm_storeu_si128((__m128i*)to + 20, tmp);
_mm_storeu_si128((__m128i*)to + 21, tmp);
_mm_storeu_si128((__m128i*)to + 22, tmp);
_mm_storeu_si128((__m128i*)to + 23, tmp);
_mm_storeu_si128((__m128i*)to + 24, tmp);
_mm_storeu_si128((__m128i*)to + 25, tmp);
_mm_storeu_si128((__m128i*)to + 26, tmp);
_mm_storeu_si128((__m128i*)to + 27, tmp);
_mm_storeu_si128((__m128i*)to + 28, tmp);
_mm_storeu_si128((__m128i*)to + 29, tmp);
_mm_storeu_si128((__m128i*)to + 30, tmp);
_mm_storeu_si128((__m128i*)to + 31, tmp);
_mm_storeu_si128((__m128i*)to + 32, tmp);
_mm_storeu_si128((__m128i*)to + 33, tmp);
_mm_storeu_si128((__m128i*)to + 34, tmp);
_mm_storeu_si128((__m128i*)to + 35, tmp);
_mm_storeu_si128((__m128i*)to + 36, tmp);
_mm_storeu_si128((__m128i*)to + 37, tmp);
_mm_storeu_si128((__m128i*)to + 38, tmp);
_mm_storeu_si128((__m128i*)to + 39, tmp);
_mm_storeu_si128((__m128i*)to + 40, tmp);
_mm_storeu_si128((__m128i*)to + 41, tmp);
_mm_storeu_si128((__m128i*)to + 42, tmp);
_mm_storeu_si128((__m128i*)to + 43, tmp);
_mm_storeu_si128((__m128i*)to + 44, tmp);
_mm_storeu_si128((__m128i*)to + 45, tmp);
_mm_storeu_si128((__m128i*)to + 46, tmp);
_mm_storeu_si128((__m128i*)to + 47, tmp);
_mm_storeu_si128((__m128i*)to + 48, tmp);
_mm_storeu_si128((__m128i*)to + 49, tmp);
_mm_storeu_si128((__m128i*)to + 50, tmp);
_mm_storeu_si128((__m128i*)to + 51, tmp);
_mm_storeu_si128((__m128i*)to + 52, tmp);
_mm_storeu_si128((__m128i*)to + 53, tmp);
_mm_storeu_si128((__m128i*)to + 54, tmp);
_mm_storeu_si128((__m128i*)to + 55, tmp);
_mm_storeu_si128((__m128i*)to + 56, tmp);
_mm_storeu_si128((__m128i*)to + 57, tmp);
_mm_storeu_si128((__m128i*)to + 58, tmp);
_mm_storeu_si128((__m128i*)to + 59, tmp);
_mm_storeu_si128((__m128i*)to + 60, tmp);
_mm_storeu_si128((__m128i*)to + 61, tmp);
_mm_storeu_si128((__m128i*)to + 62, tmp);
_mm_storeu_si128((__m128i*)to + 63, tmp);
to += 256;
case 0x05:
tmp = _mm_loadu_si128((__m128i*)constants::static_mask_1);
_mm_storeu_si128((__m128i*)to, tmp);
_mm_storeu_si128((__m128i*)to + 1, tmp);
_mm_storeu_si128((__m128i*)to + 2, tmp);
_mm_storeu_si128((__m128i*)to + 3, tmp);
_mm_storeu_si128((__m128i*)to + 4, tmp);
_mm_storeu_si128((__m128i*)to + 5, tmp);
_mm_storeu_si128((__m128i*)to + 6, tmp);