Debian Codegraph @

plink_perm.h

raw symbols SCIP
1 #ifndef __PLINK_PERM_H__
2 #define __PLINK_PERM_H__
3
4 // This file is part of PLINK 1.9, copyright (C) 2005-2024 Shaun Purcell,
5 // Christopher Chang.
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
21 // Permutation generation and interpretation code common to many association
22 // tests.
23
24 // Inputs/outputs for multithreaded permutation generators.
25 extern uint32_t g_perm_pheno_nm_ct;
26 extern uint32_t g_perm_case_ct;
27 extern uint32_t g_perm_tot_quotient;
28 extern uint64_t g_perm_totq_magic;
29 extern uint32_t g_perm_totq_preshift;
30 extern uint32_t g_perm_totq_postshift;
31 extern uint32_t g_perm_totq_incr;
32 extern uint32_t g_perm_is_1bit;
33 extern uint32_t g_perm_generation_thread_ct;
34 extern uintptr_t g_perm_vec_ct;
35
36 extern uint32_t g_perm_cluster_ct;
37 extern uint32_t* g_perm_cluster_map;
38 extern uint32_t* g_perm_cluster_starts;
39 extern uint32_t* g_perm_cluster_case_cts;
40 extern uintptr_t* g_perm_cluster_cc_preimage;
41 extern uint32_t* g_perm_tot_quotients;
42 extern uint64_t* g_perm_totq_magics;
43 extern uint32_t* g_perm_totq_preshifts;
44 extern uint32_t* g_perm_totq_postshifts;
45 extern uint32_t* g_perm_totq_incrs;
46
47 extern uintptr_t* g_perm_vecs;
48
49 extern double* g_perm_vecstd;
50 extern double* g_perm_pheno_d2;
51 extern uint32_t* g_perm_sample_to_cluster;
52 extern uint32_t* g_perm_qt_cluster_thread_wkspace;
53
54 extern double* g_perm_pmajor;
55 extern uint32_t* g_perm_precomputed_mods; // [n] = 2^32 mod (n-2)
56
57 void generate_cc_perm_vec(uint32_t tot_ct, uint32_t set_ct, uint32_t tot_quotient, uint64_t totq_magic, uint32_t totq_preshift, uint32_t totq_postshift, uint32_t totq_incr, uintptr_t* perm_vec, sfmt_t* sfmtp);
58
59 void generate_cc_perm1(uint32_t tot_ct, uint32_t set_ct, uint32_t tot_quotient, uint64_t totq_magic, uint32_t totq_preshift, uint32_t totq_postshift, uint32_t totq_incr, uintptr_t* perm_vec, sfmt_t* sfmtp);
60
61 void generate_cc_cluster_perm_vec(uint32_t tot_ct, uintptr_t* preimage, uint32_t cluster_ct, uint32_t* cluster_map, uint32_t* cluster_starts, uint32_t* cluster_case_cts, uint32_t* tot_quotients, uint64_t* totq_magics, uint32_t* totq_preshifts, uint32_t* totq_postshifts, uint32_t* totq_incrs, uintptr_t* perm_vec, sfmt_t* sfmtp);
62
63 void generate_cc_cluster_perm1(uint32_t tot_ct, uintptr_t* preimage, uint32_t cluster_ct, uint32_t* cluster_map, uint32_t* cluster_starts, uint32_t* cluster_case_cts, uint32_t* tot_quotients, uint64_t* totq_magics, uint32_t* totq_preshifts, uint32_t* totq_postshifts, uint32_t* totq_incrs, uintptr_t* perm_vec, sfmt_t* sfmtp);
64
65 THREAD_RET_TYPE generate_cc_perms_thread(void* arg);
66
67 THREAD_RET_TYPE generate_cc_cluster_perms_thread(void* arg);
68
69 THREAD_RET_TYPE generate_qt_perms_smajor_thread(void* arg);
70
71 THREAD_RET_TYPE generate_qt_cluster_perms_smajor_thread(void* arg);
72
73 THREAD_RET_TYPE generate_qt_perms_pmajor_thread(void* arg);
74
75 THREAD_RET_TYPE generate_qt_cluster_perms_pmajor_thread(void* arg);
76
77 // Efficient "vertical popcount" support.
78 void transpose_perms(uintptr_t* perm_vecs, uint32_t perm_vec_ct, uint32_t pheno_nm_ct, uint32_t* perm_vecst);
79
80 void transpose_perm1s(uintptr_t* perm_vecs, uint32_t perm_vec_ct, uint32_t pheno_nm_ct, uint32_t* perm_vecst);
81
82 #ifdef __LP64__
83 HEADER_INLINE void unroll_incr_1_4(const __m128i* acc1, __m128i* acc4, uint32_t acc1_vec_ct) {
84 const __m128i m1x4 = {0x1111111111111111LLU, 0x1111111111111111LLU};
85 __m128i loader;
86 uint32_t vidx;
87 for (vidx = 0; vidx < acc1_vec_ct; vidx++) {
88 loader = *acc1++;
89 *acc4 = _mm_add_epi64(*acc4, _mm_and_si128(loader, m1x4));
90 acc4++;
91 loader = _mm_srli_epi64(loader, 1);
92 *acc4 = _mm_add_epi64(*acc4, _mm_and_si128(loader, m1x4));
93 acc4++;
94 loader = _mm_srli_epi64(loader, 1);
95 *acc4 = _mm_add_epi64(*acc4, _mm_and_si128(loader, m1x4));
96 acc4++;
97 loader = _mm_srli_epi64(loader, 1);
98 *acc4 = _mm_add_epi64(*acc4, _mm_and_si128(loader, m1x4));
99 acc4++;
100 }
101 }
102
103 HEADER_INLINE void unroll_incr_4_8(const __m128i* acc4, __m128i* acc8, uint32_t acc4_vec_ct) {
104 const __m128i m4 = {0x0f0f0f0f0f0f0f0fLLU, 0x0f0f0f0f0f0f0f0fLLU};
105 __m128i loader;
106 uint32_t vidx;
107 for (vidx = 0; vidx < acc4_vec_ct; vidx++) {
108 loader = *acc4++;
109 *acc8 = _mm_add_epi64(*acc8, _mm_and_si128(loader, m4));
110 acc8++;
111 loader = _mm_srli_epi64(loader, 4);
112 *acc8 = _mm_add_epi64(*acc8, _mm_and_si128(loader, m4));
113 acc8++;
114 }
115 }
116
117 HEADER_INLINE void unroll_zero_incr_4_8(__m128i* acc4, __m128i* acc8, uint32_t acc4_vec_ct) {
118 const __m128i m4 = {0x0f0f0f0f0f0f0f0fLLU, 0x0f0f0f0f0f0f0f0fLLU};
119 __m128i loader;
120 uint32_t vidx;
121 for (vidx = 0; vidx < acc4_vec_ct; vidx++) {
122 loader = *acc4;
123 *acc4++ = _mm_setzero_si128();
124 *acc8 = _mm_add_epi64(*acc8, _mm_and_si128(loader, m4));
125 acc8++;
126 loader = _mm_srli_epi64(loader, 4);
127 *acc8 = _mm_add_epi64(*acc8, _mm_and_si128(loader, m4));
128 acc8++;
129 }
130 }
131
132 HEADER_INLINE void unroll_incr_8_32(const __m128i* acc8, __m128i* acc32, uint32_t acc8_vec_ct) {
133 const __m128i m8x32 = {0x000000ff000000ffLLU, 0x000000ff000000ffLLU};
134 __m128i loader;
135 uint32_t vidx;
136 for (vidx = 0; vidx < acc8_vec_ct; vidx++) {
137 loader = *acc8++;
138 *acc32 = _mm_add_epi64(*acc32, _mm_and_si128(loader, m8x32));
139 acc32++;
140 loader = _mm_srli_epi64(loader, 8);
141 *acc32 = _mm_add_epi64(*acc32, _mm_and_si128(loader, m8x32));
142 acc32++;
143 loader = _mm_srli_epi64(loader, 8);
144 *acc32 = _mm_add_epi64(*acc32, _mm_and_si128(loader, m8x32));
145 acc32++;
146 loader = _mm_srli_epi64(loader, 8);
147 *acc32 = _mm_add_epi64(*acc32, _mm_and_si128(loader, m8x32));
148 acc32++;
149 }
150 }
151
152 HEADER_INLINE void unroll_zero_incr_8_32(__m128i* acc8, __m128i* acc32, uint32_t acc8_vec_ct) {
153 const __m128i m8x32 = {0x000000ff000000ffLLU, 0x000000ff000000ffLLU};
154 __m128i loader;
155 uint32_t vidx;
156 for (vidx = 0; vidx < acc8_vec_ct; vidx++) {
157 loader = *acc8;
158 *acc8++ = _mm_setzero_si128();
159 *acc32 = _mm_add_epi64(*acc32, _mm_and_si128(loader, m8x32));
160 acc32++;
161 loader = _mm_srli_epi64(loader, 8);
162 *acc32 = _mm_add_epi64(*acc32, _mm_and_si128(loader, m8x32));
163 acc32++;
164 loader = _mm_srli_epi64(loader, 8);
165 *acc32 = _mm_add_epi64(*acc32, _mm_and_si128(loader, m8x32));
166 acc32++;
167 loader = _mm_srli_epi64(loader, 8);
168 *acc32 = _mm_add_epi64(*acc32, _mm_and_si128(loader, m8x32));
169 acc32++;
170 }
171 }
172 #else
173 HEADER_INLINE void unroll_incr_1_4(const uintptr_t* acc1, uintptr_t* acc4, uint32_t acc1_word_ct) {
174 uint32_t widx;
175 uintptr_t loader;
176 for (widx = 0; widx < acc1_word_ct; widx++) {
177 loader = *acc1++;
178 *acc4 += loader & 0x11111111U;
179 acc4++;
180 loader >>= 1;
181 *acc4 += loader & 0x11111111U;
182 acc4++;
183 loader >>= 1;
184 *acc4 += loader & 0x11111111U;
185 acc4++;
186 loader >>= 1;
187 *acc4 += loader & 0x11111111U;
188 acc4++;
189 }
190 }
191
192 HEADER_INLINE void unroll_incr_4_8(const uintptr_t* acc4, uintptr_t* acc8, uint32_t acc4_word_ct) {
193 uint32_t widx;
194 uintptr_t loader;
195 for (widx = 0; widx < acc4_word_ct; widx++) {
196 loader = *acc4++;
197 *acc8 += loader & 0x0f0f0f0fU;
198 acc8++;
199 loader >>= 4;
200 *acc8 += loader & 0x0f0f0f0fU;
201 acc8++;
202 }
203 }
204
205 HEADER_INLINE void unroll_zero_incr_4_8(uintptr_t* acc4, uintptr_t* acc8, uint32_t acc4_word_ct) {
206 uint32_t widx;
207 uintptr_t loader;
208 for (widx = 0; widx < acc4_word_ct; widx++) {
209 loader = *acc4;
210 *acc4++ = 0;
211 *acc8 += loader & 0x0f0f0f0fU;
212 acc8++;
213 loader >>= 4;
214 *acc8 += loader & 0x0f0f0f0fU;
215 acc8++;
216 }
217 }
218
219 HEADER_INLINE void unroll_incr_8_32(const uintptr_t* acc8, uintptr_t* acc32, uint32_t acc8_word_ct) {
220 uint32_t widx;
221 uintptr_t loader;
222 for (widx = 0; widx < acc8_word_ct; widx++) {
223 loader = *acc8++;
224 *acc32 += (uint8_t)loader;
225 acc32++;
226 loader >>= 8;
227 *acc32 += (uint8_t)loader;
228 acc32++;
229 loader >>= 8;
230 *acc32 += (uint8_t)loader;
231 acc32++;
232 loader >>= 8;
233 *acc32 += loader;
234 acc32++;
235 }
236 }
237
238 HEADER_INLINE void unroll_zero_incr_8_32(uintptr_t* acc8, uintptr_t* acc32, uint32_t acc8_word_ct) {
239 uint32_t widx;
240 uintptr_t loader;
241 for (widx = 0; widx < acc8_word_ct; widx++) {
242 loader = *acc8;
243 *acc8++ = 0;
244 *acc32 += (uint8_t)loader;
245 acc32++;
246 loader >>= 8;
247 *acc32 += (uint8_t)loader;
248 acc32++;
249 loader >>= 8;
250 *acc32 += (uint8_t)loader;
251 acc32++;
252 loader >>= 8;
253 *acc32 += loader;
254 acc32++;
255 }
256 }
257 #endif
258
259 int32_t make_perm_pheno(pthread_t* threads, char* outname, char* outname_end, uintptr_t unfiltered_sample_ct, uintptr_t* sample_exclude, uintptr_t sample_ct, char* sample_ids, uintptr_t max_sample_id_len, uint32_t cluster_ct, uint32_t* cluster_map, uint32_t* cluster_starts, uint32_t pheno_nm_ct, uintptr_t* pheno_nm, uintptr_t* pheno_c, double* pheno_d, char* output_missing_pheno, uint32_t permphe_ct);
260
261 #endif // __PLINK_PERM_H__