-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathkernel.cl
3455 lines (2984 loc) · 114 KB
/
kernel.cl
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
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
#include "sha256.h"
#include "fmt.h"
#pragma OPENCL EXTENSION cl_amd_printf : enable
// You must define this parameters through compiler command line
// #define FixedPrimorial 19
// #define L1CacheSize (16384)
// #define WeaveDepth (6144+256)
// #define GroupSize (256)
// #define ExtensionsNum (9)
// #define ChainLength (10)
// #define FixedRoundsNum (80)
#define GPUMultiprecisionLimbs (12)
#define MaxRoundsNum (256)
#define MaxChainLength (20)
//#define MaxWeaveDepth (6144+256)
#define MaxSieveSize (L1CacheSize*MaxRoundsNum)
#define MaxSieveBufferSize (MaxSieveSize*(ExtensionsNum+1))
//#define MaxMultipliersBufferSize ((MaxChainLength+ExtensionsNum)*MaxWeaveDepth)
#define FixedSieveSize (FixedRoundsNum*L1CacheSize)
#define FirstLargePrimeIndex (2048)
__constant uint32_t binvert_limb_table[128] = {
0x01, 0xAB, 0xCD, 0xB7, 0x39, 0xA3, 0xC5, 0xEF,
0xF1, 0x1B, 0x3D, 0xA7, 0x29, 0x13, 0x35, 0xDF,
0xE1, 0x8B, 0xAD, 0x97, 0x19, 0x83, 0xA5, 0xCF,
0xD1, 0xFB, 0x1D, 0x87, 0x09, 0xF3, 0x15, 0xBF,
0xC1, 0x6B, 0x8D, 0x77, 0xF9, 0x63, 0x85, 0xAF,
0xB1, 0xDB, 0xFD, 0x67, 0xE9, 0xD3, 0xF5, 0x9F,
0xA1, 0x4B, 0x6D, 0x57, 0xD9, 0x43, 0x65, 0x8F,
0x91, 0xBB, 0xDD, 0x47, 0xC9, 0xB3, 0xD5, 0x7F,
0x81, 0x2B, 0x4D, 0x37, 0xB9, 0x23, 0x45, 0x6F,
0x71, 0x9B, 0xBD, 0x27, 0xA9, 0x93, 0xB5, 0x5F,
0x61, 0x0B, 0x2D, 0x17, 0x99, 0x03, 0x25, 0x4F,
0x51, 0x7B, 0x9D, 0x07, 0x89, 0x73, 0x95, 0x3F,
0x41, 0xEB, 0x0D, 0xF7, 0x79, 0xE3, 0x05, 0x2F,
0x31, 0x5B, 0x7D, 0xE7, 0x69, 0x53, 0x75, 0x1F,
0x21, 0xCB, 0xED, 0xD7, 0x59, 0xC3, 0xE5, 0x0F,
0x11, 0x3B, 0x5D, 0xC7, 0x49, 0x33, 0x55, 0xFF
};
void dbgPrint_v4(uint4 Reg)
{
printf("%08X %08X %08X %08X ", Reg.x, Reg.y, Reg.z, Reg.w);
}
// Taking a modulo of long integer to 32-bit integer
#define longModuloByMulRound(mod, number, inversedMultiplier, shift) {\
uint64_t dividend = (mod << 32) + number;\
uint64_t quotient = mul_hi(dividend, inversedMultiplier) >> shift;\
mod = dividend - quotient*divisor;\
}
uint32_t longModuloByMul256(uint4 nl0, uint4 nl1,
uint32_t divisor,
uint64_t inversedMultiplier,
uint32_t shift)
{
uint64_t mod = 0;
longModuloByMulRound(mod, nl1.w, inversedMultiplier, shift);
longModuloByMulRound(mod, nl1.z, inversedMultiplier, shift);
longModuloByMulRound(mod, nl1.y, inversedMultiplier, shift);
longModuloByMulRound(mod, nl1.x, inversedMultiplier, shift);
longModuloByMulRound(mod, nl0.w, inversedMultiplier, shift);
longModuloByMulRound(mod, nl0.z, inversedMultiplier, shift);
longModuloByMulRound(mod, nl0.y, inversedMultiplier, shift);
longModuloByMulRound(mod, nl0.x, inversedMultiplier, shift);
return mod;
}
uint32_t longModuloByMul384(uint4 nl0, uint4 nl1, uint4 nl2,
uint32_t divisor,
uint64_t inversedMultiplier,
uint32_t shift)
{
uint64_t mod = 0;
longModuloByMulRound(mod, nl2.w, inversedMultiplier, shift);
longModuloByMulRound(mod, nl2.z, inversedMultiplier, shift);
longModuloByMulRound(mod, nl2.y, inversedMultiplier, shift);
longModuloByMulRound(mod, nl2.x, inversedMultiplier, shift);
longModuloByMulRound(mod, nl1.w, inversedMultiplier, shift);
longModuloByMulRound(mod, nl1.z, inversedMultiplier, shift);
longModuloByMulRound(mod, nl1.y, inversedMultiplier, shift);
longModuloByMulRound(mod, nl1.x, inversedMultiplier, shift);
longModuloByMulRound(mod, nl0.w, inversedMultiplier, shift);
longModuloByMulRound(mod, nl0.z, inversedMultiplier, shift);
longModuloByMulRound(mod, nl0.y, inversedMultiplier, shift);
longModuloByMulRound(mod, nl0.x, inversedMultiplier, shift);
return mod;
}
// Extended Euclidian algorithm
uint32_t intInvert(uint32_t a, uint32_t mod)
{
uint32_t rem0 = mod, rem1 = a % mod, rem2;
uint32_t aux0 = 0, aux1 = 1, aux2;
uint32_t quotient, inverse;
while (1) {
if (rem1 <= 1) {
inverse = aux1;
break;
}
rem2 = rem0 % rem1;
quotient = rem0 / rem1;
aux2 = -quotient * aux1 + aux0;
if (rem2 <= 1) {
inverse = aux2;
break;
}
rem0 = rem1 % rem2;
quotient = rem1 / rem2;
aux0 = -quotient * aux2 + aux1;
if (rem0 <= 1) {
inverse = aux0;
break;
}
rem1 = rem2 % rem0;
quotient = rem2 / rem0;
aux1 = -quotient * aux0 + aux2;
}
return (inverse + mod) % mod;
}
unsigned int calculateOffset(unsigned int currentPrime,
unsigned int currentPrimeMod,
unsigned int offset)
{
return offset >= currentPrimeMod ?
offset - currentPrimeMod : currentPrime + offset - currentPrimeMod;
}
void clFillMemoryByGroup(__global void *buffer, unsigned size)
{
__global uint32_t *ptr32 = (__global uint32_t*)buffer;
for (unsigned i = get_local_id(0); i < size/4; i += GroupSize)
ptr32[i] = 0xFFFFFFFF;
}
void flushLayer(unsigned layer,
__global uint8 *cunningham1,
__global uint8 *cunningham2,
__global uint8 *bitwin,
uint8 CR1,
uint8 CR2,
unsigned threadId)
{
if (layer < ChainLength/2) {
cunningham1[threadId] &= CR1;
cunningham2[threadId] &= CR2;
CR1 &= CR2;
bitwin[threadId] &= CR1;
} else if (layer < (ChainLength + 1)/2) {
cunningham1[threadId] &= CR1;
cunningham2[threadId] &= CR2;
bitwin[threadId] &= CR1;
} else if (layer < ChainLength) {
cunningham1[threadId] &= CR1;
cunningham2[threadId] &= CR2;
}
}
// GPU weave procedure. For understanding, look first to CSieveOfEratosthenesL1Ext
void weave(uint4 M0, uint4 M1, uint4 M2,
__global uint32_t *cunningham1Bitfield,
__global uint32_t *cunningham2Bitfield,
__global uint32_t *bitwinBitfield,
__local uint8_t *localCunningham1,
__local uint8_t *localCunningham2,
__constant uint32_t *primes,
__global uint64_t *multipliers64,
__global uint32_t *offsets64,
unsigned roundsNum)
{
const unsigned primesPerThread = WeaveDepth / GroupSize;
const unsigned layersNum = ChainLength + ExtensionsNum;
const unsigned threadId = get_local_id(0);
unsigned sieveBytes = L1CacheSize * roundsNum / 8;
unsigned sieveWords = sieveBytes / 4;
uint32_t inverseModulos[256]; // <--- large buffer for global memory placing
uint32_t inverseModulosCurrent[WeaveDepth / GroupSize];
// Set all bits of output buffers to 1
clFillMemoryByGroup(cunningham1Bitfield, sieveBytes);
clFillMemoryByGroup(cunningham2Bitfield, sieveBytes);
clFillMemoryByGroup(bitwinBitfield, sieveBytes);
for (unsigned extNum = 1; extNum <= ExtensionsNum; extNum++) {
clFillMemoryByGroup(cunningham1Bitfield + extNum*sieveWords + sieveWords/2, sieveBytes/2);
clFillMemoryByGroup(cunningham2Bitfield + extNum*sieveWords + sieveWords/2, sieveBytes/2);
clFillMemoryByGroup(bitwinBitfield + extNum*sieveWords + sieveWords/2, sieveBytes/2);
}
unsigned primeIdx = FixedPrimorial+threadId;
for (unsigned j = 0; j < WeaveDepth/get_local_size(0); j++, primeIdx += GroupSize) {
unsigned currentPrime = primes[primeIdx];
unsigned mod = longModuloByMul384(M0, M1, M2,
currentPrime,
multipliers64[primeIdx],
offsets64[primeIdx]);
inverseModulos[j] = intInvert(mod, currentPrime);
}
const unsigned L1CacheWords = L1CacheSize/4;
__local uint32_t *localCunningham1_32 = (__local uint32_t*)localCunningham1;
__local uint32_t *localCunningham2_32 = (__local uint32_t*)localCunningham2;
for (unsigned round = 0; round < roundsNum; round += 8) {
unsigned lowIdx = L1CacheSize * round;
for (unsigned i = 0; i < primesPerThread; i++)
inverseModulosCurrent[i] = inverseModulos[i];
for (unsigned layer = 0; layer < layersNum; layer++) {
if (layer >= ChainLength && round < roundsNum/2)
break;
barrier(CLK_LOCAL_MEM_FENCE);
for (unsigned i = 0, index = get_local_id(0); i < L1CacheWords/GroupSize; i++, index += GroupSize) {
uint32_t X = 0xFFFFFFFF;
localCunningham1_32[index] = X;
localCunningham2_32[index] = X;
}
unsigned primeIdx;
for (unsigned j = 0, primeIdx = FixedPrimorial+threadId; j < FirstLargePrimeIndex/get_local_size(0); j++, primeIdx += GroupSize) {
unsigned offset;
unsigned offset2;
const uint32_t currentPrime = primes[primeIdx];
const uint32_t inverseModulo = inverseModulosCurrent[j];
const uint32_t currentPrimeMod = lowIdx % currentPrime;
offset = calculateOffset(currentPrime, currentPrimeMod, inverseModulo);
offset2 = calculateOffset(currentPrime, currentPrimeMod, currentPrime - inverseModulo);
for (unsigned iter = 0; iter < 8; iter++) {
barrier(CLK_LOCAL_MEM_FENCE);
uint8_t fill = ~(1 << iter);
unsigned maxOffset = max(offset, offset2);
while (maxOffset < L1CacheSize) {
localCunningham1[offset] &= fill;
localCunningham2[offset2] &= fill;
offset += currentPrime;
offset2 += currentPrime;
maxOffset += currentPrime;
}
if (offset < L1CacheSize) {
localCunningham1[offset] &= fill;
offset += currentPrime;
}
if (offset2 < L1CacheSize) {
localCunningham2[offset2] &= fill;
offset2 += currentPrime;
}
offset -= L1CacheSize;
offset2 -= L1CacheSize;
}
inverseModulosCurrent[j] = (inverseModulo & 0x1) ?
(inverseModulo + currentPrime) / 2 : inverseModulo / 2;
}
for (unsigned j = FirstLargePrimeIndex/GroupSize,
primeIdx = FirstLargePrimeIndex+FixedPrimorial+threadId;
j < primesPerThread;
j++, primeIdx += GroupSize) {
const uint32_t currentPrime = primes[primeIdx];
const uint32_t currentPrimeMod = lowIdx % currentPrime;
const uint32_t inverseModulo = inverseModulosCurrent[j];
unsigned offset = calculateOffset(currentPrime, currentPrimeMod, inverseModulo);
unsigned offset2 = calculateOffset(currentPrime, currentPrimeMod, currentPrime - inverseModulo);
for (unsigned iter = 0; iter < 8; iter++) {
uint8_t fill = ~(1 << iter);
if (offset < L1CacheSize) {
localCunningham1[offset] &= fill;
offset += currentPrime;
}
if (offset2 < L1CacheSize) {
localCunningham2[offset2] &= fill;
offset2 += currentPrime;
}
offset -= L1CacheSize;
offset2 -= L1CacheSize;
}
inverseModulosCurrent[j] = (inverseModulo & 0x1) ?
(inverseModulo + currentPrime) / 2 : inverseModulo / 2;
}
barrier(CLK_LOCAL_MEM_FENCE);
// Flush window to "main" range
__global uint32_t *cunningham1 = cunningham1Bitfield + lowIdx/32;
__global uint32_t *cunningham2 = cunningham2Bitfield + lowIdx/32;
__global uint32_t *bitwin = bitwinBitfield + lowIdx/32;
uint8 CR1 = vload8(threadId, localCunningham1_32);
uint8 CR2 = vload8(threadId, localCunningham2_32);
flushLayer(layer, cunningham1, cunningham2, bitwin, CR1, CR2, threadId);
// Flush window to extensions
if (round < roundsNum/2)
continue;
unsigned extNumMin = layer < ChainLength ? 1 : layer - ChainLength + 1;
unsigned extNumMax = layer < ExtensionsNum ? layer : ExtensionsNum;
for (unsigned extNum = extNumMin; extNum <= extNumMax; extNum++) {
__global uint32_t *extCunningham1 = cunningham1Bitfield + extNum*sieveWords + lowIdx/32;
__global uint32_t *extCunningham2 = cunningham2Bitfield + extNum*sieveWords + lowIdx/32;
__global uint32_t *extBitwin = bitwinBitfield + extNum*sieveWords + lowIdx/32;
flushLayer(layer - extNum, extCunningham1, extCunningham2, extBitwin, CR1, CR2, threadId);
}
}
}
}
__kernel void sieveBenchmark(__global uint32_t *fixedMultipliers,
__global uint32_t *cunningham1Bitfield,
__global uint32_t *cunningham2Bitfield,
__global uint32_t *bitwinBitfield,
__constant uint32_t *primes,
__global uint64_t *multipliers64,
__global uint32_t *offsets64,
unsigned roundsNum)
{
__local uint8_t localCunningham1[L1CacheSize];
__local uint8_t localCunningham2[L1CacheSize];
__global uint4 *M = (__global uint4*)(fixedMultipliers + get_group_id(0) * GPUMultiprecisionLimbs);
weave(M[0], M[1], M[2],
cunningham1Bitfield + get_group_id(0) * MaxSieveBufferSize/32,
cunningham2Bitfield + get_group_id(0) * MaxSieveBufferSize/32,
bitwinBitfield + get_group_id(0) * MaxSieveBufferSize/32,
localCunningham1,
localCunningham2,
primes,
multipliers64,
offsets64,
roundsNum);
return;
}
uint32_t add128(uint4 *A, uint4 B)
{
*A += B;
uint4 carry = -convert_uint4((*A) < B);
(*A).y += carry.x; carry.y += ((*A).y < carry.x);
(*A).z += carry.y; carry.z += ((*A).z < carry.y);
(*A).w += carry.z;
return carry.w + ((*A).w < carry.z);
}
uint32_t add128Carry(uint4 *A, uint4 B, uint32_t externalCarry)
{
*A += B;
uint4 carry = -convert_uint4((*A) < B);
(*A).x += externalCarry; carry.x += ((*A).x < externalCarry);
(*A).y += carry.x; carry.y += ((*A).y < carry.x);
(*A).z += carry.y; carry.z += ((*A).z < carry.y);
(*A).w += carry.z;
return carry.w + ((*A).w < carry.z);
}
uint32_t add256(uint4 *a0, uint4 *a1, uint4 b0, uint4 b1)
{
return add128Carry(a1, b1, add128(a0, b0));
}
uint32_t add384(uint4 *a0, uint4 *a1, uint4 *a2, uint4 b0, uint4 b1, uint4 b2)
{
return add128Carry(a2, b2, add128Carry(a1, b1, add128(a0, b0)));
}
uint32_t add512(uint4 *a0, uint4 *a1, uint4 *a2, uint4 *a3, uint4 b0, uint4 b1, uint4 b2, uint4 b3)
{
return add128Carry(a3, b3, add128Carry(a2, b2, add128Carry(a1, b1, add128(a0, b0))));
}
uint32_t sub64Borrow(uint2 *A, uint2 B, uint32_t externalBorrow)
{
uint2 borrow = -convert_uint2((*A) < B);
*A -= B;
borrow.x += (*A).x < externalBorrow; (*A).x -= externalBorrow;
borrow.y += (*A).y < borrow.x; (*A).y -= borrow.x;
return borrow.y;
}
uint32_t sub128(uint4 *A, uint4 B)
{
uint4 borrow = -convert_uint4((*A) < B);
*A -= B;
borrow.y += (*A).y < borrow.x; (*A).y -= borrow.x;
borrow.z += (*A).z < borrow.y; (*A).z -= borrow.y;
borrow.w += (*A).w < borrow.z; (*A).w -= borrow.z;
return borrow.w;
}
uint32_t sub128Borrow(uint4 *A, uint4 B, uint32_t externalBorrow)
{
uint4 borrow = -convert_uint4((*A) < B);
*A -= B;
borrow.x += (*A).x < externalBorrow; (*A).x -= externalBorrow;
borrow.y += (*A).y < borrow.x; (*A).y -= borrow.x;
borrow.z += (*A).z < borrow.y; (*A).z -= borrow.y;
borrow.w += (*A).w < borrow.z; (*A).w -= borrow.z;
return borrow.w;
}
uint32_t sub256(uint4 *a0, uint4 *a1, uint4 b0, uint4 b1)
{
return sub128Borrow(a1, b1, sub128(a0, b0));
}
uint32_t sub384(uint4 *a0, uint4 *a1, uint4 *a2, uint4 b0, uint4 b1, uint4 b2)
{
return sub128Borrow(a2, b2, sub128Borrow(a1, b1, sub128(a0, b0)));
}
uint32_t sub448(uint4 *a0, uint4 *a1, uint4 *a2, uint2 *a3, uint4 b0, uint4 b1, uint4 b2, uint2 b3)
{
return sub64Borrow(a3, b3, sub128Borrow(a2, b2, sub128Borrow(a1, b1, sub128(a0, b0))));
}
void mul128round(uint4 op1l0, uint32_t m1, uint32_t m2,
uint64_t *R0, uint64_t *R1, uint64_t *R2, uint64_t *R3)
{
uint4 l0 = mul_hi(op1l0, m1);
uint4 l1 = op1l0 * m2;
*R0 += l0.x; *R0 += l1.x;
*R1 += l0.y; *R1 += l1.y; *R1 += (*R0 >> 32);
*R2 += l0.z; *R2 += l1.z;
*R3 += l0.w; *R3 += l1.w;
}
void mul128schoolBook_v3(uint4 op1l0, uint4 op2l0, uint4 *rl0, uint4 *rl1)
{
#define b1 op2l0.w
#define b2 op2l0.z
#define b3 op2l0.y
#define b4 op2l0.x
ulong R0x = op1l0.x * b4;
ulong R0y = op1l0.y * b4;
ulong R0z = op1l0.z * b4;
ulong R0w = op1l0.w * b4;
ulong R1x = mul_hi(op1l0.x, b1);
ulong R1y = mul_hi(op1l0.y, b1);
ulong R1z = mul_hi(op1l0.z, b1);
ulong R1w = mul_hi(op1l0.w, b1);
mul128round(op1l0, b4, b3, &R0y, &R0z, &R0w, &R1x);
mul128round(op1l0, b3, b2, &R0z, &R0w, &R1x, &R1y);
mul128round(op1l0, b2, b1, &R0w, &R1x, &R1y, &R1z);
R1y += (R1x >> 32);
R1z += (R1y >> 32);
R1w += (R1z >> 32);
*rl0 = (uint4){R0x, R0y, R0z, R0w};
*rl1 = (uint4){R1x, R1y, R1z, R1w};
#undef b1
#undef b2
#undef b3
#undef b4
}
void mul256round_v3(uint4 op1l0, uint4 op1l1, uint32_t m1, uint32_t m2,
uint64_t *R0, uint64_t *R1, uint64_t *R2, uint64_t *R3,
uint64_t *R4, uint64_t *R5, uint64_t *R6, uint64_t *R7)
{
uint4 m1l0 = mul_hi(op1l0, m1);
uint4 m1l1 = mul_hi(op1l1, m1);
uint4 m2l0 = op1l0 * m2;
uint4 m2l1 = op1l1 * m2;
union {
uint2 v32;
ulong v64;
} Int;
*R0 += m1l0.x; *R0 += m2l0.x;
*R1 += m1l0.y; *R1 += m2l0.y; Int.v64 = *R0; *R1 += Int.v32.y;
*R2 += m1l0.z; *R2 += m2l0.z;
*R3 += m1l0.w; *R3 += m2l0.w;
*R4 += m1l1.x; *R4 += m2l1.x;
*R5 += m1l1.y; *R5 += m2l1.y;
*R6 += m1l1.z; *R6 += m2l1.z;
*R7 += m1l1.w; *R7 += m2l1.w;
}
void mul384round_v3(uint4 op1l0, uint4 op1l1, uint4 op1l2, uint32_t m1, uint32_t m2,
uint64_t *R0, uint64_t *R1, uint64_t *R2, uint64_t *R3,
uint64_t *R4, uint64_t *R5, uint64_t *R6, uint64_t *R7,
uint64_t *R8, uint64_t *R9, uint64_t *R10, uint64_t *R11)
{
uint4 m1l0 = mul_hi(op1l0, m1);
uint4 m1l1 = mul_hi(op1l1, m1);
uint4 m1l2 = mul_hi(op1l2, m1);
uint4 m2l0 = op1l0 * m2;
uint4 m2l1 = op1l1 * m2;
uint4 m2l2 = op1l2 * m2;
union {
uint2 v32;
ulong v64;
} Int;
*R0 += m1l0.x; *R0 += m2l0.x;
*R1 += m1l0.y; *R1 += m2l0.y; Int.v64 = *R0; *R1 += Int.v32.y;
*R2 += m1l0.z; *R2 += m2l0.z;
*R3 += m1l0.w; *R3 += m2l0.w;
*R4 += m1l1.x; *R4 += m2l1.x;
*R5 += m1l1.y; *R5 += m2l1.y;
*R6 += m1l1.z; *R6 += m2l1.z;
*R7 += m1l1.w; *R7 += m2l1.w;
*R8 += m1l2.x; *R8 += m2l2.x;
*R9 += m1l2.y; *R9 += m2l2.y;
*R10 += m1l2.z; *R10 += m2l2.z;
*R11 += m1l2.w; *R11 += m2l2.w;
}
void mul448round_v3(uint4 op1l0, uint4 op1l1, uint4 op1l2, uint2 op1l3, uint32_t m1, uint32_t m2,
uint64_t *R0, uint64_t *R1, uint64_t *R2, uint64_t *R3,
uint64_t *R4, uint64_t *R5, uint64_t *R6, uint64_t *R7,
uint64_t *R8, uint64_t *R9, uint64_t *R10, uint64_t *R11,
uint64_t *R12, uint64_t *R13)
{
uint4 m1l0 = mul_hi(op1l0, m1);
uint4 m1l1 = mul_hi(op1l1, m1);
uint4 m1l2 = mul_hi(op1l2, m1);
uint2 m1l3 = mul_hi(op1l3, m1);
uint4 m2l0 = op1l0 * m2;
uint4 m2l1 = op1l1 * m2;
uint4 m2l2 = op1l2 * m2;
uint2 m2l3 = op1l3 * m2;
union {
uint2 v32;
ulong v64;
} Int;
*R0 += m1l0.x; *R0 += m2l0.x;
*R1 += m1l0.y; *R1 += m2l0.y; Int.v64 = *R0; *R1 += Int.v32.y;
*R2 += m1l0.z; *R2 += m2l0.z;
*R3 += m1l0.w; *R3 += m2l0.w;
*R4 += m1l1.x; *R4 += m2l1.x;
*R5 += m1l1.y; *R5 += m2l1.y;
*R6 += m1l1.z; *R6 += m2l1.z;
*R7 += m1l1.w; *R7 += m2l1.w;
*R8 += m1l2.x; *R8 += m2l2.x;
*R9 += m1l2.y; *R9 += m2l2.y;
*R10 += m1l2.z; *R10 += m2l2.z;
*R11 += m1l2.w; *R11 += m2l2.w;
*R12 += m1l3.x; *R12 += m2l3.x;
*R13 += m1l3.y; *R13 += m2l3.y;
}
void mul256schoolBook_v3(uint4 op1l0, uint4 op1l1,
uint4 op2l0, uint4 op2l1,
uint4 *rl0, uint4 *rl1, uint4 *rl2, uint4 *rl3)
{
#define b1 op2l1.w
#define b2 op2l1.z
#define b3 op2l1.y
#define b4 op2l1.x
#define b5 op2l0.w
#define b6 op2l0.z
#define b7 op2l0.y
#define b8 op2l0.x
ulong R0x = op1l0.x * b8;
ulong R0y = op1l0.y * b8;
ulong R0z = op1l0.z * b8;
ulong R0w = op1l0.w * b8;
ulong R1x = op1l1.x * b8;
ulong R1y = op1l1.y * b8;
ulong R1z = op1l1.z * b8;
ulong R1w = op1l1.w * b8;
ulong R2x = mul_hi(op1l0.x, b1);
ulong R2y = mul_hi(op1l0.y, b1);
ulong R2z = mul_hi(op1l0.z, b1);
ulong R2w = mul_hi(op1l0.w, b1);
ulong R3x = mul_hi(op1l1.x, b1);
ulong R3y = mul_hi(op1l1.y, b1);
ulong R3z = mul_hi(op1l1.z, b1);
ulong R3w = mul_hi(op1l1.w, b1);
mul256round_v3(op1l0, op1l1, b8, b7, &R0y, &R0z, &R0w, &R1x, &R1y, &R1z, &R1w, &R2x);
mul256round_v3(op1l0, op1l1, b7, b6, &R0z, &R0w, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y);
mul256round_v3(op1l0, op1l1, b6, b5, &R0w, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z);
mul256round_v3(op1l0, op1l1, b5, b4, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w);
mul256round_v3(op1l0, op1l1, b4, b3, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x);
mul256round_v3(op1l0, op1l1, b3, b2, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y);
mul256round_v3(op1l0, op1l1, b2, b1, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z);
union {
uint2 v32;
ulong v64;
} Int;
Int.v64 = R2x; R2y += Int.v32.y;
Int.v64 = R2y; R2z += Int.v32.y;
Int.v64 = R2z; R2w += Int.v32.y;
Int.v64 = R2w; R3x += Int.v32.y;
Int.v64 = R3x; R3y += Int.v32.y;
Int.v64 = R3y; R3z += Int.v32.y;
Int.v64 = R3z; R3w += Int.v32.y;
*rl0 = (uint4){R0x, R0y, R0z, R0w};
*rl1 = (uint4){R1x, R1y, R1z, R1w};
*rl2 = (uint4){R2x, R2y, R2z, R2w};
*rl3 = (uint4){R3x, R3y, R3z, R3w};
#undef b1
#undef b2
#undef b3
#undef b4
#undef b5
#undef b6
#undef b7
#undef b8
}
void mul384schoolBook_v3(uint4 op1l0, uint4 op1l1, uint4 op1l2, // low --> hi
uint4 op2l0, uint4 op2l1, uint4 op2l2, // low --> hi
uint4 *rl0, uint4 *rl1, uint4 *rl2, uint4 *rl3, uint4 *rl4, uint4 *rl5)
{
#define b1 op2l2.w
#define b2 op2l2.z
#define b3 op2l2.y
#define b4 op2l2.x
#define b5 op2l1.w
#define b6 op2l1.z
#define b7 op2l1.y
#define b8 op2l1.x
#define b9 op2l0.w
#define b10 op2l0.z
#define b11 op2l0.y
#define b12 op2l0.x
ulong R0x = op1l0.x * b12;
ulong R0y = op1l0.y * b12;
ulong R0z = op1l0.z * b12;
ulong R0w = op1l0.w * b12;
ulong R1x = op1l1.x * b12;
ulong R1y = op1l1.y * b12;
ulong R1z = op1l1.z * b12;
ulong R1w = op1l1.w * b12;
ulong R2x = op1l2.x * b12;
ulong R2y = op1l2.y * b12;
ulong R2z = op1l2.z * b12;
ulong R2w = op1l2.w * b12;
ulong R3x = mul_hi(op1l0.x, b1);
ulong R3y = mul_hi(op1l0.y, b1);
ulong R3z = mul_hi(op1l0.z, b1);
ulong R3w = mul_hi(op1l0.w, b1);
ulong R4x = mul_hi(op1l1.x, b1);
ulong R4y = mul_hi(op1l1.y, b1);
ulong R4z = mul_hi(op1l1.z, b1);
ulong R4w = mul_hi(op1l1.w, b1);
ulong R5x = mul_hi(op1l2.x, b1);
ulong R5y = mul_hi(op1l2.y, b1);
ulong R5z = mul_hi(op1l2.z, b1);
ulong R5w = mul_hi(op1l2.w, b1);
mul384round_v3(op1l0, op1l1, op1l2, b12, b11, &R0y, &R0z, &R0w, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x);
mul384round_v3(op1l0, op1l1, op1l2, b11, b10, &R0z, &R0w, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y);
mul384round_v3(op1l0, op1l1, op1l2, b10, b9, &R0w, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z);
mul384round_v3(op1l0, op1l1, op1l2, b9, b8, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w);
mul384round_v3(op1l0, op1l1, op1l2, b8, b7, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x);
mul384round_v3(op1l0, op1l1, op1l2, b7, b6, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y);
mul384round_v3(op1l0, op1l1, op1l2, b6, b5, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z);
mul384round_v3(op1l0, op1l1, op1l2, b5, b4, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w);
mul384round_v3(op1l0, op1l1, op1l2, b4, b3, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x);
mul384round_v3(op1l0, op1l1, op1l2, b3, b2, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x, &R5y);
mul384round_v3(op1l0, op1l1, op1l2, b2, b1, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x, &R5y, &R5z);
union {
uint2 v32;
ulong v64;
} Int;
Int.v64 = R3x; R3y += Int.v32.y;
Int.v64 = R3y; R3z += Int.v32.y;
Int.v64 = R3z; R3w += Int.v32.y;
Int.v64 = R3w; R4x += Int.v32.y;
Int.v64 = R4x; R4y += Int.v32.y;
Int.v64 = R4y; R4z += Int.v32.y;
Int.v64 = R4z; R4w += Int.v32.y;
Int.v64 = R4w; R5x += Int.v32.y;
Int.v64 = R5x; R5y += Int.v32.y;
Int.v64 = R5y; R5z += Int.v32.y;
Int.v64 = R5z; R5w += Int.v32.y;
*rl0 = (uint4){R0x, R0y, R0z, R0w};
*rl1 = (uint4){R1x, R1y, R1z, R1w};
*rl2 = (uint4){R2x, R2y, R2z, R2w};
*rl3 = (uint4){R3x, R3y, R3z, R3w};
*rl4 = (uint4){R4x, R4y, R4z, R4w};
*rl5 = (uint4){R5x, R5y, R5z, R5w};
#undef b1
#undef b2
#undef b3
#undef b4
#undef b5
#undef b6
#undef b7
#undef b8
#undef b9
#undef b10
#undef b11
#undef b12
}
void mul448schoolBook_v3(uint4 op1l0, uint4 op1l1, uint4 op1l2, uint2 op1l3, // low --> hi
uint4 op2l0, uint4 op2l1, uint4 op2l2, uint2 op2l3, // low --> hi
uint4 *rl0, uint4 *rl1, uint4 *rl2, uint4 *rl3, uint4 *rl4, uint4 *rl5, uint4 *rl6)
{
#define b1 op2l3.y
#define b2 op2l3.x
#define b3 op2l2.w
#define b4 op2l2.z
#define b5 op2l2.y
#define b6 op2l2.x
#define b7 op2l1.w
#define b8 op2l1.z
#define b9 op2l1.y
#define b10 op2l1.x
#define b11 op2l0.w
#define b12 op2l0.z
#define b13 op2l0.y
#define b14 op2l0.x
ulong R0x = op1l0.x * b14;
ulong R0y = op1l0.y * b14;
ulong R0z = op1l0.z * b14;
ulong R0w = op1l0.w * b14;
ulong R1x = op1l1.x * b14;
ulong R1y = op1l1.y * b14;
ulong R1z = op1l1.z * b14;
ulong R1w = op1l1.w * b14;
ulong R2x = op1l2.x * b14;
ulong R2y = op1l2.y * b14;
ulong R2z = op1l2.z * b14;
ulong R2w = op1l2.w * b14;
ulong R3x = op1l3.x * b14;
ulong R3y = op1l3.y * b14;
ulong R3z = mul_hi(op1l0.x, b1);
ulong R3w = mul_hi(op1l0.y, b1);
ulong R4x = mul_hi(op1l0.z, b1);
ulong R4y = mul_hi(op1l0.w, b1);
ulong R4z = mul_hi(op1l1.x, b1);
ulong R4w = mul_hi(op1l1.y, b1);
ulong R5x = mul_hi(op1l1.z, b1);
ulong R5y = mul_hi(op1l1.w, b1);
ulong R5z = mul_hi(op1l2.x, b1);
ulong R5w = mul_hi(op1l2.y, b1);
ulong R6x = mul_hi(op1l2.z, b1);
ulong R6y = mul_hi(op1l2.w, b1);
ulong R6z = mul_hi(op1l3.x, b1);
ulong R6w = mul_hi(op1l3.y, b1);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b14, b13, &R0y, &R0z, &R0w, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b13, b12, &R0z, &R0w, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b12, b11, &R0w, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b11, b10, &R1x, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b10, b9, &R1y, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b9, b8, &R1z, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b8, b7, &R1w, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b7, b6, &R2x, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x, &R5y);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b6, b5, &R2y, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x, &R5y, &R5z);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b5, b4, &R2z, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x, &R5y, &R5z, &R5w);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b4, b3, &R2w, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x, &R5y, &R5z, &R5w, &R6x);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b3, b2, &R3x, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x, &R5y, &R5z, &R5w, &R6x, &R6y);
mul448round_v3(op1l0, op1l1, op1l2, op1l3, b2, b1, &R3y, &R3z, &R3w, &R4x, &R4y, &R4z, &R4w, &R5x, &R5y, &R5z, &R5w, &R6x, &R6y, &R6z);
union {
uint2 v32;
ulong v64;
} Int;
Int.v64 = R3z; R3w += Int.v32.y;
Int.v64 = R3w; R4x += Int.v32.y;
Int.v64 = R4x; R4y += Int.v32.y;
Int.v64 = R4y; R4z += Int.v32.y;
Int.v64 = R4z; R4w += Int.v32.y;
Int.v64 = R4w; R5x += Int.v32.y;
Int.v64 = R5x; R5y += Int.v32.y;
Int.v64 = R5y; R5z += Int.v32.y;
Int.v64 = R5z; R5w += Int.v32.y;
Int.v64 = R5w; R6x += Int.v32.y;
Int.v64 = R6x; R6y += Int.v32.y;
Int.v64 = R6y; R6z += Int.v32.y;
Int.v64 = R6z; R6w += Int.v32.y;
*rl0 = (uint4){R0x, R0y, R0z, R0w};
*rl1 = (uint4){R1x, R1y, R1z, R1w};
*rl2 = (uint4){R2x, R2y, R2z, R2w};
*rl3 = (uint4){R3x, R3y, R3z, R3w};
*rl4 = (uint4){R4x, R4y, R4z, R4w};
*rl5 = (uint4){R5x, R5y, R5z, R5w};
*rl6 = (uint4){R6x, R6y, R6z, R6w};
#undef b1
#undef b2
#undef b3
#undef b4
#undef b5
#undef b6
#undef b7
#undef b8
#undef b9
#undef b10
#undef b11
#undef b12
#undef b13
#undef b14
}
void mul512schoolBook_v3(uint4 op1l0, uint4 op1l1, uint4 op1l2, uint4 op1l3, // low --> hi
uint4 op2l0, uint4 op2l1, uint4 op2l2, uint4 op2l3, // low --> hi
uint4 *rl0, uint4 *rl1, uint4 *rl2, uint4 *rl3, uint4 *rl4, uint4 *rl5, uint4 *rl6, uint4 *rl7)
{
}
__kernel void multiplyBenchmark128(__global uint32_t *m1,
__global uint32_t *m2,
__global uint32_t *out,
unsigned elementsNum)
{
__global uint4 *M1 = (__global uint4*)m1;
__global uint4 *M2 = (__global uint4*)m2;
__global uint4 *OUT = (__global uint4*)out;
unsigned globalSize = get_global_size(0);
for (unsigned i = get_global_id(0); i < elementsNum; i += globalSize) {
uint4 op0l0 = M1[i];
uint4 op1l0 = M2[i];
uint4 ResultLimb1;
uint4 ResultLimb2;
for (unsigned repeatNum = 0; repeatNum < 512; repeatNum++) {
mul128schoolBook_v3(op0l0, op1l0, &ResultLimb1, &ResultLimb2);
op0l0 = ResultLimb1;
}
OUT[i*2] = ResultLimb1;
OUT[i*2+1] = ResultLimb2;
}
}
__kernel void multiplyBenchmark256(__global uint32_t *m1,
__global uint32_t *m2,
__global uint32_t *out,
unsigned elementsNum)
{
__global uint4 *M1 = (__global uint4*)m1;
__global uint4 *M2 = (__global uint4*)m2;
__global uint4 *OUT = (__global uint4*)out;
unsigned globalSize = get_global_size(0);
for (unsigned i = get_global_id(0); i < elementsNum; i += globalSize) {
uint4 op1l0 = M1[i*2];
uint4 op1l1 = M1[i*2+1];
uint4 op2l0 = M2[i*2];
uint4 op2l1 = M2[i*2+1];
uint4 ResultLimb1;
uint4 ResultLimb2;
uint4 ResultLimb3;
uint4 ResultLimb4;
for (unsigned repeatNum = 0; repeatNum < 512; repeatNum++) {
mul256schoolBook_v3(op1l0, op1l1, op2l0, op2l1,
&ResultLimb1, &ResultLimb2, &ResultLimb3, &ResultLimb4);
op1l0 = ResultLimb1;
op1l1 = ResultLimb2;
}
OUT[i*4] = ResultLimb1;
OUT[i*4+1] = ResultLimb2;
OUT[i*4+2] = ResultLimb3;
OUT[i*4+3] = ResultLimb4;
}
}
__kernel void multiplyBenchmark384(__global uint32_t *m1,
__global uint32_t *m2,
__global uint32_t *out,
unsigned elementsNum)
{
__global uint4 *M1 = (__global uint4*)m1;
__global uint4 *M2 = (__global uint4*)m2;
__global uint4 *OUT = (__global uint4*)out;
unsigned globalSize = get_global_size(0);
for (unsigned i = get_global_id(0); i < elementsNum; i += globalSize) {
uint4 op1l0 = M1[i*3];
uint4 op1l1 = M1[i*3+1];
uint4 op1l2 = M1[i*3+2];
uint4 op2l0 = M2[i*3];
uint4 op2l1 = M2[i*3+1];
uint4 op2l2 = M2[i*3+2];
uint4 ResultLimb1;
uint4 ResultLimb2;
uint4 ResultLimb3;
uint4 ResultLimb4;
uint4 ResultLimb5;
uint4 ResultLimb6;
for (unsigned repeatNum = 0; repeatNum < 512; repeatNum++) {
mul384schoolBook_v3(op1l0, op1l1, op1l2, op2l0, op2l1, op2l2,
&ResultLimb1, &ResultLimb2, &ResultLimb3, &ResultLimb4, &ResultLimb5, &ResultLimb6);
op1l0 = ResultLimb1;
op1l1 = ResultLimb2;
op1l2 = ResultLimb3;
}
OUT[i*6] = ResultLimb1;
OUT[i*6+1] = ResultLimb2;
OUT[i*6+2] = ResultLimb3;
OUT[i*6+3] = ResultLimb4;
OUT[i*6+4] = ResultLimb5;
OUT[i*6+5] = ResultLimb6;
}
}
__kernel void multiplyBenchmark448(__global uint32_t *m1,
__global uint32_t *m2,
__global uint32_t *out,
unsigned elementsNum)
{
__global uint4 *M1 = (__global uint4*)m1;
__global uint4 *M2 = (__global uint4*)m2;
__global uint4 *OUT = (__global uint4*)out;
unsigned globalSize = get_global_size(0);
for (unsigned i = get_global_id(0); i < elementsNum; i += globalSize) {
uint4 op1l0 = *(__global uint4*)(m1 + i*14); //M1[i*3];
uint4 op1l1 = *(__global uint4*)(m1 + i*14 + 4);
uint4 op1l2 = *(__global uint4*)(m1 + i*14 + 8);
uint2 op1l3 = *(__global uint2*)(m1 + i*14 + 12);
uint4 op2l0 = *(__global uint4*)(m2 + i*14);
uint4 op2l1 = *(__global uint4*)(m2 + i*14 + 4);
uint4 op2l2 = *(__global uint4*)(m2 + i*14 + 8);
uint2 op2l3 = *(__global uint2*)(m2 + i*14 + 12);
uint4 ResultLimb1;
uint4 ResultLimb2;
uint4 ResultLimb3;
uint4 ResultLimb4;
uint4 ResultLimb5;
uint4 ResultLimb6;
uint4 ResultLimb7;
for (unsigned repeatNum = 0; repeatNum < 512; repeatNum++) {
mul448schoolBook_v3(op1l0, op1l1, op1l2, op1l3, op2l0, op2l1, op2l2, op2l3,
&ResultLimb1, &ResultLimb2, &ResultLimb3, &ResultLimb4, &ResultLimb5, &ResultLimb6, &ResultLimb7);
op1l0 = ResultLimb1;
op1l1 = ResultLimb2;
op1l2 = ResultLimb3;
op1l3 = ResultLimb4.xy;
}
OUT[i*7] = ResultLimb1;
OUT[i*7+1] = ResultLimb2;
OUT[i*7+2] = ResultLimb3;
OUT[i*7+3] = ResultLimb4;
OUT[i*7+4] = ResultLimb5;