-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
PMP_Multilinear_64_out_32.h
1590 lines (1368 loc) · 65.6 KB
/
PMP_Multilinear_64_out_32.h
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
/* -------------------------------------------------------------------------------
* Copyright (c) 2014, Dmytro Ivanchykhin, Sergey Ignatchenko, Daniel Lemire
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* -------------------------------------------------------------------------------
*
* PMP+-Multilinear hash family implementation
*
* v.1.00 Apr-14-2014 Initial release
*
* -------------------------------------------------------------------------------*/
// PMP_Multilinear64_out_32.h: implementtation of a 64-bit version with 32 bit output of PMP+-Multilinear hash family
#if !defined __PMP_MULTILINEAR_HASHER_64_OUT_32_H__
#define __PMP_MULTILINEAR_HASHER_64_OUT_32_H__
//#define __MULTILINEARPRIMESTRINGHASHFUNCTOR_CPP_H__REVISION_ "$Rev: 397 $" /* for automated version information update; could be removed, if not desired */
#if !defined __arm__
#if (defined _WIN64) || (defined __x86_64__)
#include "PMP_Multilinear_common.h"
#ifdef _MSC_VER
#define PMPML_CHUNK_OPTIMIZATION_TYPE 2 // 1 or 2 is recommended
//#define PMPML_MSC_32_WORKAROUND_64_OUT_32 // enables MSVC-specific code that appears to be more efficient than a regular one; comment out, if not desired
#else // _MSC_VER
#ifdef __arm__
#define PMPML_CHUNK_OPTIMIZATION_TYPE 1 // 1 is recommended
#else // __arm__
#ifdef __INTEL_COMPILER
#define PMPML_CHUNK_OPTIMIZATION_TYPE 1 // add64 function fails to build on some Intel compilers
#else
#define PMPML_CHUNK_OPTIMIZATION_TYPE 2 // 2 is recommended
#endif //__INTEL_COMPILER
#endif // __arm __
#endif // _MSC_VER
#ifdef __arm__
//#define PMPML_STRICT_UNALIGNED_HANDLING
#endif // __arm__
#if (PMPML_CHUNK_OPTIMIZATION_TYPE == 2)
#if defined(_MSC_VER)
#include <intrin.h>
#define MultiplyWordLoHi(p0,p1,a,b) p0 = _umul128((a),(b),&(p1));
FORCE_INLINE
void mul32x32to64addto96_x64(uint64_t lo, uint64_t hi, uint32_t a, uint32_t b )
{
uint64_t mul = a;
mul *= b;
_addcarry_u64(_addcarry_u64(0, lo, mul, &lo), hi, 0, &hi); \
}
FORCE_INLINE
void multiply32x32to64_x64(uint32_t& rhi, uint32_t& rlo, uint32_t a, uint32_t b)
{
ULARGE_INTEGER__XX mul;
mul.QuadPart = a * (uint64_t)b;
rhi = mul.HighPart;
rlo = mul.LowPart;
}
#define MULADD_MUL64x64to128ADDto128__( lo, hi, a, b ) { \
uint64_t mulLo, mulHi; \
MultiplyWordLoHi(mulLo, mulHi, a, b); \
unsigned char carry = 0; \
carry = _addcarry_u64(carry, lo, mulLo, &(lo)); \
carry = _addcarry_u64(carry, hi, mulHi, &(hi)); \
}
#else
FORCE_INLINE
void mul32x32to64addto96_x64(uint64_t& loCtr, uint64_t& hiCtr, uint32_t a, uint32_t b)
{
uint64_t dummy1, dummy2; /*Dummy variable to tell the compiler that the register rax is input and clobbered but not actually output; see assembler code below. Better syntactic expression is very welcome.*/
#ifdef __arm__
uint32_t rlo;
__asm("UMULL %3, %4, %5, %6\n"
"ADDS %0, %3, %0\n"
"ADCS %1, %4, %1\n"
"ADC %2, %2, #0x0"
: "+r" (loWord), "+r" (hiWord), "+r" (hhWord), "=r" (rlo), "=r" (rhi)
: "r" (a), "r" (b) : "cc" );
#else // __arm__
__asm__("imulq %%rcx\n"
"addq %%rax, %0\n"
"adcq $0, %1\n"
: "+g" (loCtr), "+g" (hiCtr), "=a" (dummy1), "=d" (dummy2)
:"a"(a), "c"(b) : "cc" );
#endif
}
FORCE_INLINE
void multiply32x32to64_x64(uint32_t& rhi, uint32_t& rlo, uint32_t a, uint32_t b)
{
#ifdef __arm__
__asm("UMULL %0, %1, %2, %3\n"
: "+r" (rlo), "+r" (rhi)
: "r" (a), "r" (b) : "cc", "memory" );
#else // __arm__
__asm__(
" mull %[b]\n"
:"=d"(rhi),"=a"(rlo)
:"1"(a),[b]"rm"(b));
#endif
}
#define MULADD_MUL64x64to128ADDto128__( lo, hi, a, b ) { \
uint64_t rhi; /*Dummy variable to tell the compiler that the register rax is input and clobbered but not actually output; see assembler code below. Better syntactic expression is very welcome.*/ \
__asm__( "mulq %4\n" \
"addq %%rax, %0\n" \
"adcq %%rdx, %1\n" \
: "+g" (lo), "+g" (hi), "=a" (rhi) \
:"a"(a), "g"(b) : "rdx", "cc" ); \
}
#endif
#define PMPML_CHUNK_LOOP_INTRO_L0_64_OUT_32 \
uint64_t ctr; \
ctr = 0; \
ULARGE_INTEGER__XX mul;
#ifdef _MSC_VER
#define PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( i ) \
{ \
uint64_t mul = coeff[i]; \
mul *= x[ i ]; \
unsigned char carry = _addcarry_u64( 0, constTerm.QuadPart, mul, &(constTerm.QuadPart)); \
_addcarry_u64(carry, ctr, 0, &(ctr)); \
}
#define PMPML_CHUNK_LOOP_BODY_ULI_T1_LAST_64_OUT_32 \
{\
uint64_t mul = coeff[size]; \
mul *= xLast; \
unsigned char carry = _addcarry_u64( 0, constTerm.QuadPart, mul, &(constTerm.QuadPart)); \
_addcarry_u64(carry, ctr, 0, &(ctr)); \
}
#define PMPML_CHUNK_LOOP_BODY_ULI_T1_LAST_FOR_JUST_1_64_OUT_32 \
{\
uint64_t _coeff = coeff[size]; \
_addcarry_u64(_addcarry_u64(0, constTerm.QuadPart, _coeff, &(constTerm.QuadPart)), ctr, 0, &ctr); \
}
#else // _MSC_VER
#define PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( i ) \
mul32x32to64addto96_x64(constTerm.QuadPart, ctr, x[i], coeff[ i ]); \
#define PMPML_CHUNK_LOOP_BODY_ULI_T1_LAST_64_OUT_32 \
mul32x32to64addto96_x64(constTerm.QuadPart, ctr, xLast, coeff[ size ]); \
#endif // _MSC_VER
#define PMPML_CHUNK_LOOP_PRE_REDUCE_L0
#define PMPML_CHUNK_REDUCE_96_TO_64
#define PMPML_CHUNK_REDUCE_64_TO_32_64_OUT_32 \
{ \
uint32_t lo, hi; \
multiply32x32to64_x64(hi, lo, constTerm.HighPart, 15); \
uint32_t part = ctr * 225 + (hi << 4) - hi + 15; \
constTerm.LowPart += part; \
constTerm.HighPart = 1 + (constTerm.LowPart < part); \
constTerm.HighPart -= (constTerm.LowPart < lo); \
constTerm.LowPart -= lo; \
if ( _LIKELY_BRANCH_( constTerm.LowPart >= 30) ) { constTerm.LowPart -= constTerm.HighPart * 15; constTerm.HighPart = 0; } \
else \
{ \
if ( constTerm.HighPart ) \
{ \
constTerm.LowPart -= constTerm.HighPart * 15; \
constTerm.HighPart = 1; \
if ( _LIKELY_BRANCH_( constTerm.LowPart >= 15)) { constTerm.LowPart -= 15; constTerm.HighPart = 0; } \
else \
{ \
constTerm.LowPart -= 15; \
constTerm.HighPart = 0; \
} \
} \
} \
}
#define PMPML_FULL_REDUCE_MOD_2_32_PLUS_15_AND_RETURN_64_OUT_32 \
PMPML_CHUNK_REDUCE_96_TO_64 \
PMPML_CHUNK_REDUCE_64_TO_32_64_OUT_32 \
return constTerm.QuadPart;
#define PMPML_FULL_REDUCE_MOD_2_32_PLUS_15_AND_RETURN_RETURN_32x32_ONLY_64_OUT_32 \
{ \
constTerm.QuadPart = constTerm.LowPart + PMPML_MAIN_PRIME - constTerm.HighPart * UINT64_C( 15 ); \
if ( _LIKELY_BRANCH_( constTerm.LowPart >= 30) ) { constTerm.LowPart -= (constTerm.HighPart << 4) - constTerm.HighPart; return fmix32_short( constTerm.LowPart ); } \
else \
{ \
constTerm.LowPart -= constTerm.HighPart * 15; \
if ( constTerm.LowPart < 30 ) return fmix32_short( constTerm.LowPart ); \
else \
{ \
constTerm.LowPart += 15; \
return fmix32_short( constTerm.LowPart ); \
} \
} \
}
#define PMPML_FULL_REDUCE_MOD_2_32_PLUS_15_AND_RETURN_RETURN_64_OUT_32 \
{ \
uint32_t lo, hi; \
multiply32x32to64_x64(hi, lo, constTerm.HighPart, 15); \
uint32_t part = ctr * 225 + (hi << 4) - hi + 15; \
constTerm.LowPart += part; \
constTerm.HighPart = 1 + (constTerm.LowPart < part); \
/*constTerm.HighPart -= (constTerm.LowPart < lo); \
constTerm.LowPart -= lo;*/ \
constTerm.QuadPart -= (uint64_t)lo; \
if ( _LIKELY_BRANCH_( constTerm.LowPart >= 30) ) { constTerm.LowPart -= (constTerm.HighPart << 4) - constTerm.HighPart/*constTerm.HighPart * 15*/; return fmix32_short( constTerm.LowPart ); } \
else \
{ \
if ( constTerm.HighPart ) \
{ \
constTerm.LowPart -= constTerm.HighPart * 15 - 15; \
constTerm.HighPart = 1; \
if ( _LIKELY_BRANCH_( constTerm.LowPart >= 15)) { constTerm.LowPart -= 15; return fmix32_short( constTerm.LowPart ); } \
else \
{ \
return constTerm.LowPart; \
} \
} \
else \
return fmix32_short( constTerm.LowPart ); \
} \
}
#endif
class PMP_Multilinear_Hasher_64_out_32
{
private:
random_data_for_MPSHF* curr_rd;
#ifdef PMPML_USE_SSE
const unsigned char* base_addr;
#endif
// calls to be done from LEVEL=0
FORCE_INLINE
uint64_t hash_of_string_chunk_compact( const uint32_t* coeff, ULARGE_INTEGER__XX constTerm, const uint32_t* x ) const
{
PMPML_CHUNK_LOOP_INTRO_L0_64_OUT_32
#ifdef PMPML_USE_SSE
#if PMPML_USE_SSE_SIZE == 128
__m128i ctr0, ctr1, mask_low;
__m128i a, data, product, temp;
uint64_t temp_fin;
int i;
ctr0 = _mm_setzero_si128 (); // Sets the 128-bit value to zero.
ctr1 = _mm_setzero_si128 ();
mask_low = _mm_set_epi32 ( 0, -1, 0 , -1 );
uint32_t *x1, *x2, *x3, *c1, *c2, *c3;
#if (PMPML_CHUNK_SIZE >= 64)
for ( i=0; i<PMPML_CHUNK_SIZE; i+=64 )
#elif (PMPML_CHUNK_SIZE >= 32)
for ( i=0; i<PMPML_CHUNK_SIZE; i+=32 )
#elif (PMPML_CHUNK_SIZE >= 16)
for ( i=0; i<PMPML_CHUNK_SIZE; i+=16 )
#elif (PMPML_CHUNK_SIZE >= 8)
for ( i=0; i<PMPML_CHUNK_SIZE; i+=8 )
#elif (PMPML_CHUNK_SIZE >= 4)
for ( i=0; i<PMPML_CHUNK_SIZE; i+=4 )
#else
#error PMPML_CHUNK_SIZE is incompatible with PMPML_USE_SSE option
#endif
{
a = _mm_load_si128 ((__m128i *)(coeff+i)); // Loads 128-bit value. Address p must be 16-byte aligned.
data = _mm_loadu_si128 ((__m128i *)(x+i)); // Loads 128-bit value. Address p does not need be 16-byte aligned.
product = _mm_mul_epu32 ( data, a); // A 128-bit value that contains two 64-bit unsigned integers. The result can be expressed by the following equations. r0 := a0 * b0; r1 := a2 * b2
temp = _mm_srli_epi64( product, 32 ); // Shifts the 2 signed or unsigned 64-bit integers in a right by count bits while shifting in zeros.
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
#if ( PMPML_CHUNK_SIZE > 4 )
a = _mm_load_si128 ((__m128i *)(coeff+i+4));
data = _mm_loadu_si128 ((__m128i *)(x+i+4));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
#endif // ( PMPML_CHUNK_SIZE > 4 )
#if ( PMPML_CHUNK_SIZE > 8 )
a = _mm_load_si128 ((__m128i *)(coeff+i+8));
data = _mm_loadu_si128 ((__m128i *)(x+i+8));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(coeff+i+12));
data = _mm_loadu_si128 ((__m128i *)(x+i+12));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
#endif // ( PMPML_CHUNK_SIZE > 8 )
#if ( PMPML_CHUNK_SIZE > 16 )
a = _mm_load_si128 ((__m128i *)(coeff+i+16));
data = _mm_loadu_si128 ((__m128i *)(x+i+16));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(coeff+i+20));
data = _mm_loadu_si128 ((__m128i *)(x+i+20));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(coeff+i+24));
data = _mm_loadu_si128 ((__m128i *)(x+i+24));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(coeff+i+28));
data = _mm_loadu_si128 ((__m128i *)(x+i+28));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
#endif // ( PMPML_CHUNK_SIZE > 16 )
#if ( PMPML_CHUNK_SIZE > 32 )
x1 = const_cast<uint32_t*>( x+i+36 );
x2 = const_cast<uint32_t*>( x+i+40 );
x3 = const_cast<uint32_t*>( x+i+44 );
c1 = const_cast<uint32_t*>( coeff+i+36 );
c2 = const_cast<uint32_t*>( coeff+i+40 );
c3 = const_cast<uint32_t*>( coeff+i+44 );
a = _mm_load_si128 ((__m128i *)(coeff+i+32));
data = _mm_loadu_si128 ((__m128i *)(x+i+32));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(c1));
data = _mm_loadu_si128 ((__m128i *)(x1));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(c2));
data = _mm_loadu_si128 ((__m128i *)(x2));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(c3));
data = _mm_loadu_si128 ((__m128i *)(x3));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
x1 = const_cast<uint32_t*>( x+i+52 );
x2 = const_cast<uint32_t*>( x+i+56 );
x3 = const_cast<uint32_t*>( x+i+60 );
c1 = const_cast<uint32_t*>( coeff+i+52 );
c2 = const_cast<uint32_t*>( coeff+i+56 );
c3 = const_cast<uint32_t*>( coeff+i+60 );
a = _mm_load_si128 ((__m128i *)(coeff+i+48));
data = _mm_loadu_si128 ((__m128i *)(x+i+48));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(c1));
data = _mm_loadu_si128 ((__m128i *)(x1));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(c2));
data = _mm_loadu_si128 ((__m128i *)(x2));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_load_si128 ((__m128i *)(c3));
data = _mm_loadu_si128 ((__m128i *)(x3));
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a);
temp = _mm_srli_epi64( product, 32 );
ctr1 = _mm_add_epi64 ( ctr1, temp );
//temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, product );//ctr0 = _mm_add_epi64 ( ctr0, temp );
#endif // ( PMPML_CHUNK_SIZE > 32 )
}
temp = _mm_unpackhi_epi64 ( ctr0, ctr1 ); // Interleaves the upper signed or unsigned 64-bit integer in a with the upper signed or unsigned 64-bit integer in b. r0 := a1 ; r1 := b1
data = _mm_unpacklo_epi64 ( ctr0, ctr1 ); // Interleaves the lower signed or unsigned 64-bit integer in a with the lower signed or unsigned 64-bit integer in b. r0 := a0 ; r1 := b0
ctr1 = _mm_add_epi64 ( data, temp );
#if (PMPML_CHUNK_OPTIMIZATION_TYPE== 2)
uint64_t lo = ((uint64_t*)(&ctr1))[0];
uint64_t hi = ((uint64_t*)(&ctr1))[1];
/* constTerm.QuadPart += lo;
ctr += constTerm.QuadPart < lo;
constTerm.HighPart += ((uint32_t*)(&ctr1))[2];
ctr += constTerm.HighPart < ((uint32_t*)(&ctr1))[2];
ctr += ((uint32_t*)(&ctr1))[3];*/
uint32_t lohi = lo >> 32;
uint32_t hilo = hi;
uint32_t diff = lohi - hilo;
hi += diff;
lo = (uint32_t)lo + (((uint64_t)(uint32_t)hi) << 32 );
constTerm.QuadPart += lo;
ctr += constTerm.QuadPart < lo;
ctr += hi >> 32;
#else
#error unexpected PMPML_CHUNK_OPTIMIZATION_TYPE
#endif
#elif PMPML_USE_SSE_SIZE == 256
__m256i ctr0, ctr1;
__m256i a, data, product, temp;
uint64_t temp_fin;
int i;
ctr0 = _mm256_setzero_si256 (); // Sets the 128-bit value to zero.
ctr1 = _mm256_setzero_si256 ();
uint32_t *x1, *x2, *x3, *c1, *c2, *c3;
#if (PMPML_CHUNK_SIZE >= 64)
for ( i=0; i<PMPML_CHUNK_SIZE; i+=64 )
#elif (PMPML_CHUNK_SIZE >= 32)
for ( i=0; i<PMPML_CHUNK_SIZE; i+=32 )
#elif (PMPML_CHUNK_SIZE >= 16)
for ( i=0; i<PMPML_CHUNK_SIZE; i+=16 )
#elif (PMPML_CHUNK_SIZE >= 8)
for ( i=0; i<PMPML_CHUNK_SIZE; i+=8 )
#else
#error PMPML_CHUNK_SIZE is incompatible with PMPML_USE_SSE option
#endif
{
a = _mm256_load_si256 ((__m256i *)(coeff+i)); // Loads 256-bit value. Address p must be 32-byte aligned.
data = _mm256_loadu_si256 ((__m256i *)(x+i)); // Loads 256-bit value. Address p does not need be 32-byte aligned.
product = _mm256_mul_epu32 ( data, a); // A 256-bit value that contains four 64-bit unsigned integers. The result can be expressed by the following equations. r0 := a0 * b0; r1 := a2 * b2; ...
temp = _mm256_srli_epi64( product, 32 ); // Shifts the 4 signed or unsigned 64-bit integers in a right by count bits while shifting in zeros.
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm256_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
#if ( PMPML_CHUNK_SIZE > 8 )
a = _mm256_load_si256 ((__m256i *)(coeff+i+8));
data = _mm256_loadu_si256 ((__m256i *)(x+i+8));
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm256_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
#endif // ( PMPML_CHUNK_SIZE > 8 )
#if ( PMPML_CHUNK_SIZE > 16 )
a = _mm256_load_si256 ((__m256i *)(coeff+i+16));
data = _mm256_loadu_si256 ((__m256i *)(x+i+16));
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm256_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_load_si256 ((__m256i *)(coeff+i+24));
data = _mm256_loadu_si256 ((__m256i *)(x+i+24));
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm256_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
#endif // ( PMPML_CHUNK_SIZE > 16 )
#if ( PMPML_CHUNK_SIZE > 32 )
a = _mm256_load_si256 ((__m256i *)(coeff+i+32));
data = _mm256_loadu_si256 ((__m256i *)(x+i+32));
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm256_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_load_si256 ((__m256i *)(coeff+i+40));
data = _mm256_loadu_si256 ((__m256i *)(x+i+40));
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm256_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_load_si256 ((__m256i *)(coeff+i+48));
data = _mm256_loadu_si256 ((__m256i *)(x+i+48));
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm256_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_load_si256 ((__m256i *)(coeff+i+56));
data = _mm256_loadu_si256 ((__m256i *)(x+i+56));
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm256_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
#endif // ( PMPML_CHUNK_SIZE > 32 )
}
temp = _mm256_unpackhi_epi64 ( ctr0, ctr1 ); // Interleaves the upper signed or unsigned 64-bit integer in a with the upper signed or unsigned 64-bit integer in b. r0 := a1 ; r1 := b1 ; ...
data = _mm256_unpacklo_epi64 ( ctr0, ctr1 ); // Interleaves the lower signed or unsigned 64-bit integer in a with the lower signed or unsigned 64-bit integer in b. r0 := a0 ; r1 := b0 ; ...
ctr1 = _mm256_add_epi64 ( data, temp );
#if (PMPML_CHUNK_OPTIMIZATION_TYPE== 2)
uint64_t lo = *(uint64_t*)(&ctr1) + ((uint64_t*)(&ctr1))[2];
uint64_t hi = ((uint64_t*)(&ctr1))[1] + ((uint64_t*)(&ctr1))[3];
uint32_t lohi = lo >> 32;
uint32_t hilo = hi;
uint32_t diff = lohi - hilo;
hi += diff;
lo = (uint32_t)lo + (((uint64_t)(uint32_t)hi) << 32 );
constTerm.QuadPart += lo;
ctr += constTerm.QuadPart < lo;
ctr += hi >> 32;
#else
#error unexpected PMPML_CHUNK_OPTIMIZATION_TYPE
#endif
#else
#error unsupported PMPML_USE_SSE_SIZE value
#endif
#else //PMPML_USE_SSE
for ( uint32_t i=0; i<PMPML_CHUNK_SIZE; i+=8 )
{
PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 0 + i )
PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 1 + i )
PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 2 + i )
PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 3 + i )
#if ( PMPML_CHUNK_SIZE > 4 )
PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 4 + i )
PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 5 + i )
PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 6 + i )
PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 7 + i )
#endif
}
#endif // PMPML_USE_SSE
PMPML_CHUNK_LOOP_PRE_REDUCE_L0
PMPML_FULL_REDUCE_MOD_2_32_PLUS_15_AND_RETURN_64_OUT_32
}
FORCE_INLINE
uint64_t hash_of_beginning_of_string_chunk_type2( const uint32_t* coeff, ULARGE_INTEGER__XX constTerm, const unsigned char* tail, unsigned int tail_size ) const
{
PMPML_CHUNK_LOOP_INTRO_L0_64_OUT_32
#if 1
if ( tail_size < 4 )
{
uint32_t xLast;
uint32_t size = 0;
switch ( tail_size )
{
case 0: { xLast = 0x1; break;}
case 1: { xLast = 0x100 | tail[tail_size-1]; break;}
case 2: { xLast = *((const unsigned short*)(tail + tail_size - 2 )) | 0x10000; break; }
case 3: { xLast = tail[ tail_size - 1 ]; xLast = ( xLast << 16 ) | *((const unsigned short*)(tail + tail_size - 3 )) | 0x1000000; break;}
}
PMPML_CHUNK_LOOP_BODY_ULI_T1_LAST_64_OUT_32
PMPML_CHUNK_LOOP_PRE_REDUCE_L0
PMPML_FULL_REDUCE_MOD_2_32_PLUS_15_AND_RETURN_64_OUT_32
}
#endif // 0
uint32_t size = tail_size >> PMPML_WORD_SIZE_BYTES_LOG2;
const uint32_t* x = (const uint32_t*)tail;
#if 0
if ( tail_size < 32 )
{
uint32_t offset = size & 0xFFFFFFF8;
switch( size & 0x7 )
{
case 0: { break; }
case 1: { PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 0 + offset ) } break;
case 2: { PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 0 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 1 + offset ) } break;
case 3: { PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 0 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 1 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 2 + offset ) } break;
case 4: { PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 0 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 1 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 2 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 3 + offset ) } break;
case 5: { PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 0 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 1 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 2 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 3 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 4 + offset ) } break;
case 6: { PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 0 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 1 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 2 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 3 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 4 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 5 + offset ) } break;
case 7: { PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 0 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 1 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 2 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 3 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 4 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 5 + offset ) PMPML_CHUNK_LOOP_BODY_ULI_T1_64_OUT_32( 6 + offset ) } break;
}
uint32_t xLast;
switch ( tail_size & ( PMPML_WORD_SIZE_BYTES - 1 ) )
{
case 0: { xLast = 0x1; break;}
case 1: { xLast = 0x100 | tail[tail_size-1]; break;}
case 2: { xLast = *((const unsigned short*)(tail + tail_size - 2 )) | 0x10000; break; }
case 3: { xLast = tail[ tail_size - 1 ]; xLast = ( xLast << 16 ) | *((const unsigned short*)(tail + tail_size - 3 )) | 0x1000000; break;}
}
PMPML_CHUNK_LOOP_BODY_ULI_T1_LAST_64_OUT_32
PMPML_CHUNK_LOOP_PRE_REDUCE_L0
PMPML_FULL_REDUCE_MOD_2_32_PLUS_15_AND_RETURN_64_OUT_32
}
#endif // 0
#ifdef PMPML_USE_SSE
if ( size >= 8 )
{
#if PMPML_USE_SSE_SIZE == 128
__m128i ctr0, ctr1, a, data, product, temp, mask_low;
int i;
ctr0 = _mm_setzero_si128 (); // Sets the 128-bit value to zero.
ctr1 = _mm_setzero_si128 ();
mask_low = _mm_set_epi32 ( 0, -1, 0 , -1 );
for ( i=0; i<(size&0xFFFFFFF8); i+=4 )
{
a = _mm_load_si128 ((__m128i *)(coeff+i)); // Loads 128-bit value. Address p must be 16-byte aligned.
data = _mm_loadu_si128 ((__m128i *)(x+i)); // Loads 128-bit value. Address p does not need be 16-byte aligned.
product = _mm_mul_epu32 ( data, a); // A 128-bit value that contains two 64-bit unsigned integers. The result can be expressed by the following equations. r0 := a0 * b0; r1 := a2 * b2
temp = _mm_srli_epi64( product, 32 ); // Shifts the 2 signed or unsigned 64-bit integers in a right by count bits while shifting in zeros.
ctr1 = _mm_add_epi64 ( ctr1, temp );
temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, temp );
// a = _mm_srli_epi64 ( a, 32 );
// data = _mm_srli_epi64 ( data, 32 );
a = _mm_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm_mul_epu32 ( data, a); // A 128-bit value that contains two 64-bit unsigned integers. The result can be expressed by the following equations. r0 := a0 * b0; r1 := a2 * b2
temp = _mm_srli_epi64( product, 32 ); // Shifts the 2 signed or unsigned 64-bit integers in a right by count bits while shifting in zeros.
ctr1 = _mm_add_epi64 ( ctr1, temp );
temp = _mm_and_si128 ( mask_low, product );
ctr0 = _mm_add_epi64 ( ctr0, temp );
}
temp = _mm_unpackhi_epi64 ( ctr0, ctr1 ); // Interleaves the upper signed or unsigned 64-bit integer in a with the upper signed or unsigned 64-bit integer in b. r0 := a1 ; r1 := b1
data = _mm_unpacklo_epi64 ( ctr0, ctr1 ); // Interleaves the lower signed or unsigned 64-bit integer in a with the lower signed or unsigned 64-bit integer in b. r0 := a0 ; r1 := b0
ctr1 = _mm_add_epi64 ( data, temp );
#if (PMPML_CHUNK_OPTIMIZATION_TYPE== 1)
#if defined(_MSC_VER)
constTerm.QuadPart += ctr1.m128i_u32[0]; // Microsoft specific
ctr.QuadPart += ctr1.m128i_u64[1] + ctr1.m128i_u32[1];
#elif defined( __SSE4_1__)
constTer.QuadPart += _mm_extract_epi32(ctr1,0);
ctr.QuadPart += _mm_extract_epi64(ctr1,0) + _mm_extract_epi32(ctr1,1);
#else
uint32_t b[4];
_mm_storeu_si128((__m128i *)b,ctr1);
constTerm.QuadPart += b[0];
ctr.QuadPart += b[1] + b[2] + ((uint64_t) b[3] <<32);
#endif
#elif (PMPML_CHUNK_OPTIMIZATION_TYPE== 2)
constTerm.QuadPart += *(uint64_t*)(&ctr1);
ctr += constTerm.QuadPart < *(uint64_t*)(&ctr1);
constTerm.HighPart += ((uint32_t*)(&ctr1))[2];
ctr += constTerm.HighPart < ((uint32_t*)(&ctr1))[2];
ctr += ((uint32_t*)(&ctr1))[3];
#else
#error unxpected PMPML_CHUNK_OPTIMIZATION_TYPE
#endif
#elif PMPML_USE_SSE_SIZE == 256
__m256i ctr0, ctr1, mask_low;
__m256i a, data, product, temp;
uint64_t temp_fin;
int i;
ctr0 = _mm256_setzero_si256 (); // Sets the 128-bit value to zero.
ctr1 = _mm256_setzero_si256 ();
mask_low = _mm256_set_epi32 ( 0, -1, 0 , -1, 0, -1, 0 , -1 );
uint32_t *x1, *x2, *x3, *c1, *c2, *c3;
for ( i=0; i<(size&0xFFFFFFF8); i+=8 )
{
a = _mm256_load_si256 ((__m256i *)(coeff+i)); // Loads 256-bit value. Address p must be 32-byte aligned.
data = _mm256_loadu_si256 ((__m256i *)(x+i)); // Loads 256-bit value. Address p does not need be 32-byte aligned.
product = _mm256_mul_epu32 ( data, a); // A 256-bit value that contains four 64-bit unsigned integers. The result can be expressed by the following equations. r0 := a0 * b0; r1 := a2 * b2; ...
temp = _mm256_srli_epi64( product, 32 ); // Shifts the 4 signed or unsigned 64-bit integers in a right by count bits while shifting in zeros.
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
a = _mm256_shuffle_epi32( a, 1*1+0*4+3*16+2*64 );
data = _mm256_shuffle_epi32( data, 1*1+0*4+3*16+2*64 );
product = _mm256_mul_epu32 ( data, a);
temp = _mm256_srli_epi64( product, 32 );
ctr1 = _mm256_add_epi64 ( ctr1, temp );
//temp = _mm256_and_si256 ( mask_low, product );
ctr0 = _mm256_add_epi64 ( ctr0, product );//ctr0 = _mm256_add_epi64 ( ctr0, temp );
}
temp = _mm256_unpackhi_epi64 ( ctr0, ctr1 ); // Interleaves the upper signed or unsigned 64-bit integer in a with the upper signed or unsigned 64-bit integer in b. r0 := a1 ; r1 := b1 ; ...
data = _mm256_unpacklo_epi64 ( ctr0, ctr1 ); // Interleaves the lower signed or unsigned 64-bit integer in a with the lower signed or unsigned 64-bit integer in b. r0 := a0 ; r1 := b0 ; ...
ctr1 = _mm256_add_epi64 ( data, temp );
#if (PMPML_CHUNK_OPTIMIZATION_TYPE== 2)
uint64_t lo = *(uint64_t*)(&ctr1) + ((uint64_t*)(&ctr1))[2];
uint64_t hi = ((uint64_t*)(&ctr1))[1] + ((uint64_t*)(&ctr1))[3];
uint32_t lohi = lo >> 32;
uint32_t hilo = hi;
uint32_t diff = lohi - hilo;
hi += diff;
lo = (uint32_t)lo + (((uint64_t)(uint32_t)hi) << 32 );
constTerm.QuadPart += lo;
ctr += constTerm.QuadPart < lo;