Skip to content

Commit

Permalink
Various CI compiler fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lczech committed Nov 12, 2024
1 parent d049f22 commit 0edac0d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/genesis/taxonomy/functions/kmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void assign_children_to_group_(
) {
// Get the data and assert that we are in the right type of taxon
auto& data = taxon.data<KmerTaxonData>();
assert( data.group_status = KmerTaxonData::GroupStatus::kAssigned );
assert( data.group_status == KmerTaxonData::GroupStatus::kAssigned );
assert( data.group_index != std::numeric_limits<size_t>::max() );

// In some previous iteration of the procedur, we already decided that this taxon here is
Expand Down Expand Up @@ -299,6 +299,10 @@ size_t group_with_target_number_of_groups( TaxonGroupingSearchParams const& para
// in which case we cannot get any closer to our target number of groups.
while( true ) {

// The current limit always is in between the low and high
assert( limit_l <= limit_c );
assert( limit_c <= limit_h );

// Construct groups with the current limits.
// Depending on whether the given params want us to modify the number of sequences,
// or their total combined length per group, we set the internal "limit" here, which can
Expand Down
11 changes: 9 additions & 2 deletions lib/genesis/utils/core/std.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ struct genesis_invoke_result
// container traits
// -------------------------------------------------------------------------

// Implement void_t for C++11.
// We are not using the C++17 version here, for simplicity.
template <typename...>
using void_t = void;

template <typename T, typename = void>
struct is_container : std::false_type {};

Expand All @@ -236,7 +241,7 @@ struct is_container : std::false_type {};
*/
template <typename T>
struct is_container<
T, std::void_t<
T, void_t<
typename T::value_type,
decltype(std::declval<T>().begin()),
decltype(std::declval<T>().end())
Expand All @@ -252,7 +257,9 @@ template <typename T, typename = void>
struct has_reserve : std::false_type {};

template <typename T>
struct has_reserve<T, std::void_t<decltype(std::declval<T&>().reserve(std::declval<size_t>()))>> : std::true_type {};
struct has_reserve<
T, void_t<decltype(std::declval<T&>().reserve(std::declval<size_t>()))>
> : std::true_type {};

// Convenience variable template for has_reserve trait
template <typename T>
Expand Down
3 changes: 3 additions & 0 deletions lib/genesis/utils/io/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ size_t parse_unsigned_integer_from_chars_( utils::InputStream& source )
using namespace utils;
T x = 0;

// If we want to use __builtin_mul_overflow here, we should check its existence first,
// using __has_builtin first. See genesis/utils/math/bit.hpp for examples.

// Hardcoded base 10. See below for other version that allows to select base.
auto raise_and_add_ = []( T& val, unsigned char c ) {
return !(
Expand Down
14 changes: 12 additions & 2 deletions lib/genesis/utils/math/bit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ namespace utils {
// Pop Count
// ================================================================================================

// Following the preprocessor documentation for __has_builtin
// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fbuiltin.html
#ifdef __has_builtin
# if __has_builtin(__builtin_popcount) && __has_builtin(__builtin_popcountl) && __has_builtin(__builtin_popcountll)
# define GENESIS_HAS_BUILTIN_POPCOUNT
# endif
#endif

/**
* @brief Compute the pop count (Hamming weight) of an unsigned int.
*/
template <typename T>
inline
#if defined(__cpp_lib_bitops) || (defined(__has_builtin) && __has_builtin(__builtin_popcountll))
#if defined(__cpp_lib_bitops) || defined(GENESIS_HAS_BUILTIN_POPCOUNT)
constexpr
#endif
typename std::enable_if<std::is_unsigned<T>::value, uint64_t>::type
Expand All @@ -75,7 +83,7 @@ pop_count( T n )
// https://en.cppreference.com/w/cpp/numeric/popcount
return std::popcount(n);

#elif defined(__has_builtin) && __has_builtin(__builtin_popcountll)
#elif defined(GENESIS_HAS_BUILTIN_POPCOUNT)

// Otherwise, use GCC/Clang intrinsic if available.
if (sizeof(T) <= sizeof(unsigned int)) {
Expand Down Expand Up @@ -112,6 +120,8 @@ pop_count( T n )
#endif
}

#undef GENESIS_HAS_BUILTIN_POPCOUNT

// ================================================================================================
// Bit Extract
// ================================================================================================
Expand Down

0 comments on commit 0edac0d

Please sign in to comment.