• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MikkelSchubert / adapterremoval / #45

20 Sep 2024 06:49PM UTC coverage: 26.244% (-49.2%) from 75.443%
#45

push

travis-ci

web-flow
attempt to fix coveralls run

2458 of 9366 relevant lines covered (26.24%)

4362.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/simd_avx512bw.cpp
1
/*************************************************************************\
2
 * AdapterRemoval - cleaning next-generation sequencing reads            *
3
 *                                                                       *
4
 * Copyright (C) 2024 by Mikkel Schubert - mikkelsch@gmail.com           *
5
 *                                                                       *
6
 * This program is free software: you can redistribute it and/or modify  *
7
 * it under the terms of the GNU General Public License as published by  *
8
 * the Free Software Foundation, either version 3 of the License, or     *
9
 * (at your option) any later version.                                   *
10
 *                                                                       *
11
 * This program is distributed in the hope that it will be useful,       *
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 * GNU General Public License for more details.                          *
15
 *                                                                       *
16
 * You should have received a copy of the GNU General Public License     *
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. *
18
\*************************************************************************/
19
#include "simd.hpp"    // declarations
20
#include <bitset>      // for bitset
21
#include <cstddef>     // for size_t
22
#include <immintrin.h> // for _mm512_set1_epi8, __m512i, _mm512_lo...
23

24
#if defined(MESON) || __GNUC__ >= 11 ||                                        \
25
  (defined(__clang_major__) && __clang_major__ >= 8)
26

27
namespace adapterremoval {
28

29
namespace simd {
30

31
namespace {
32

33
/** Counts the number of masked bytes **/
34
inline auto
35
count_masked_avx512(__mmask64 value)
×
36
{
37
  // Generate 64 bit mask from most significant bits of each byte and count bits
38
  return std::bitset<64>(value).count();
×
39
}
40

41
} // namespace
42

43
bool
44
compare_subsequences_avx512(size_t& n_mismatches,
×
45
                            size_t& n_ambiguous,
46
                            const char* seq_1,
47
                            const char* seq_2,
48
                            size_t length,
49
                            size_t max_penalty)
50
{
51
  //! Mask of all Ns
52
  const auto n_mask = _mm512_set1_epi8('N');
×
53

54
  while (length) {
×
55
    __m512i s1;
×
56
    __m512i s2;
×
57

58
    if (length < 64) {
×
59
      const auto mask = 0xFFFFFFFFFFFFFFFFLLU >> (64 - length);
×
60
      s1 = _mm512_maskz_loadu_epi8(mask, seq_1);
×
61
      s2 = _mm512_maskz_loadu_epi8(mask, seq_2);
×
62

63
      length = 0;
×
64
    } else {
65
      s1 = _mm512_loadu_epi8(seq_1);
×
66
      s2 = _mm512_loadu_epi8(seq_2);
×
67

68
      seq_1 += 64;
×
69
      seq_2 += 64;
×
70
      length -= 64;
×
71
    }
72

73
    // Sets 0xFF for every byte where one or both nts is N
74
    const auto ns_mask =
×
75
      _mm512_cmpeq_epu8_mask(s1, n_mask) | _mm512_cmpeq_epu8_mask(s2, n_mask);
×
76

77
    // Sets 0xFF for every byte where bytes are equal or N
78
    const auto eq_mask = _mm512_cmpeq_epu8_mask(s1, s2) | ns_mask;
×
79

80
    n_mismatches += 64 - count_masked_avx512(eq_mask);
×
81
    if (2 * n_mismatches + n_ambiguous > max_penalty) {
×
82
      return false;
83
    }
84

85
    // Early termination is almost always due to mismatches, so updating the
86
    // number of Ns after the above check saves time in the common case.
87
    n_ambiguous += count_masked_avx512(ns_mask);
×
88
  }
89

90
  return true;
91
}
92

93
} // namespace simd
94

95
} // namespace adapterremoval
96

97
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc