Skip to content

Commit

Permalink
fix --glm bug in previous build
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchang committed Sep 21, 2023
1 parent 811043f commit 271f266
Show file tree
Hide file tree
Showing 10 changed files with 545 additions and 36 deletions.
10 changes: 10 additions & 0 deletions 2.0/include/plink2_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,11 @@ HEADER_INLINE VecUc vecuc_setr8x(char e31, char e30, char e29, char e28, char e2
return VecToUc(_mm256_setr_epi8(e31, e30, e29, e28, e27, e26, e25, e24, e23, e22, e21, e20, e19, e18, e17, e16, e15, e14, e13, e12, e11, e10, e9, e8, e7, e6, e5, e4, e3, e2, e1, e0));
}

HEADER_INLINE VecW vecw_setr32(uint32_t e3, uint32_t e2, uint32_t e1, uint32_t e0) {
return VecToW(_mm256_setr_epi32(e3, e2, e1, e0, e3, e2, e1, e0));
}


HEADER_INLINE VecW vecw_unpacklo8(VecW evens, VecW odds) {
return VecToW(_mm256_unpacklo_epi8(WToVec(evens), WToVec(odds)));
}
Expand Down Expand Up @@ -1456,6 +1461,10 @@ HEADER_INLINE VecUc vecuc_setr8x(
return VecToUc(_mm_setr_epi8(e31, e30, e29, e28, e27, e26, e25, e24, e23, e22, e21, e20, e19, e18, e17, e16));
}

HEADER_INLINE VecW vecw_setr32(uint32_t e3, uint32_t e2, uint32_t e1, uint32_t e0) {
return VecToW(_mm_setr_epi32(e3, e2, e1, e0));
}

HEADER_INLINE VecW vecw_unpacklo8(VecW evens, VecW odds) {
return VecToW(_mm_unpacklo_epi8(WToVec(evens), WToVec(odds)));
}
Expand Down Expand Up @@ -1818,6 +1827,7 @@ CONSTI32(kBitsPerVec, kBytesPerVec * CHAR_BIT);
// We now use Knuth's Nyp/Nybble vocabulary for 2-bit and 4-bit elements,
// respectively.
CONSTI32(kNypsPerVec, kBytesPerVec * 4);
CONSTI32(kNybblesPerVec, kBytesPerVec * 2);

CONSTI32(kBitsPerWordD2, kBitsPerWord / 2);
CONSTI32(kBitsPerWordD4, kBitsPerWord / 4);
Expand Down
14 changes: 14 additions & 0 deletions 2.0/include/plink2_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,20 @@ HEADER_INLINE void ClearNyparrEntry(uint32_t idx, uintptr_t* nyparr) {
nyparr[idx / kBitsPerWordD2] &= ~((3 * k1LU) << (idx % kBitsPerWordD2));
}

HEADER_CINLINE uintptr_t NybbleCtToVecCt(uintptr_t val) {
return DivUp(val, kNybblesPerVec);
}

HEADER_CINLINE uintptr_t NybbleCtToAlignedWordCt(uintptr_t val) {
return kWordsPerVec * NybbleCtToVecCt(val);
}

HEADER_INLINE void AssignNybblearrEntry(uint32_t idx, uintptr_t newval, uintptr_t* nybblearr) {
const uint32_t bit_shift_ct = 4 * (idx % kBitsPerWordD4);
uintptr_t* wordp = &(nybblearr[idx / kBitsPerWordD4]);
*wordp = ((*wordp) & (~((15 * k1LU) << bit_shift_ct))) | (newval << bit_shift_ct);
}

