From cc7ef8c4101a52a823ce226cdaa812b86a8e8226 Mon Sep 17 00:00:00 2001
From: "se.gorbunov" <se.gorbunov@gsi.de>
Date: Tue, 6 Sep 2022 00:31:28 +0000
Subject: [PATCH] L1: SIMD vectors: remove IsHorizontallyEqual()

---
 reco/L1/L1Algo/L1Field.cxx    | 23 +++--------------------
 reco/L1/L1Algo/L1Utils.h      |  6 +++++-
 reco/L1/vectors/L1vecPseudo.h | 15 ---------------
 reco/L1/vectors/L1vecVc.h     | 15 ---------------
 4 files changed, 8 insertions(+), 51 deletions(-)

diff --git a/reco/L1/L1Algo/L1Field.cxx b/reco/L1/L1Algo/L1Field.cxx
index 15d8df849d..d2591e1a4c 100644
--- a/reco/L1/L1Algo/L1Field.cxx
+++ b/reco/L1/L1Algo/L1Field.cxx
@@ -67,26 +67,9 @@ void L1FieldSlice::CheckConsistency() const
 {
   /* Check SIMD data vectors for consistent initialization */
   for (int i = 0; i < L1Constants::size::kMaxNFieldApproxCoefficients; ++i) {
-    if (!IsHorizontallyEqual(cx[i])) {
-      std::stringstream msg;
-      msg << "L1FieldSlice: \"cx[" << i
-          << "]\" SIMD vector is inconsistent not all of the words are equal each other: " << cx[i];
-      throw std::logic_error(msg.str());
-    }
-
-    if (!IsHorizontallyEqual(cy[i])) {
-      std::stringstream msg;
-      msg << "L1FieldSlice: \"cy[" << i
-          << "]\" SIMD vector is inconsistent not all of the words are equal each other: " << cy[i];
-      throw std::logic_error(msg.str());
-    }
-
-    if (!IsHorizontallyEqual(cz[i])) {
-      std::stringstream msg;
-      msg << "L1FieldSlice: \"cz[" << i
-          << "]\" SIMD vector is inconsistent not all of the words are equal each other: " << cz[i];
-      throw std::logic_error(msg.str());
-    }
+    L1Utils::CheckSimdVectorEquality(cx[i], "L1FieldSlice: cx");
+    L1Utils::CheckSimdVectorEquality(cy[i], "L1FieldSlice: cy");
+    L1Utils::CheckSimdVectorEquality(cz[i], "L1FieldSlice: cz");
   }
 }
 
diff --git a/reco/L1/L1Algo/L1Utils.h b/reco/L1/L1Algo/L1Utils.h
index 740c713c86..305d502580 100644
--- a/reco/L1/L1Algo/L1Utils.h
+++ b/reco/L1/L1Algo/L1Utils.h
@@ -44,7 +44,11 @@ namespace L1Utils
 
   [[gnu::always_inline]] inline void CheckSimdVectorEquality(fvec v, const char* name)
   {
-    if (!IsHorizontallyEqual(v)) {
+    bool ok = true;
+    for (size_t i = 1; i < fvec::size(); i++) {
+      ok = ok && (v[i] == v[0]);
+    }
+    if (!ok) {
       std::stringstream msg;
       msg << name << " SIMD vector is inconsistent, not all of the words are equal each other: " << v;
       throw std::logic_error(msg.str());
diff --git a/reco/L1/vectors/L1vecPseudo.h b/reco/L1/vectors/L1vecPseudo.h
index 201b8dc4f7..f8b5e22bad 100644
--- a/reco/L1/vectors/L1vecPseudo.h
+++ b/reco/L1/vectors/L1vecPseudo.h
@@ -272,21 +272,6 @@ public:
 
 #define _fvecalignment __attribute__((aligned(fvec::size() * sizeof(fscal))))
 
-
-/// Checks, if all bands are equal
-/// NOTE: two values defined as signaling_NaN() are not equal, thus if there are all or one
-/// of the words are kNaN, the function returns false
-inline bool IsHorizontallyEqual(const fvec& v)
-{
-  fscal s  = v[0];
-  bool ret = true;
-  for (int i = 1; i < fvec::size(); i++) {
-    ret = ret && (v[i] == s);
-  }
-  return ret;
-}
-
-
 #include "std_alloc.h"
 
 #endif
diff --git a/reco/L1/vectors/L1vecVc.h b/reco/L1/vectors/L1vecVc.h
index b0d3c16863..b38e36bc45 100644
--- a/reco/L1/vectors/L1vecVc.h
+++ b/reco/L1/vectors/L1vecVc.h
@@ -25,21 +25,6 @@ inline fvec operator+(const fvec& a, fscal b) { return a + fvec(b); }
 inline fvec operator-(fscal a, const fvec& b) { return fvec(a) - b; }
 inline fvec operator-(const fvec& a, fscal b) { return a - fvec(b); }
 
-
-/// Checks, if all bands are equal
-/// NOTE: two values defined as signaling_NaN() are not equal, thus if there are all or one
-/// of the words are kNaN, the function returns false
-inline bool IsHorizontallyEqual(const fvec& v)
-{
-  fscal s  = v[0];
-  bool ret = true;
-  for (size_t i = 1; i < fvec::size(); i++) {
-    ret = ret && (v[i] == s);
-  }
-  return ret;
-}
-
-
 #include "std_alloc.h"
 
 
-- 
GitLab