forked from chrchang/plink-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plink_calc.c
9934 lines (9719 loc) · 348 KB
/
plink_calc.c
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
// The key ideas behind this calculator's design are:
//
// 1. Incremental processing of SNPs. Each element A_{jk} of a distance or
// relationship matrix is a sum of M terms, one for each SNP, multiplied by a
// missingness correction at the end. We can walk through the SNPs
// sequentially without keeping much in memory beyond partial sums;
// conveniently, this plays well with the decision made by the PLINK team a few
// years ago to switch to SNP-major binary files.
//
// 2. Multiplexing of markers using bitwise operations. For instance, there
// are only seven possible ways SNP i can affect the relationship matrix entry
// between samples j and k:
// a. j and k are both homozygous for the rare allele
// b. one is homozygous rare, one is heterozygous
// c. one is homozygous rare, one is homozygous common
// d. both are heterozygous
// e. one is heterozygous, one is homozygous common
// f. both are homozygous common
// g. one or both has missing genotype data
// Seven cases can be distinguished by three bits, so one can compose a
// sequence of bitwise operations that maps a pair of padded 2-bit PLINK
// genotypes to seven different 3-bit values according to this breakdown.
// On 64-bit machines, this allows integer operations to act on 20 markers
// simultaneously. (There's space for a 21st, but we currently choose not to
// use it.)
//
// 3. Lookup tables describing the effect of 5-7 markers at a time on a
// distance or relationship, rather than just one. For relationship matrices,
// idea #2 allows computation of a single 64-bit integer where bits 0-2
// describe the relationship on marker #0, bits 3-5 describe the relationship
// on marker #1, ..., all the way up to bits 57-59 describing the relationship
// on marker #19. We then want to perform the update
// A_{jk} := A_{jk} + f_0(x_0) + f_1(x_1) + ... + f_19(x_19)
// where the x_i's are bit trios, and the f_i's map them to floating point
// terms. We could do this with 20 table lookups and floating point additions.
// Or, we could structure this as
// A_{jk} := A_{jk} + f_{0-4}(x_{0-4}) + ... + f_{15-19}(x_{15-19})
// where x_{0-4} denotes the lowest order *15* bits, and f_{0-4} maps them
// directly to f_0(x_0) + f_1(x_1) + f_2(x_2) + f_3(x_3) + f_4(x_4); similarly
// for f_{5-9}, f_{10-14}, and f_{15-19}. This requires precomputation of four
// lookup tables of size 2^15, total size 1 MB (which fits comfortably in a
// typical L2/L3 cache these days), and licenses the use of four table lookups
// and adds instead of twenty.
//
// 4. Bitslicing algorithms for especially fast calculation of unweighted
// distances and SNP covariances. Zero-exponent distance matrices and IBS
// matrices are special cases, reducing to Hamming weight computations plus a
// bit of dressing to handle missing markers. Hamming weight computation on
// x86 CPUs has been studied extensively by others; a good reference as of this
// writing is
// http://www.dalkescientific.com/writings/diary/archive/2011/11/02/faster_popcount_update.html .
// We use a variant of the Kim Walisch/Cedric Lauradoux bitslicing algorithm
// discussed there (with most 64-bit integer operations replaced by SSE2
// instructions), which runs several times faster than our corresponding
// nonzero exponent distance matrix computation.
//
// We also reduce SNP covariance calculation (used in LD-based pruning) to a
// few Hamming weights. (This can also be done for covariances between
// samples, but only when there are no missing markers, so we do not include
// an implementation of that.)
//
// 5. Splitting the distance/relationship matrix into pieces of roughly equal
// size and assigning one thread to each piece. This is an "embarrassingly
// parallel" problem with no need for careful synchronization. Cluster
// computing is supported in essentially the same manner.
//
//
//
// In the end, we can't get around the O(MN^2) nature of these calculations,
// but we believe we have beaten down the leading constant by a large enough
// factor to meaningfully help researchers.
#include "plink_common.h"
#include "plink_calc.h"
#include "plink_cluster.h"
#include "plink_matrix.h"
#include "plink_misc.h"
#include "plink_stats.h"
#include "pigz.h"
// number of different types of jackknife values to precompute (x^2, x, y, xy)
#define JACKKNIFE_VALS_REL 5
// Number of snp-major .bed lines to read at once for distance calc if exponent
// is zero. Currently assumed to be a multiple of 192, and no larger than
// 1920, by the popcount_..._multiword functions. (The optimal value depends
// on both system-specific properties such as cache sizes, as well as the
// number of samples in the current calculation, so in principle it's best to
// select this value at runtime. But 960 usually works well in practice in my
// experience.)
#define MULTIPLEX_DIST 960
#define MULTIPLEX_2DIST (MULTIPLEX_DIST * 2)
// Must be multiple of 384, no larger than 3840.
#define GENOME_MULTIPLEX 1152
#define GENOME_MULTIPLEX2 (GENOME_MULTIPLEX * 2)
#define MAX_EM_ACCEL 100.0
void rel_init(Rel_info* relip) {
relip->modifier = 0;
relip->regress_rel_iters = ITERS_DEFAULT;
relip->regress_rel_d = 0;
relip->unrelated_herit_tol = 0.0000001;
relip->unrelated_herit_covg = 0.45;
relip->unrelated_herit_covr = 0.55;
relip->cutoff = 0.025;
relip->ibc_type = 0;
relip->pc_ct = 20;
relip->pca_cluster_names_flattened = NULL;
relip->pca_clusters_fname = NULL;
}
void rel_cleanup(Rel_info* relip) {
free_cond(relip->pca_cluster_names_flattened);
free_cond(relip->pca_clusters_fname);
}
void update_rel_ibc(double* rel_ibc, uintptr_t* geno, double* set_allele_freqs, double* main_weights, int32_t ibc_type, uint32_t sample_ct, uint32_t window_size) {
// first calculate weight array, then loop
uint32_t uii;
uint32_t ujj;
uint32_t ukk;
uint32_t umm;
double twt;
double* wtptr;
double mult = 1.0;
uintptr_t ulii;
double weights[BITCT * 12];
double* weights1 = &(weights[64]);
double* weights2 = &(weights[128]);
double* weights3 = &(weights[256]);
double* weights4 = &(weights[320]);
#ifdef __LP64__
double* weights5 = &(weights[384]);
double* weights6 = &(weights[448]);
double* weights7 = &(weights[512]);
double* weights8 = &(weights[640]);
double* weights9 = &(weights[704]);
#endif
double wtarr[BITCT2 * 5];
double *wptr = weights;
fill_double_zero(wtarr, BITCT2 * 5);
for (uii = 0; uii < window_size; uii++) {
if ((set_allele_freqs[uii] != 0.0) && (set_allele_freqs[uii] < (1.0 - EPSILON))) {
if (ibc_type) {
if (ibc_type == 2) {
wtarr[uii * 8] = 2;
wtarr[uii * 8 + 2] = 2.0 - 1.0 / (2 * set_allele_freqs[uii] * (1.0 - set_allele_freqs[uii]));
wtarr[uii * 8 + 3] = 2;
} else {
twt = 2 * set_allele_freqs[uii];
if (ibc_type == 1) {
mult = 1 / (twt * (1.0 - set_allele_freqs[uii]));
}
wtarr[uii * 8] = twt * twt * mult;
wtarr[uii * 8 + 2] = (1.0 - twt) * (1.0 - twt) * mult;
wtarr[uii * 8 + 3] = (2.0 - twt) * (2.0 - twt) * mult;
}
} else {
twt = 1.0 - set_allele_freqs[uii];
mult = 1 / (set_allele_freqs[uii] * twt);
wtarr[uii * 8] = 1.0 + set_allele_freqs[uii] * set_allele_freqs[uii] * mult;
wtarr[uii * 8 + 3] = 1.0 + twt * twt * mult;
}
} else {
if (ibc_type) {
if (ibc_type == -1) {
twt = 2 * set_allele_freqs[uii];
wtarr[uii * 8] = twt * twt;
wtarr[uii * 8 + 2] = (1.0 - twt) * (1.0 - twt);
wtarr[uii * 8 + 3] = (2.0 - twt) * (2.0 - twt);
} else if (ibc_type == 1) {
// infinities are useful here for calling out inaccurate zero MAFs,
// but those markers should just be automatically filtered out
// instead?
wtarr[uii * 8 + 2] = INFINITY;
if (set_allele_freqs[uii] == 0.0) {
wtarr[uii * 8] = 0;
wtarr[uii * 8 + 3] = INFINITY;
} else {
wtarr[uii * 8] = INFINITY;
wtarr[uii * 8 + 3] = 0;
}
} else {
// need to set to 1 instead of 2 for agreement with GCTA
wtarr[uii * 8] = 1;
wtarr[uii * 8 + 2] = -INFINITY;
wtarr[uii * 8 + 3] = 1;
}
} else {
if (set_allele_freqs[uii] == 0.0) {
wtarr[uii * 8] = 1;
wtarr[uii * 8 + 3] = INFINITY;
} else {
wtarr[uii * 8] = INFINITY;
wtarr[uii * 8 + 3] = 1;
}
}
}
if (main_weights) {
wtarr[uii * 8] *= main_weights[uii];
wtarr[uii * 8 + 2] *= main_weights[uii];
wtarr[uii * 8 + 3] *= main_weights[uii];
}
}
for (ukk = 0; ukk < (BITCT * 5) / 32; ukk++) {
wtptr = &(wtarr[16 * ukk]);
#ifdef __LP64__
if ((ukk == 2) || (ukk == 7)) {
for (uii = 0; uii < 8; uii++) {
twt = wtptr[uii + 8];
for (ujj = 0; ujj < 8; ujj++) {
*wptr++ = twt + wtptr[ujj];
}
wptr = &(wptr[8]);
}
} else {
for (uii = 0; uii < 8; uii++) {
twt = wtptr[uii + 8];
for (ujj = 0; ujj < 8; ujj++) {
*wptr++ = twt + wtptr[ujj];
}
}
}
#else
if (ukk == 2) {
for (uii = 0; uii < 8; uii++) {
twt = wtptr[uii + 8];
for (ujj = 0; ujj < 8; ujj++) {
*wptr++ = twt + wtptr[ujj];
}
wptr = &(wptr[8]);
}
} else {
for (uii = 0; uii < 8; uii++) {
twt = wtptr[uii + 8];
for (ujj = 0; ujj < 8; ujj++) {
*wptr++ = twt + wtptr[ujj];
}
}
}
#endif
}
for (umm = 0; umm < sample_ct; umm++) {
ulii = *geno++;
#ifdef __LP64__
*rel_ibc += weights9[ulii >> 57] + weights8[(ulii >> 51) & 63] + weights7[(ulii >> 44) & 127] + weights6[(ulii >> 38) & 63] + weights5[(ulii >> 32) & 63] + weights4[(ulii >> 25) & 63] + weights3[(ulii >> 19) & 63] + weights2[(ulii >> 12) & 127] + weights1[(ulii >> 6) & 63] + weights[ulii & 63];
#else
*rel_ibc += weights4[ulii >> 25] + weights3[(ulii >> 19) & 63] + weights2[(ulii >> 12) & 127] + weights1[(ulii >> 6) & 63] + weights[ulii & 63];
#endif
rel_ibc++;
}
}
void fill_subset_weights(double* subset_weights, double* main_weights) {
uint32_t uii;
uint32_t ujj;
uint32_t ukk;
uint32_t umm;
uint32_t unn;
uint32_t uoo;
double wtarr[MULTIPLEX_DIST_EXP / 2];
double* wt;
#ifdef __LP64__
double twt[5];
double twtf;
__m128d* swpairs = (__m128d*)subset_weights;
__m128d vpen;
__m128d vfinal1;
__m128d vfinal2;
#else
uint32_t upp;
uint32_t uqq;
double twt[7];
#endif
memcpy(wtarr, main_weights, (MULTIPLEX_DIST_EXP / 2) * sizeof(double));
for (uoo = 0; uoo < 2; uoo++) {
wt = &(wtarr[7 * uoo]);
#ifdef __LP64__
vfinal1 = _mm_set_pd(wt[0], 0.0);
vfinal2 = _mm_set_pd(wt[0] * 2, wt[0]);
#endif
twt[0] = 0;
for (uii = 0; uii < 4; uii += 1) {
// turning the uii == 2 case into a memcpy doesn't actually seem to speed
// this up
if (uii & 1) {
twt[0] += wt[6];
}
twt[1] = twt[0];
for (ujj = 0; ujj < 4; ujj += 1) {
if (ujj & 1) {
twt[1] += wt[5];
}
twt[2] = twt[1];
for (ukk = 0; ukk < 4; ukk += 1) {
if (ukk & 1) {
twt[2] += wt[4];
}
twt[3] = twt[2];
for (umm = 0; umm < 4; umm++) {
if (umm & 1) {
twt[3] += wt[3];
}
twt[4] = twt[3];
for (unn = 0; unn < 4; unn++) {
if (unn & 1) {
twt[4] += wt[2];
}
#ifdef __LP64__
twtf = twt[4];
vpen = _mm_set1_pd(twtf);
*swpairs++ = _mm_add_pd(vpen, vfinal1);
*swpairs++ = _mm_add_pd(vpen, vfinal2);
twtf += wt[1];
vpen = _mm_set1_pd(twtf);
*swpairs++ = _mm_add_pd(vpen, vfinal1);
*swpairs++ = _mm_add_pd(vpen, vfinal2);
*swpairs = *(swpairs - 2);
swpairs++;
*swpairs = *(swpairs - 2);
swpairs++;
vpen = _mm_set1_pd(twtf + wt[1]);
*swpairs++ = _mm_add_pd(vpen, vfinal1);
*swpairs++ = _mm_add_pd(vpen, vfinal2);
#else
twt[5] = twt[4];
for (upp = 0; upp < 4; upp++) {
if (upp & 1) {
twt[5] += wt[1];
}
twt[6] = twt[5];
for (uqq = 0; uqq < 4; uqq++) {
if (uqq & 1) {
twt[6] += wt[0];
}
*subset_weights++ = twt[6];
}
}
#endif
}
}
}
}
}
}
#ifdef __LP64__
for (uoo = 0; uoo < 3; uoo++) {
wt = &(wtarr[14 + 6 * uoo]);
vfinal1 = _mm_set_pd(wt[0], 0.0);
vfinal2 = _mm_set_pd(2 * wt[0], wt[0]);
twt[0] = 0;
for (uii = 0; uii < 4; uii += 1) {
if (uii & 1) {
twt[0] += wt[5];
}
twt[1] = twt[0];
for (ujj = 0; ujj < 4; ujj += 1) {
if (ujj & 1) {
twt[1] += wt[4];
}
twt[2] = twt[1];
for (ukk = 0; ukk < 4; ukk += 1) {
if (ukk & 1) {
twt[2] += wt[3];
}
twt[3] = twt[2];
for (umm = 0; umm < 4; umm++) {
if (umm & 1) {
twt[3] += wt[2];
}
twtf = twt[3];
vpen = _mm_set1_pd(twtf);
*swpairs++ = _mm_add_pd(vpen, vfinal1);
*swpairs++ = _mm_add_pd(vpen, vfinal2);
twtf += wt[1];
vpen = _mm_set1_pd(twtf);
*swpairs++ = _mm_add_pd(vpen, vfinal1);
*swpairs++ = _mm_add_pd(vpen, vfinal2);
*swpairs = *(swpairs - 2);
swpairs++;
*swpairs = *(swpairs - 2);
swpairs++;
vpen = _mm_set1_pd(twtf + wt[1]);
*swpairs++ = _mm_add_pd(vpen, vfinal1);
*swpairs++ = _mm_add_pd(vpen, vfinal2);
}
}
}
}
}
#endif
}
void fill_subset_weights_r(double* subset_weights, double* set_allele_freqs, double* main_weights, uint32_t var_std) {
uint32_t uii;
uint32_t ujj;
uint32_t ukk;
uint32_t umm;
uint32_t unn;
// 20 markers to process in quintuplets, for 64-bit; 10, for 32-bit.
// Each quintuplet of markers requires 40 wtarr entries, and induces
// 2^15 writes to subset_weights[].
double wtarr_raw[BITCT2 * 5 + 1];
double* wtarr = wtarr_raw;
double twt;
double twt2;
double twt3;
double twt4;
double* wtptr;
double mean;
double mean_m1;
double mean_m2;
double mult = 1.0;
double aux;
#ifdef __LP64__
__m128d* swpairs = (__m128d*)subset_weights;
__m128d vpen;
__m128d vfinal1;
__m128d vfinal2;
__m128d vfinal3;
__m128d vfinal4;
#else
uint32_t uoo;
#endif
if (((uintptr_t)wtarr) & 15) {
// force 16-byte alignment; can't do this at compile-time since stack
// pointer has no 16-byte align guarantee.
// yes, this assumes doubles are 8 bytes.
wtarr++;
}
for (uii = 0; uii < MULTIPLEX_REL / 3; uii += 1) {
if (((set_allele_freqs[uii] != 0.0) && (set_allele_freqs[uii] < (1.0 - EPSILON))) || (!var_std)) {
if (set_allele_freqs[uii] < 0.5) {
mean = 2 * set_allele_freqs[uii];
mean_m1 = mean - 1.0;
mean_m2 = mean - 2.0;
if (var_std) {
mult = 1 / (mean * (1.0 - set_allele_freqs[uii]));
}
aux = mean * mult;
wtarr[uii * 8] = mean * aux;
wtarr[uii * 8 + 1] = 0;
wtarr[uii * 8 + 2] = mean_m1 * aux;
wtarr[uii * 8 + 3] = mean_m2 * aux;
wtarr[uii * 8 + 4] = mean_m1 * mean_m1 * mult;
wtarr[uii * 8 + 5] = mean_m2 * mean_m1 * mult;
wtarr[uii * 8 + 6] = mean_m2 * mean_m2 * mult;
} else {
mean = 2 * (1.0 - set_allele_freqs[uii]);
mean_m1 = mean - 1.0;
mean_m2 = mean - 2.0;
if (var_std) {
mult = 1 / (mean * set_allele_freqs[uii]);
}
aux = mean_m2 * mult;
wtarr[uii * 8] = mean_m2 * aux;
wtarr[uii * 8 + 1] = 0;
wtarr[uii * 8 + 2] = mean_m1 * aux;
wtarr[uii * 8 + 3] = mean * aux;
wtarr[uii * 8 + 4] = mean_m1 * mean_m1 * mult;
wtarr[uii * 8 + 5] = mean_m1 * mean * mult;
wtarr[uii * 8 + 6] = mean * mean * mult;
}
} else {
if (set_allele_freqs[uii] == 0.0) {
wtarr[uii * 8] = 0;
wtarr[uii * 8 + 1] = 0;
wtarr[uii * 8 + 2] = -1;
wtarr[uii * 8 + 3] = -2;
wtarr[uii * 8 + 4] = INFINITY;
wtarr[uii * 8 + 5] = INFINITY;
wtarr[uii * 8 + 6] = INFINITY;
} else {
wtarr[uii * 8] = INFINITY;
wtarr[uii * 8 + 1] = 0;
wtarr[uii * 8 + 2] = INFINITY;
wtarr[uii * 8 + 3] = -2;
wtarr[uii * 8 + 4] = INFINITY;
wtarr[uii * 8 + 5] = -1;
wtarr[uii * 8 + 6] = 0;
}
}
if (main_weights) {
for (ujj = 0; ujj < 7; ujj++) {
wtarr[uii * 8 + ujj] *= main_weights[uii];
}
}
wtarr[uii * 8 + 7] = 0;
}
for (unn = 0; unn < BITCT / 16; unn++) {
wtptr = &(wtarr[40 * unn]);
#ifdef __LP64__
vfinal1 = _mm_load_pd(wtptr);
vfinal2 = _mm_load_pd(&(wtptr[2]));
vfinal3 = _mm_load_pd(&(wtptr[4]));
vfinal4 = _mm_load_pd(&(wtptr[6]));
#endif
for (uii = 0; uii < 8; uii++) {
twt = wtptr[uii + 32];
for (ujj = 0; ujj < 8; ujj++) {
twt2 = twt + wtptr[ujj + 24];
for (ukk = 0; ukk < 8; ukk++) {
twt3 = twt2 + wtptr[ukk + 16];
for (umm = 0; umm < 8; umm++) {
twt4 = twt3 + wtptr[umm + 8];
#ifdef __LP64__
vpen = _mm_set1_pd(twt4);
*swpairs++ = _mm_add_pd(vpen, vfinal1);
*swpairs++ = _mm_add_pd(vpen, vfinal2);
*swpairs++ = _mm_add_pd(vpen, vfinal3);
*swpairs++ = _mm_add_pd(vpen, vfinal4);
#else
for (uoo = 0; uoo < 8; uoo++) {
*subset_weights++ = twt4 + wtptr[uoo];
}
#endif
}
}
}
}
}
}
int32_t get_chrom_end(Chrom_info* chrom_info_ptr, uintptr_t marker_idx) {
return chrom_info_ptr->chrom_end[get_marker_chrom(chrom_info_ptr, marker_idx)];
}
void exclude_multi(uintptr_t* exclude_arr, int32_t* new_excl, uint32_t unfiltered_sample_ct, uintptr_t* exclude_ct_ptr) {
uint32_t exclude_ct = *exclude_ct_ptr;
int32_t* new_excl_end = &(new_excl[unfiltered_sample_ct - exclude_ct]);
uint32_t sample_uidx = 0;
uint32_t sample_uidx_stop;
do {
sample_uidx = next_unset_unsafe(exclude_arr, sample_uidx);
sample_uidx_stop = next_set(exclude_arr, sample_uidx, unfiltered_sample_ct);
do {
if (*new_excl++ == -1) {
SET_BIT(exclude_arr, sample_uidx);
exclude_ct++;
}
} while (++sample_uidx < sample_uidx_stop);
} while (new_excl < new_excl_end);
*exclude_ct_ptr = exclude_ct;
}
void collapse_copy_phenod(double* target, double* pheno_d, uintptr_t* sample_exclude, uintptr_t unfiltered_sample_ct, uintptr_t sample_ct) {
uintptr_t sample_uidx = 0;
double* target_end = &(target[sample_ct]);
uintptr_t delta;
do {
sample_uidx = next_unset_ul_unsafe(sample_exclude, sample_uidx);
delta = next_set_ul(sample_exclude, sample_uidx, unfiltered_sample_ct) - sample_uidx;
memcpy(target, &(pheno_d[sample_uidx]), delta * sizeof(double));
target = &(target[delta]);
sample_uidx += delta;
} while (target < target_end);
}
static inline void collapse_copy_phenod_incl(double* target, double* pheno_d, uintptr_t* sample_include, uintptr_t unfiltered_sample_ct, uintptr_t sample_ct) {
uintptr_t sample_uidx = 0;
double* target_end = &(target[sample_ct]);
uintptr_t delta;
do {
sample_uidx = next_set_ul_unsafe(sample_include, sample_uidx);
delta = next_unset_ul(sample_include, sample_uidx, unfiltered_sample_ct) - sample_uidx;
memcpy(target, &(pheno_d[sample_uidx]), delta * sizeof(double));
target = &(target[delta]);
sample_uidx += delta;
} while (target < target_end);
}
#ifdef __LP64__
// XOR + mask variants of vectorized Lauradoux/Walisch popcount. (See
// popcount_vecs() in plink_common.c for basic documentation.)
// Note that the size of the popcounted buffer is a hardcoded constant
// (specifically, (MULTIPLEX_DIST / BITCT) * 16 bytes). The current code
// assumes (MULTIPLEX_DIST / BITCT) is a multiple of 3, and no greater than 30.
static inline uint32_t popcount_xor_1mask_multiword(__m128i** xor1p, __m128i* xor2, __m128i** maskp) {
const __m128i m1 = {FIVEMASK, FIVEMASK};
const __m128i m2 = {0x3333333333333333LLU, 0x3333333333333333LLU};
const __m128i m4 = {0x0f0f0f0f0f0f0f0fLLU, 0x0f0f0f0f0f0f0f0fLLU};
const __m128i m8 = {0x00ff00ff00ff00ffLLU, 0x00ff00ff00ff00ffLLU};
__m128i count1, count2, half1, half2;
__uni16 acc;
__m128i* xor2_end = &(xor2[MULTIPLEX_2DIST / 128]);
acc.vi = _mm_setzero_si128();
do {
count1 = _mm_and_si128(_mm_xor_si128(*((*xor1p)++), *xor2++), *((*maskp)++));
count2 = _mm_and_si128(_mm_xor_si128(*((*xor1p)++), *xor2++), *((*maskp)++));
half1 = _mm_and_si128(_mm_xor_si128(*((*xor1p)++), *xor2++), *((*maskp)++));
half2 = _mm_and_si128(_mm_srli_epi64(half1, 1), m1);
half1 = _mm_and_si128(half1, m1);
count1 = _mm_sub_epi64(count1, _mm_and_si128(_mm_srli_epi64(count1, 1), m1));
count2 = _mm_sub_epi64(count2, _mm_and_si128(_mm_srli_epi64(count2, 1), m1));
count1 = _mm_add_epi64(count1, half1);
count2 = _mm_add_epi64(count2, half2);
count1 = _mm_add_epi64(_mm_and_si128(count1, m2), _mm_and_si128(_mm_srli_epi64(count1, 2), m2));
count1 = _mm_add_epi64(count1, _mm_add_epi64(_mm_and_si128(count2, m2), _mm_and_si128(_mm_srli_epi64(count2, 2), m2)));
acc.vi = _mm_add_epi64(acc.vi, _mm_add_epi64(_mm_and_si128(count1, m4), _mm_and_si128(_mm_srli_epi64(count1, 4), m4)));
} while (xor2 < xor2_end);
#if MULTIPLEX_DIST > 960
acc.vi = _mm_add_epi64(_mm_and_si128(acc.vi, m8), _mm_and_si128(_mm_srli_epi64(acc.vi, 8), m8));
#else
// can get away with this when MULTIPLEX_DIST <= 960, since the 8-bit counts
// are guaranteed to be <= 120, thus adding two together does not overflow
// 255.
acc.vi = _mm_and_si128(_mm_add_epi64(acc.vi, _mm_srli_epi64(acc.vi, 8)), m8);
#endif
return ((acc.u8[0] + acc.u8[1]) * 0x1000100010001LLU) >> 48;
}
static inline uint32_t popcount_xor_2mask_multiword(__m128i** xor1p, __m128i* xor2, __m128i** mask1p, __m128i* mask2) {
const __m128i m1 = {FIVEMASK, FIVEMASK};
const __m128i m2 = {0x3333333333333333LLU, 0x3333333333333333LLU};
const __m128i m4 = {0x0f0f0f0f0f0f0f0fLLU, 0x0f0f0f0f0f0f0f0fLLU};
const __m128i m8 = {0x00ff00ff00ff00ffLLU, 0x00ff00ff00ff00ffLLU};
__m128i count1, count2, half1, half2;
__uni16 acc;
__m128i* xor2_end = &(xor2[MULTIPLEX_2DIST / 128]);
acc.vi = _mm_setzero_si128();
do {
count1 = _mm_and_si128(_mm_xor_si128(*((*xor1p)++), *xor2++), _mm_and_si128(*((*mask1p)++), *mask2++));
count2 = _mm_and_si128(_mm_xor_si128(*((*xor1p)++), *xor2++), _mm_and_si128(*((*mask1p)++), *mask2++));
half1 = _mm_and_si128(_mm_xor_si128(*((*xor1p)++), *xor2++), _mm_and_si128(*((*mask1p)++), *mask2++));
half2 = _mm_and_si128(_mm_srli_epi64(half1, 1), m1);
half1 = _mm_and_si128(half1, m1);
count1 = _mm_sub_epi64(count1, _mm_and_si128(_mm_srli_epi64(count1, 1), m1));
count2 = _mm_sub_epi64(count2, _mm_and_si128(_mm_srli_epi64(count2, 1), m1));
count1 = _mm_add_epi64(count1, half1);
count2 = _mm_add_epi64(count2, half2);
count1 = _mm_add_epi64(_mm_and_si128(count1, m2), _mm_and_si128(_mm_srli_epi64(count1, 2), m2));
count1 = _mm_add_epi64(count1, _mm_add_epi64(_mm_and_si128(count2, m2), _mm_and_si128(_mm_srli_epi64(count2, 2), m2)));
acc.vi = _mm_add_epi64(acc.vi, _mm_add_epi64(_mm_and_si128(count1, m4), _mm_and_si128(_mm_srli_epi64(count1, 4), m4)));
} while (xor2 < xor2_end);
#if MULTIPLEX_DIST > 960
acc.vi = _mm_add_epi64(_mm_and_si128(acc.vi, m8), _mm_and_si128(_mm_srli_epi64(acc.vi, 8), m8));
#else
acc.vi = _mm_and_si128(_mm_add_epi64(acc.vi, _mm_srli_epi64(acc.vi, 8)), m8);
#endif
return ((acc.u8[0] + acc.u8[1]) * 0x1000100010001LLU) >> 48;
}
#else
static inline uint32_t popcount_xor_1mask_multiword(uintptr_t** xor1p, uintptr_t* xor2, uintptr_t** maskp) {
uintptr_t* xor2_end = &(xor2[MULTIPLEX_DIST / 16]);
uint32_t bit_count = 0;
uintptr_t tmp_stor;
uintptr_t loader;
uintptr_t ulii;
uintptr_t uljj;
do {
loader = ((*((*xor1p)++)) ^ *xor2++) & (*((*maskp)++));
ulii = loader - ((loader >> 1) & FIVEMASK);
loader = ((*((*xor1p)++)) ^ *xor2++) & (*((*maskp)++));
uljj = loader - ((loader >> 1) & FIVEMASK);
loader = ((*((*xor1p)++)) ^ *xor2++) & (*((*maskp)++));
ulii += (loader >> 1) & FIVEMASK;
uljj += loader & FIVEMASK;
ulii = (ulii & 0x33333333) + ((ulii >> 2) & 0x33333333);
ulii += (uljj & 0x33333333) + ((uljj >> 2) & 0x33333333);
tmp_stor = (ulii & 0x0f0f0f0f) + ((ulii >> 4) & 0x0f0f0f0f);
loader = ((*((*xor1p)++)) ^ *xor2++) & (*((*maskp)++));
ulii = loader - ((loader >> 1) & FIVEMASK);
loader = ((*((*xor1p)++)) ^ *xor2++) & (*((*maskp)++));
uljj = loader - ((loader >> 1) & FIVEMASK);
loader = ((*((*xor1p)++)) ^ *xor2++) & (*((*maskp)++));
ulii += (loader >> 1) & FIVEMASK;
uljj += loader & FIVEMASK;
ulii = (ulii & 0x33333333) + ((ulii >> 2) & 0x33333333);
ulii += (uljj & 0x33333333) + ((uljj >> 2) & 0x33333333);
tmp_stor += (ulii & 0x0f0f0f0f) + ((ulii >> 4) & 0x0f0f0f0f);
bit_count += (tmp_stor * 0x01010101) >> 24;
} while (xor2 < xor2_end);
return bit_count;
}
static inline uint32_t popcount_xor_2mask_multiword(uintptr_t** xor1p, uintptr_t* xor2, uintptr_t** mask1p, uintptr_t* mask2) {
uintptr_t* xor2_end = &(xor2[MULTIPLEX_DIST / 16]);
uint32_t bit_count = 0;
uintptr_t tmp_stor;
uintptr_t loader;
uintptr_t ulii;
uintptr_t uljj;
do {
loader = ((*((*xor1p)++)) ^ *xor2++) & ((*((*mask1p)++)) & *mask2++);
ulii = loader - ((loader >> 1) & FIVEMASK);
loader = ((*((*xor1p)++)) ^ *xor2++) & ((*((*mask1p)++)) & *mask2++);
uljj = loader - ((loader >> 1) & FIVEMASK);
loader = ((*((*xor1p)++)) ^ *xor2++) & ((*((*mask1p)++)) & *mask2++);
loader -= ((loader >> 1) & FIVEMASK);
ulii = (ulii & 0x33333333) + ((ulii >> 2) & 0x33333333);
ulii += (uljj & 0x33333333) + ((uljj >> 2) & 0x33333333);
ulii += (loader & 0x33333333) + ((loader >> 2) & 0x33333333);
tmp_stor = (ulii & 0x0f0f0f0f) + ((ulii >> 4) & 0x0f0f0f0f);
loader = ((*((*xor1p)++)) ^ *xor2++) & ((*((*mask1p)++)) & *mask2++);
ulii = loader - ((loader >> 1) & FIVEMASK);
loader = ((*((*xor1p)++)) ^ *xor2++) & ((*((*mask1p)++)) & *mask2++);
uljj = loader - ((loader >> 1) & FIVEMASK);
loader = ((*((*xor1p)++)) ^ *xor2++) & ((*((*mask1p)++)) & *mask2++);
loader -= ((loader >> 1) & FIVEMASK);
ulii = (ulii & 0x33333333) + ((ulii >> 2) & 0x33333333);
ulii += (uljj & 0x33333333) + ((uljj >> 2) & 0x33333333);
ulii += (loader & 0x33333333) + ((loader >> 2) & 0x33333333);
tmp_stor += (ulii & 0x0f0f0f0f) + ((ulii >> 4) & 0x0f0f0f0f);
bit_count += (tmp_stor * 0x01010101) >> 24;
} while (xor2 < xor2_end);
return bit_count;
}
#endif
// ----- multithread globals -----
double* g_rel_dists = NULL;
uint32_t* g_sample_missing_unwt = NULL;
uint32_t* g_missing_dbl_excluded = NULL;
double* g_dists = NULL;
static uint32_t g_thread_start[MAX_THREADS_P1];
static int32_t* g_idists;
static uintptr_t* g_pheno_nm = NULL;
static uintptr_t* g_pheno_c = NULL;
static unsigned char* g_geno = NULL;
static double* g_subset_weights;
static uint32_t* g_subset_weights_i;
static double g_reg_tot_xy;
static double g_reg_tot_x;
static double g_reg_tot_y;
static double g_reg_tot_xx;
static double g_reg_tot_yy;
static uint32_t g_ctrl_ct;
static uint32_t g_case_ct;
static uintptr_t g_jackknife_iters;
static uint32_t g_jackknife_d;
static double g_calc_result[MAX_THREADS_P1][9];
static uintptr_t* g_masks;
static uintptr_t* g_mmasks;
static uint32_t* g_missing_tot_weights;
static uint32_t* g_sample_missing;
static double* g_jackknife_precomp = NULL;
static uint32_t* g_genome_main = NULL;
static uintptr_t g_marker_window[GENOME_MULTIPLEX * 2];
static double* g_pheno_packed;
// interleaved: first word of *every* permutation, then second word, etc.
static uintptr_t* g_perm_rows;
static uintptr_t* g_perm_col_buf;
static double* g_ibs_test_partial_sums;
static double* g_perm_results;
static uintptr_t g_perm_ct;
static double g_half_marker_ct_recip;
static uint32_t g_load_dists;
static unsigned char* g_generic_buf;
void ibs_test_init_col_buf(uintptr_t row_idx, uintptr_t perm_ct, uintptr_t* perm_rows, uintptr_t* perm_col_buf) {
uintptr_t perm_idx = 0;
uintptr_t block_size = BITCT;
uintptr_t rshift_ct = row_idx & (BITCT - 1);
uintptr_t* gpr_ptr;
uintptr_t ulii;
uintptr_t block_pos;
gpr_ptr = &(perm_rows[(row_idx / BITCT) * perm_ct]);
do {
if (perm_idx + BITCT > perm_ct) {
block_size = perm_ct - perm_idx;
}
ulii = 0;
block_pos = 0;
do {
ulii |= (((*gpr_ptr++) >> rshift_ct) & ONELU) << block_pos;
} while (++block_pos < block_size);
perm_idx += block_size;
*perm_col_buf++ = ulii;
} while (perm_idx < perm_ct);
}
double fill_psbuf(uintptr_t block_size, double half_marker_ct_recip, uint32_t load_dists, uintptr_t* pheno_nm, uintptr_t* pheno_c, double* dists, uintptr_t* col_uidxp, double* psbuf, double* ssq0p) {
// also updates total sum and sums of squares
double tot = 0.0;
uintptr_t col_idx = 0;
uintptr_t col_uidx = *col_uidxp;
uint32_t sub_block_size = 8;
uint32_t sub_block_idx;
double subtot;
uintptr_t ulii;
double increment[8];
double ssq[2];
double dxx;
ssq[0] = 0.0;
ssq[1] = 0.0;
do {
if (col_idx + 8 > block_size) {
sub_block_size = block_size - col_idx;
}
sub_block_idx = 0;
subtot = 0.0;
do {
next_set_ul_unsafe_ck(pheno_nm, &col_uidx);
if (load_dists) {
dxx = dists[col_uidx];
} else {
dxx = 1.0 - dists[col_uidx] * half_marker_ct_recip;
}
increment[sub_block_idx] = subtot - dxx;
subtot += dxx;
ssq[IS_SET(pheno_c, col_uidx)] += dxx * dxx;
col_uidx++;
} while (++sub_block_idx < sub_block_size);
tot += subtot;
while (sub_block_idx < 8) {
increment[sub_block_idx++] = subtot;
}
ulii = 0;
dxx = subtot;
goto fill_psbuf_loop_start;
do {
dxx += increment[CTZLU(++ulii)];
fill_psbuf_loop_start:
*psbuf++ = dxx;
} while (ulii < 255);
col_idx += sub_block_size;
} while (col_idx < block_size);
*col_uidxp = col_uidx;
ssq0p[0] += ssq[0];
ssq0p[1] += ssq[1];
return tot;
}
void ibs_test_process_perms(uintptr_t* perm_row_start, uintptr_t perm_ct, uint32_t sub_block_ct, double block_tot, double* psbuf, uintptr_t* perm_col_buf, double* perm_results) {
uintptr_t perm_idx = 0;
uintptr_t block_size = BITCT;
double dxx;
uintptr_t block_pos;
uintptr_t col_bits;
uintptr_t ulii;
uint32_t sub_block_idx;
do {
col_bits = *perm_col_buf++;
if (perm_idx + BITCT > perm_ct) {
block_size = perm_ct - perm_idx;
}
block_pos = 0;
if (sub_block_ct == BITCT / 8) {
do {
sub_block_idx = 0;
ulii = *perm_row_start++;
#ifdef __LP64__
dxx = psbuf[(uint8_t)ulii] + psbuf[256 + ((uint8_t)(ulii >> 8))] + psbuf[512 + ((uint8_t)(ulii >> 16))] + psbuf[768 + ((uint8_t)(ulii >> 24))] + psbuf[1024 + ((uint8_t)(ulii >> 32))] + psbuf[1280 + ((uint8_t)(ulii >> 40))] + psbuf[1536 + ((uint8_t)(ulii >> 48))] + psbuf[1792 + (ulii >> 56)];
#else
dxx = psbuf[(uint8_t)ulii] + psbuf[256 + ((uint8_t)(ulii >> 8))] + psbuf[512 + ((uint8_t)(ulii >> 16))] + psbuf[768 + (ulii >> 24)];
#endif
if (col_bits & 1) {
perm_results[2 * block_pos + 1] += dxx;
} else {
perm_results[2 * block_pos] += dxx;
perm_results[2 * block_pos + 1] += (block_tot - dxx);
}
col_bits >>= 1;
} while (++block_pos < block_size);
} else {
do {
sub_block_idx = 0;
ulii = *perm_row_start++;
dxx = psbuf[(uint8_t)ulii];
while (++sub_block_idx < sub_block_ct) {
dxx += psbuf[256 * sub_block_idx + ((uint8_t)(ulii >> (8 * sub_block_idx)))];
}
if (col_bits & 1) {
perm_results[2 * block_pos + 1] += dxx;
} else {
perm_results[2 * block_pos] += dxx;
perm_results[2 * block_pos + 1] += (block_tot - dxx);
}
col_bits >>= 1;
} while (++block_pos < block_size);
}
perm_idx += block_size;
perm_results = &(perm_results[2 * block_size]);
} while (perm_idx < perm_ct);
}
void ibs_test_range(uint32_t tidx, uintptr_t* perm_col_buf, double* perm_results) {
// (11-bit chunks were tested and found wanting.)
// 256 possible bytes * (BITCT / 8) bytes per word
double* psptr = &(g_ibs_test_partial_sums[tidx * (32 * BITCT)]);
double dist_tot = 0.0;
uintptr_t row_uidx = 0;
uintptr_t pct = 0;
uintptr_t pct_div = 1 + ((g_thread_start[1] * (g_thread_start[1] - 1)) / 100);
uintptr_t pct_next = pct_div;
uintptr_t perm_ct = g_perm_ct;
uintptr_t row_bound1 = g_thread_start[tidx];
uintptr_t row_bound2 = g_thread_start[tidx + 1];
uintptr_t* pheno_nm = g_pheno_nm;
uintptr_t* pheno_c = g_pheno_c;
uintptr_t* perm_rows = g_perm_rows;
double* dists = g_dists;
double half_marker_ct_recip = g_half_marker_ct_recip;
uint32_t load_dists = g_load_dists;
double ssq[3];
double* dptr;
double block_tot;
uintptr_t row_idx;
uintptr_t col_idx;
uintptr_t col_uidx;
uintptr_t block_size;
uintptr_t ulii;
uint32_t row_set;
ssq[0] = 0.0;
ssq[1] = 0.0;
ssq[2] = 0.0;
for (row_idx = 0; row_idx < row_bound1; row_uidx++, row_idx++) {
next_set_ul_unsafe_ck(pheno_nm, &row_uidx);
}
for (; row_idx < row_bound2; row_uidx++, row_idx++) {
next_set_ul_unsafe_ck(pheno_nm, &row_uidx);
dptr = &(dists[(row_uidx * (row_uidx - 1)) / 2]);
col_idx = 0;
col_uidx = 0;
row_set = IS_SET(pheno_c, row_uidx);
ibs_test_init_col_buf(row_idx, perm_ct, perm_rows, perm_col_buf);
do {
if (col_idx + BITCT > row_idx) {
block_size = row_idx - col_idx;
} else {
block_size = BITCT;
}
block_tot = fill_psbuf(block_size, half_marker_ct_recip, load_dists, pheno_nm, pheno_c, dptr, &col_uidx, psptr, &(ssq[row_set]));
dist_tot += block_tot;
ibs_test_process_perms(&(perm_rows[(col_idx / BITCT) * perm_ct]), perm_ct, (block_size + 7) / 8, block_tot, psptr, perm_col_buf, perm_results);
col_idx += block_size;
} while (col_idx < row_idx);
if (!tidx) {
// technically should change other triangular pct loops to this as well,
// to guard against int64 overflow with 400m+ people...
ulii = row_idx * (row_idx + 1);
if (ulii >= pct_next) {
if (pct >= 10) {
putchar('\b');
}
pct = ulii / pct_div;
printf("\b\b%" PRIuPTR "%%", pct);
fflush(stdout);
pct_next = pct_div * (pct + 1);
}
}
}
g_calc_result[tidx][0] = dist_tot;
g_calc_result[tidx][1] = ssq[0];
g_calc_result[tidx][2] = ssq[1];
g_calc_result[tidx][3] = ssq[2];
}
THREAD_RET_TYPE ibs_test_thread(void* arg) {
uintptr_t tidx = (uintptr_t)arg;
uintptr_t perm_ctcl = (g_perm_ct + (CACHELINE * 8 - 1)) / (CACHELINE * 8);
uintptr_t perm_ctcld = (g_perm_ct + (CACHELINE_DBL - 1)) / CACHELINE_DBL;
ibs_test_range((uint32_t)tidx, &(g_perm_col_buf[tidx * perm_ctcl * (CACHELINE / sizeof(intptr_t))]), &(g_perm_results[tidx * perm_ctcld * 2 * CACHELINE_DBL]));
THREAD_RETURN;
}
void incr_dists_i(uint32_t* idists, uintptr_t* geno, uintptr_t* masks, uint32_t start_idx, uint32_t end_idx) {
#ifdef __LP64__
__m128i* glptr;
__m128i* glptr2;
__m128i* mptr;
__m128i* mcptr_start;
uintptr_t* lptr;
#else
uintptr_t* glptr;
uintptr_t* glptr2;
uintptr_t* mptr;
uintptr_t* mcptr_start;
#endif
uint32_t uii;
int32_t jj;
uintptr_t mask_fixed;
for (uii = start_idx; uii < end_idx; uii++) {
jj = uii * (MULTIPLEX_2DIST / BITCT);
#ifdef __LP64__
glptr = (__m128i*)geno;
glptr2 = (__m128i*)(&(geno[jj]));
lptr = &(masks[jj]);
mcptr_start = (__m128i*)lptr;
mask_fixed = *lptr++;
for (jj = 0; jj < MULTIPLEX_2DIST / BITCT - 1; jj++) {
mask_fixed &= *lptr++;
}
mptr = (__m128i*)masks;
#else
glptr = geno;