From f355192d5a44de2137609a25f0e48268877279e5 Mon Sep 17 00:00:00 2001
From: Martin Larralde <martin.larralde@embl.de>
Date: Fri, 21 Jun 2024 01:00:07 +0200
Subject: [PATCH] Fix AVX2 implementation of `Maximum::argmax`

---
 lightmotif/src/pli/dispatch.rs      | 1 -
 lightmotif/src/pli/platform/avx2.rs | 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/lightmotif/src/pli/dispatch.rs b/lightmotif/src/pli/dispatch.rs
index f6a4010..7fa8add 100644
--- a/lightmotif/src/pli/dispatch.rs
+++ b/lightmotif/src/pli/dispatch.rs
@@ -198,7 +198,6 @@ impl<A: Alphabet> Maximum<u8, <Dispatch as Backend>::LANES> for Pipeline<A, Disp
         scores: &StripedScores<u8, <Dispatch as Backend>::LANES>,
     ) -> Option<MatrixCoordinates> {
         match self.backend {
-            // FIXME !!!!
             #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
             Dispatch::Avx2 => Avx2::argmax_u8(scores),
             // #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
diff --git a/lightmotif/src/pli/platform/avx2.rs b/lightmotif/src/pli/platform/avx2.rs
index 8f90e9d..1e731f0 100644
--- a/lightmotif/src/pli/platform/avx2.rs
+++ b/lightmotif/src/pli/platform/avx2.rs
@@ -438,8 +438,8 @@ unsafe fn argmax_u8_avx2(
                 let r1 = _mm256_unpacklo_epi8(r, _mm256_setzero_si256());
                 let r2 = _mm256_unpackhi_epi8(r, _mm256_setzero_si256());
                 // compare scores to local maximums
-                let c1 = _mm256_or_si256(_mm256_cmpgt_epi16(r1, s1), _mm256_cmpeq_epi16(r1, s1));
-                let c2 = _mm256_or_si256(_mm256_cmpgt_epi16(r2, s2), _mm256_cmpeq_epi16(r2, s2));
+                let c1 = _mm256_cmpgt_epi16(s1, r1);
+                let c2 = _mm256_cmpgt_epi16(s2, r2);
                 // replace indices of new local maximums
                 p1 = _mm256_blendv_epi8(p1, index, c1);
                 p2 = _mm256_blendv_epi8(p2, index, c2);
-- 
GitLab