| 1 |
#ifndef __PLINK_PERM_H__ |
| 2 |
#define __PLINK_PERM_H__ |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 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; |
| 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 |
|
| 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 |