Skip to content

Commit

Permalink
fix --ld bug introduced in previous build
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchang committed Sep 14, 2023
1 parent d1f341a commit e553529
Show file tree
Hide file tree
Showing 10 changed files with 920 additions and 123 deletions.
10 changes: 10 additions & 0 deletions 2.0/include/pgenlib_misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2837,6 +2837,16 @@ void ClearGenoarrMissing1bit16Unsafe(const uintptr_t* __restrict genoarr, uint32
}
}

double u127prod_diff_d(uint64_t plus_term0, uint64_t plus_term1, uint64_t minus_term0, uint64_t minus_term1) {
uint64_t plus_hi;
const uint64_t plus_lo = multiply64to128(plus_term0, plus_term1, &plus_hi);
uint64_t minus_hi;
const uint64_t minus_lo = multiply64to128(minus_term0, minus_term1, &minus_hi);
const uint64_t result_lo = plus_lo - minus_lo;
const uint64_t result_hi = plus_hi - minus_hi - (plus_lo < minus_lo);
return u127tod(result_hi, result_lo);
}

double MultiallelicDiploidMinimac3R2(const uint64_t* __restrict sums, const uint64_t* __restrict hap_ssqs_x2, uint32_t nm_sample_ct, uint32_t allele_ct, uint32_t extra_phased_het_ct) {
// sums[k] == sum_i [left_dosage_{ik} + right_dosage_{ik}]
// hap_ssqs_x2[k] ==
Expand Down
14 changes: 11 additions & 3 deletions 2.0/include/pgenlib_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,10 @@ HEADER_INLINE void SetTrailingNyps(uintptr_t nyp_ct, uintptr_t* bitarr) {
// GetVint31 and Vint32Append moved to plink2_base.

// Input must be validated, or bufp must be >= 5 characters before the end of
// the read buffer. Currently unused.
// the read buffer.
// todo: check if this has enough of a speed advantage over GetVint31() to
// justify using this in the main loops and catching SIGSEGV. (seems to be no
// more than 3%?)
/*
HEADER_INLINE uint32_t GetVint31Unsafe(const unsigned char** buf_iterp) {
uint32_t vint32 = *(*buf_iterp)++;
if (vint32 <= 127) {
Expand All @@ -261,7 +260,13 @@ HEADER_INLINE uint32_t GetVint31Unsafe(const unsigned char** buf_iterp) {
}
return 0x80000000U;
}
*/

HEADER_INLINE void SkipVintUnsafe(const unsigned char** buf_iterp) {
uint32_t cur_byte;
do {
cur_byte = *(*buf_iterp)++;
} while (cur_byte & 128);
}

// Does not update buf_iter.
HEADER_INLINE uint32_t PeekVint31(const unsigned char* buf_iter, const unsigned char* buf_end) {
Expand Down Expand Up @@ -562,6 +567,9 @@ HEADER_INLINE double u127tod(uint64_t hi, uint64_t lo) {
return u63tod(hi) * 18446744073709551616.0 + S_CAST(double, lo);
}

// plus_term0 * plus_term1 - minus_term0 * minus_term1
double u127prod_diff_d(uint64_t plus_term0, uint64_t plus_term1, uint64_t minus_term0, uint64_t minus_term1);

double MultiallelicDiploidMinimac3R2(const uint64_t* __restrict sums, const uint64_t* __restrict hap_ssqs_x2, uint32_t nm_sample_ct, uint32_t allele_ct, uint32_t extra_phased_het_ct);

HEADER_INLINE double MultiallelicDiploidMachR2(const uint64_t* __restrict sums, const uint64_t* __restrict ssqs, uint32_t nm_sample_ct, uint32_t allele_ct) {
Expand Down
10 changes: 10 additions & 0 deletions 2.0/include/plink2_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,16 @@ uintptr_t FirstUnequalW(const void* arr1, const void* arr2, uintptr_t nbytes) {
}
#endif

// TODO: obvious movemask optimization
uintptr_t CountVints(const unsigned char* buf, const unsigned char* buf_end) {
const uintptr_t len = buf_end - buf;
uintptr_t inv_result = 0;
for (uintptr_t ulii = 0; ulii != len; ++ulii) {
inv_result += buf[ulii] >> 7;
}
return len - inv_result;
}

#ifdef __cplusplus
} // namespace plink2
#endif
2 changes: 2 additions & 0 deletions 2.0/include/plink2_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -3991,6 +3991,8 @@ HEADER_INLINE uint32_t GetVint31(const unsigned char* buf_end, const unsigned ch
return 0x80000000U;
}

uintptr_t CountVints(const unsigned char* buf, const unsigned char* buf_end);

// Flagset conventions:
// * Each 32-bit and 64-bit flagset has its own type, which is guaranteed to be
// the appropriate width. (Todo: verify that bit 31 works properly in 32-bit
Expand Down
11 changes: 9 additions & 2 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
" (11 Sep 2023)";
" (13 Sep 2023)";
static const char ver_str2[] =
// include leading space if day < 10, so character length stays the same
""
Expand Down Expand Up @@ -4725,14 +4725,21 @@ int main(int argc, char** argv) {
logerrputs("Error: --clump-bins does not make sense when --clump 'bins' column set has been\nexcluded.\n");
goto main_ret_INVALID_CMDLINE_A;
}
if (unlikely(EnforceParamCtRange(argvk[arg_idx], param_ct, 1, 0x7fffffff))) {
// may as well enforce limit of 2^26 bin-bounds. this should never
// come up, and it lets us remove some bounds-checks.
if (unlikely(EnforceParamCtRange(argvk[arg_idx], param_ct, 1, kClumpMaxBinBounds))) {
goto main_ret_INVALID_CMDLINE_2A;
}
uint32_t comma_ct = 0;
for (uint32_t param_idx = 1; param_idx <= param_ct; ++param_idx) {
comma_ct += CountByteInStr(argvk[arg_idx], ',');
}
const uint32_t bin_bound_ct = comma_ct + param_ct;
if (bin_bound_ct > kClumpMaxBinBounds) {
logerrputs("Error: --clump-bins is currently limited to 2^26 bin boundaries.\n");
reterr = kPglRetNotYetSupported;
goto main_ret_1;
}
pc.clump_info.bin_bound_ct = bin_bound_ct;
if (unlikely(pgl_malloc(sizeof(double) * bin_bound_ct, &pc.clump_info.ln_bin_boundaries))) {
goto main_ret_NOMEM;
Expand Down
4 changes: 2 additions & 2 deletions 2.0/plink2_cmdline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ uintptr_t CountSortedLeqU64(const uint64_t* sorted_u64_arr, uintptr_t arr_length

uintptr_t IdxToUidxW(const uintptr_t* bitvec, const uintptr_t* cumulative_popcounts, uintptr_t widx_start, uintptr_t widx_end, uintptr_t idx) {
if (widx_end > widx_start) {
widx_start += CountSortedSmallerW(&(cumulative_popcounts[widx_start]), widx_end - widx_start, idx + 1);
widx_start += CountSortedSmallerW(&(cumulative_popcounts[widx_start]), widx_end - widx_start, idx + 1) - 1;
}
const uintptr_t idx_at_widx_start = cumulative_popcounts[widx_start];
return widx_start * kBitsPerWord + WordBitIdxToUidx(bitvec[widx_start], idx - idx_at_widx_start);
Expand All @@ -483,7 +483,7 @@ uintptr_t IdxToUidxW(const uintptr_t* bitvec, const uintptr_t* cumulative_popcou
uintptr_t ExpsearchIdxToUidxW(const uintptr_t* bitvec, const uintptr_t* cumulative_popcounts, uintptr_t widx_end, uintptr_t idx, uintptr_t* widx_startp) {
uintptr_t widx_start = *widx_startp;
if (widx_end > widx_start) {
widx_start += ExpsearchW(&(cumulative_popcounts[widx_start]), widx_end - widx_start, idx + 1);
widx_start += ExpsearchW(&(cumulative_popcounts[widx_start]), widx_end - widx_start, idx + 1) - 1;
*widx_startp = widx_start;
}
const uintptr_t idx_at_widx_start = cumulative_popcounts[widx_start];
Expand Down
2 changes: 0 additions & 2 deletions 2.0/plink2_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3208,7 +3208,6 @@ PglErr ParseChrRanges(const char* const* argvk, const char* flagname_p, const ch
return reterr;
}

/*
uint32_t MultiallelicVariantPresent(const uintptr_t* variant_include, const uintptr_t* allele_idx_offsets, uint32_t variant_ct) {
if (!allele_idx_offsets) {
return 0;
Expand All @@ -3223,7 +3222,6 @@ uint32_t MultiallelicVariantPresent(const uintptr_t* variant_include, const uint
}
return 0;
}
*/

uint32_t CountBiallelicVariants(const uintptr_t* variant_include, const uintptr_t* allele_idx_offsets, uint32_t variant_ct) {
if (!allele_idx_offsets) {
Expand Down
2 changes: 1 addition & 1 deletion 2.0/plink2_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ void CleanupPhenoCols(uint32_t pheno_ct, PhenoCol* pheno_cols);
PglErr ParseChrRanges(const char* const* argvk, const char* flagname_p, const char* errstr_append, uint32_t param_ct, uint32_t prohibit_extra_chrs, uint32_t xymt_subtract, char range_delim, ChrInfo* cip, uintptr_t* chr_mask);


// uint32_t MultiallelicVariantPresent(const uintptr_t* variant_include, const uintptr_t* allele_idx_offsets, uint32_t variant_ct);
uint32_t MultiallelicVariantPresent(const uintptr_t* variant_include, const uintptr_t* allele_idx_offsets, uint32_t variant_ct);

uint32_t CountBiallelicVariants(const uintptr_t* variant_include, const uintptr_t* allele_idx_offsets, uint32_t variant_ct);

Expand Down
Loading

0 comments on commit e553529

Please sign in to comment.