// 'Unsafe' because it assumes high bits of every byte are 0 and entry_ct is
// positive.
void Reduce8to4bitInplaceUnsafe(uintptr_t entry_ct, uintptr_t* mainvec);
Expand Down
50 changes: 34 additions & 16 deletions 2.0/plink2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static const char ver_str[] = "PLINK v2.00a5"
#elif defined(USE_AOCL)
" AMD"
#endif
" (19 Sep 2023)";
" (21 Sep 2023)";
static const char ver_str2[] =
// include leading space if day < 10, so character length stays the same
""
Expand Down Expand Up @@ -3103,8 +3103,16 @@ void GetExportfTargets(const char* const* argvk, uint32_t param_ct, ExportfFlags
}
break;
case 'p':
if (!strcmp(cur_modif2, "ed")) {
cur_format = kfExportfPed;
{
const uint32_t cur_modif2_slen = strlen(cur_modif2);
if (strequal_k(cur_modif2, "ed", cur_modif2_slen)) {
cur_format = kfExportfPed;
} else if (strequal_k(cur_modif2, "hylip", cur_modif2_slen)) {
cur_format = kfExportfPhylip;
} else if (strequal_k(cur_modif2, "hylip-phased", cur_modif2_slen)) {
cur_format = kfExportfPhylipPhased;
}
break;
}
break;
case 'r':
Expand Down Expand Up @@ -5178,6 +5186,14 @@ int main(int argc, char** argv) {
logerrputs("Error: Multiple --export bgen versions.\n");
goto main_ret_INVALID_CMDLINE;
}
if (unlikely((pc.exportf_info.flags & kfExportfVcf) == kfExportfVcf)) {
logerrputs("Error: 'vcf' and 'vcf-4.2' formats cannot be exported simultaneously.\n");
goto main_ret_INVALID_CMDLINE_A;
}
if (unlikely((pc.exportf_info.flags & kfExportfBcf) == kfExportfBcf)) {
logerrputs("Error: 'bcf' and 'bcf-4.2' formats cannot be exported simultaneously.\n");
goto main_ret_INVALID_CMDLINE_A;
}
if (unlikely((pc.exportf_info.flags & (kfExportfHaps | kfExportfHapsLegend)) == (kfExportfHaps | kfExportfHapsLegend))) {
logerrputs("Error: 'haps' and 'hapslegend' formats cannot be exported simultaneously.\n");
goto main_ret_INVALID_CMDLINE;
Expand All @@ -5194,6 +5210,10 @@ int main(int argc, char** argv) {
logerrputs("Error: 'ped' and 'compound-genotypes' formats cannot be exported\nsimultaneously.\n");
goto main_ret_INVALID_CMDLINE;
}
if (unlikely((pc.exportf_info.flags & (kfExportfPhylip | kfExportfPhylipPhased)) == (kfExportfPhylip | kfExportfPhylipPhased))) {
logerrputs("Error: --export 'phylip' and 'phylip-phased' formats cannot be exported\nsimultaneously.\n");
goto main_ret_INVALID_CMDLINE_A;
}
for (uint32_t param_idx = 1; param_idx <= param_ct; ++param_idx) {
// could use AdvBoundedTo0Bit()...
if ((format_param_idxs >> param_idx) & 1) {
Expand Down Expand Up @@ -5298,8 +5318,8 @@ int main(int argc, char** argv) {
snprintf(g_logbuf, kLogbufSize, "Error: The '%s' modifier does not apply to --export's A and AD output formats.\n", cur_modif);
goto main_ret_INVALID_CMDLINE_2A;
}
if (unlikely(pc.exportf_info.flags & (kfExportfVcf | kfExportfBcf))) {
logerrputs("Error: '01'/'12' cannot be used with --export's vcf or bcf output formats.\n");
if (unlikely(pc.exportf_info.flags & (kfExportfVcf | kfExportfBcf | kfExportfPhylip | kfExportfPhylipPhased))) {
logerrputs("Error: '01'/'12' cannot be used with --export's vcf, bcf, phylip, or\nphylip-phased output formats.\n");
goto main_ret_INVALID_CMDLINE_A;
}
if (cur_modif[0] == '0') {
Expand Down Expand Up @@ -5329,6 +5349,12 @@ int main(int argc, char** argv) {
goto main_ret_INVALID_CMDLINE_A;
}
pc.exportf_info.flags |= kfExportfSampleV2;
} else if (strequal_k(cur_modif, "used-sites", cur_modif_slen)) {
if (unlikely(!(pc.exportf_info.flags & (kfExportfPhylip | kfExportfPhylipPhased)))) {
logerrputs("Error: 'used-sites' modifier only applies to --export's phylip and\nphylip-phased output formats.\n");
goto main_ret_INVALID_CMDLINE_A;
}
pc.exportf_info.flags |= kfExportfPhylipUsedSites;
} else if (strequal_k(cur_modif, "ref-last", cur_modif_slen)) {
// do nothing for now
} else if (likely(strequal_k(cur_modif, "ref-first", cur_modif_slen))) {
Expand All @@ -5344,21 +5370,13 @@ int main(int argc, char** argv) {
goto main_ret_INVALID_CMDLINE_WWA;
}
}
if ((pc.exportf_info.flags & kfExportfVcf) == kfExportfVcf) {
logerrputs("Error: --export 'vcf' and 'vcf-4.2' cannot be used together.\n");
goto main_ret_INVALID_CMDLINE_A;
}
if ((pc.exportf_info.flags & kfExportfBcf) == kfExportfBcf) {
logerrputs("Error: --export 'bcf' and 'bcf-4.2' cannot be used together.\n");
goto main_ret_INVALID_CMDLINE_A;
}
if (pc.exportf_info.idpaste_flags || pc.exportf_info.id_delim) {
if (unlikely(!(pc.exportf_info.flags & (kfExportfVcf | kfExportfBcf | kfExportfBgen12 | kfExportfBgen13 | kfExportfSampleV2)))) {
logerrputs("Error: The 'id-delim' and 'id-paste' modifiers only apply to --export's vcf,\nbcf, bgen-1.2, bgen-1.3, and sample-v2 output formats.\n");
if (unlikely(!(pc.exportf_info.flags & (kfExportfVcf | kfExportfBcf | kfExportfBgen12 | kfExportfBgen13 | kfExportfSampleV2 | kfExportfPhylip | kfExportfPhylipPhased)))) {
logerrputs("Error: The 'id-delim' and 'id-paste' modifiers only apply to --export's vcf,\nbcf, bgen-1.2, bgen-1.3, sample-v2, phylip, and phylip-phased output formats.\n");
goto main_ret_INVALID_CMDLINE_A;
}
}
if (pc.exportf_info.flags & (kfExportfVcf | kfExportfBcf | kfExportfBgen12 | kfExportfBgen13 | kfExportfSampleV2)) {
if (pc.exportf_info.flags & (kfExportfVcf | kfExportfBcf | kfExportfBgen12 | kfExportfBgen13 | kfExportfSampleV2 | kfExportfPhylip | kfExportfPhylipPhased)) {
if (!pc.exportf_info.idpaste_flags) {
pc.exportf_info.idpaste_flags = kfIdpasteDefault;
}
Expand Down
19 changes: 11 additions & 8 deletions 2.0/plink2_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,19 @@ FLAGSET64_DEF_START()
kfExportfOxGen = kfExportfOxGenV1 | kfExportfOxGenV2,
kfExportfPed = (1 << 30),
kfExportfCompound = (1U << 31),
kfExportfStructure = (1LLU << 32),
kfExportfTped = (1LLU << 33),
kfExportfVcf42 = (1LLU << 34),
kfExportfVcf43 = (1LLU << 35),
kfExportfPhylip = (1LLU << 32),
kfExportfPhylipPhased = (1LLU << 33),
kfExportfStructure = (1LLU << 34),
kfExportfTped = (1LLU << 35),
kfExportfVcf42 = (1LLU << 36),
kfExportfVcf43 = (1LLU << 37),
kfExportfVcf = kfExportfVcf42 | kfExportfVcf43,
kfExportfTypemask = (2LLU * kfExportfVcf43) - kfExportf23,
kfExportfIncludeAlt = (1LLU << 36),
kfExportfBgz = (1LLU << 37),
kfExportfOmitNonmaleY = (1LLU << 38),
kfExportfSampleV2 = (1LLU << 39)
kfExportfIncludeAlt = (1LLU << 38),
kfExportfBgz = (1LLU << 39),
kfExportfOmitNonmaleY = (1LLU << 40),
kfExportfSampleV2 = (1LLU << 41),
kfExportfPhylipUsedSites = (1LLU << 42)
FLAGSET64_DEF_END(ExportfFlags);

FLAGSET_DEF_START()
Expand Down
3 changes: 2 additions & 1 deletion 2.0/plink2_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5662,7 +5662,8 @@ THREAD_FUNC_DECL MakePgenThread(void* raw_arg) {
loaded_vrtype = loaded_vrtypes[write_idx];
}
if (write_idx >= chr_end_bidx) {
const uint32_t chr_fo_idx = LastLeqU32(write_chr_fo_vidx_start, 0, cip->chr_ct, write_idx + variant_idx_offset);
// const uint32_t chr_fo_idx = LastLeqU32(write_chr_fo_vidx_start, 0, cip->chr_ct, write_idx + variant_idx_offset);
const uint32_t chr_fo_idx = LowerBoundNonemptyU32(&(write_chr_fo_vidx_start[1]), cip->chr_ct, write_idx + variant_idx_offset + 1);
const uint32_t chr_idx = cip->chr_file_order[chr_fo_idx];
chr_end_bidx = write_chr_fo_vidx_start[chr_fo_idx + 1] - variant_idx_offset;
is_x = (chr_idx == x_code);
Expand Down
Loading

0 comments on commit 271f266

Please sign in to comment.