From 87d5a307953f237ca315a768a4d672279a20fabf Mon Sep 17 00:00:00 2001
From: "se.gorbunov" <se.gorbunov@gsi.de>
Date: Mon, 5 Sep 2022 23:31:28 +0000
Subject: [PATCH] L1: SIMD vectors: replace fabs() with abs()

---
 reco/L1/L1Algo/L1CATrackFinder.cxx                     |  8 ++++----
 reco/L1/L1Algo/L1ClonesMerger.cxx                      |  4 ++--
 reco/L1/L1Algo/L1FitMaterial.cxx                       |  2 +-
 reco/L1/L1Algo/L1TrackExtender.cxx                     |  6 +++---
 reco/L1/L1Algo/L1TrackFitter.cxx                       |  4 ++--
 reco/L1/L1Algo/L1TrackParFit.cxx                       |  2 +-
 .../CbmL1RichENNRingFinderParallel.cxx                 | 10 +++++-----
 reco/L1/ParticleFinder/CbmL1PFFitter.cxx               |  4 ++--
 reco/L1/vectors/L1vecPseudo.h                          |  2 --
 reco/L1/vectors/L1vecVc.h                              |  7 -------
 10 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/reco/L1/L1Algo/L1CATrackFinder.cxx b/reco/L1/L1Algo/L1CATrackFinder.cxx
index 6fde704c0b..cd27497548 100644
--- a/reco/L1/L1Algo/L1CATrackFinder.cxx
+++ b/reco/L1/L1Algo/L1CATrackFinder.cxx
@@ -407,8 +407,8 @@ inline void L1Algo::findDoubletsStep0(
     const float& time      = T1.t[i1_4];
 
     L1HitAreaTime areaTime(vGridTime[iStaM], T1.x[i1_4] * iz, T1.y[i1_4] * iz,
-                           (sqrt(Pick_m22 * (T1.C00 + stam.XYInfo.C00)) + fMaxDZ * fabs(T1.tx))[i1_4] * iz,
-                           (sqrt(Pick_m22 * (T1.C11 + stam.XYInfo.C11)) + fMaxDZ * fabs(T1.ty))[i1_4] * iz, time,
+                           (sqrt(Pick_m22 * (T1.C00 + stam.XYInfo.C00)) + fMaxDZ * abs(T1.tx))[i1_4] * iz,
+                           (sqrt(Pick_m22 * (T1.C11 + stam.XYInfo.C11)) + fMaxDZ * abs(T1.ty))[i1_4] * iz, time,
                            sqrt(timeError) * 5);
 
 
@@ -764,8 +764,8 @@ inline void L1Algo::findTripletsStep0(  // input
 #endif  // DO_NOT_SELECT_TRIPLETS
       const fscal iz = 1.f / (T2.z[i2_4] - fParameters.GetTargetPositionZ()[0]);
       L1HitAreaTime area(vGridTime[&star - fParameters.GetStations().begin()], T2.x[i2_4] * iz, T2.y[i2_4] * iz,
-                         (sqrt(Pick_r22 * (T2.C00 + stam.XYInfo.C00)) + fMaxDZ * fabs(T2.tx))[i2_4] * iz,
-                         (sqrt(Pick_r22 * (T2.C11 + stam.XYInfo.C11)) + fMaxDZ * fabs(T2.ty))[i2_4] * iz, time,
+                         (sqrt(Pick_r22 * (T2.C00 + stam.XYInfo.C00)) + fMaxDZ * abs(T2.tx))[i2_4] * iz,
+                         (sqrt(Pick_r22 * (T2.C11 + stam.XYInfo.C11)) + fMaxDZ * abs(T2.ty))[i2_4] * iz, time,
                          sqrt(timeError) * 5);
 
       L1HitIndex_t irh       = 0;
diff --git a/reco/L1/L1Algo/L1ClonesMerger.cxx b/reco/L1/L1Algo/L1ClonesMerger.cxx
index a64a91b3c3..aece822bc1 100644
--- a/reco/L1/L1Algo/L1ClonesMerger.cxx
+++ b/reco/L1/L1Algo/L1ClonesMerger.cxx
@@ -300,8 +300,8 @@ void L1ClonesMerger::InvertCholesky(fvec a[15])
     fvec smallval(1.e-12);
     uud = iif(uud >= smallval, uud, smallval);
 
-    d[i]    = uud / fabs(uud);
-    u[i][i] = sqrt(fabs(uud));
+    d[i]    = uud / abs(uud);
+    u[i][i] = sqrt(abs(uud));
 
     for (int j = i + 1; j < 5; j++) {
       uud = 0.f;
diff --git a/reco/L1/L1Algo/L1FitMaterial.cxx b/reco/L1/L1Algo/L1FitMaterial.cxx
index 91445450bb..a5b4586b3e 100644
--- a/reco/L1/L1Algo/L1FitMaterial.cxx
+++ b/reco/L1/L1Algo/L1FitMaterial.cxx
@@ -313,7 +313,7 @@ void L1Fit::EnergyLossCorrection(float atomicA, float rho, float radLen, L1Track
   //   T.C42 *= corr;
   //   T.C43 *= corr;
   //  T.C44 *= corr*corr;
-  T.C44 += fabs(SDEDX);
+  T.C44 += abs(SDEDX);
 
   //  T.C40 *= corr;
   //  T.C41 *= corr;
diff --git a/reco/L1/L1Algo/L1TrackExtender.cxx b/reco/L1/L1Algo/L1TrackExtender.cxx
index c3c212081e..ae8298e166 100644
--- a/reco/L1/L1Algo/L1TrackExtender.cxx
+++ b/reco/L1/L1Algo/L1TrackExtender.cxx
@@ -264,8 +264,8 @@ void L1Algo::FindMoreHits(L1Branch& t, L1TrackPar& T, const bool dir,
 
 
     L1HitAreaTime area(vGridTime[ista], T.x[0] * iz, T.y[0] * iz,
-                       (sqrt(fPickGather * (T.C00 + sta.XYInfo.C00)) + fMaxDZ * fabs(T.tx))[0] * iz,
-                       (sqrt(fPickGather * (T.C11 + sta.XYInfo.C11)) + fMaxDZ * fabs(T.ty))[0] * iz, T.t[0],
+                       (sqrt(fPickGather * (T.C00 + sta.XYInfo.C00)) + fMaxDZ * abs(T.tx))[0] * iz,
+                       (sqrt(fPickGather * (T.C11 + sta.XYInfo.C11)) + fMaxDZ * abs(T.ty))[0] * iz, T.t[0],
                        sqrt(T.C55[0]));
 
     L1HitIndex_t ih = 0;
@@ -300,7 +300,7 @@ void L1Algo::FindMoreHits(L1Branch& t, L1TrackPar& T, const bool dir,
       fscal d2  = d_x * d_x + d_y * d_y;
       if (d2 > r2_best) continue;
 
-      fscal dxm_est2 = (pickGather2 * (fabs(C00 + sta.XYInfo.C00)))[0];
+      fscal dxm_est2 = (pickGather2 * (abs(C00 + sta.XYInfo.C00)))[0];
       if (d_x * d_x > dxm_est2) continue;
 
       r2_best   = d2;
diff --git a/reco/L1/L1Algo/L1TrackFitter.cxx b/reco/L1/L1Algo/L1TrackFitter.cxx
index 0520037c43..45334216b4 100644
--- a/reco/L1/L1Algo/L1TrackFitter.cxx
+++ b/reco/L1/L1Algo/L1TrackFitter.cxx
@@ -1069,7 +1069,7 @@ void L1Algo::L1KFTrackFitterMuch()
 
           const fvec st = fvec(10);
 
-          fvec nofSteps = (fabs(d_z) / 10);
+          fvec nofSteps = (abs(d_z) / 10);
 
           int max_steps = 0;
 
@@ -1212,7 +1212,7 @@ void L1Algo::L1KFTrackFitterMuch()
 
           fvec d_z      = T1.fz - z_last;
           const fvec st = fvec(10);
-          fvec nofSteps = (fabs(d_z) / 10);
+          fvec nofSteps = (abs(d_z) / 10);
 
           int max_steps = 0;
 
diff --git a/reco/L1/L1Algo/L1TrackParFit.cxx b/reco/L1/L1Algo/L1TrackParFit.cxx
index 60e163ea4e..9890852328 100644
--- a/reco/L1/L1Algo/L1TrackParFit.cxx
+++ b/reco/L1/L1Algo/L1TrackParFit.cxx
@@ -878,7 +878,7 @@ void L1TrackParFit::EnergyLossCorrection(float atomicA, float rho, float radLen,
   //   T.C42 *= corr;
   //   T.C43 *= corr;
   // T.C44 *= corr*corr;
-  C44 += fabs(SDEDX);
+  C44 += abs(SDEDX);
 }
 
 
diff --git a/reco/L1/OffLineInterface/CbmL1RichENNRingFinderParallel.cxx b/reco/L1/OffLineInterface/CbmL1RichENNRingFinderParallel.cxx
index 0fbc0228ad..71e128a516 100644
--- a/reco/L1/OffLineInterface/CbmL1RichENNRingFinderParallel.cxx
+++ b/reco/L1/OffLineInterface/CbmL1RichENNRingFinderParallel.cxx
@@ -440,13 +440,13 @@ void CbmL1RichENNRingFinderParallel::ENNRingFinder(const int NHits, nsL1vector<E
         ENNSearchHitV& sHit = SearchArea[ih];
         const fvec dx       = sHit.lx - X;
         const fvec dy       = sHit.ly - Y;
-        const fvec d        = fabs(sqrt(dx * dx + dy * dy) - R);
+        const fvec d        = abs(sqrt(dx * dx + dy * dy) - R);
         const fvec dSq      = d * d;
         sHit.on_ring        = (d <= HitSize) & validHit;
-        const fvec dp       = iif(sHit.on_ring, fvec(-1.), fabs(sHit.C + sHit.Cx * X + sHit.Cy * Y));
+        const fvec dp       = iif(sHit.on_ring, fvec(-1.), abs(sHit.C + sHit.Cx * X + sHit.Cy * Y));
         Dmax                = iif(((dp <= Dcut) & (dp > Dmax)), dp, Dmax);
 
-        fvec w = iif((sHit.on_ring), 1. / (HitSizeSq_v + fabs(dSq)), 1. / (1.e-5 + fabs(dSq)));
+        fvec w = iif((sHit.on_ring), 1. / (HitSizeSq_v + abs(dSq)), 1. / (1.e-5 + abs(dSq)));
         w      = iif((dp <= Dcut) & validHit, w, fvec::Zero());
         S0 += w * sHit.S0;
         S1 += w * sHit.S1;
@@ -528,7 +528,7 @@ void CbmL1RichENNRingFinderParallel::ENNRingFinder(const int NHits, nsL1vector<E
         ENNSearchHitV &sHit = SearchArea[ih];
         const fvec dx = sHit.x - ringV.x;
         const fvec dy = sHit.y - ringV.y;
-        const fvec d = fabs( sqrt(dx*dx+dy*dy) - ringV.r );
+        const fvec d = abs( sqrt(dx*dx+dy*dy) - ringV.r );
         validHit = validHit & ( d <= HitSize );
         ringV.chi2 += d*d;
         ringV.localIHits.push_back( iif( validHit, sHit.localIndex, fvec(-1.) ) );
@@ -543,7 +543,7 @@ void CbmL1RichENNRingFinderParallel::ENNRingFinder(const int NHits, nsL1vector<E
         ENNHitV &puHit = PickUpArea[ipu];
         const fvec dx = puHit.x - ringV.x;
         const fvec dy = puHit.y - ringV.y;
-        const fvec d = fabs( sqrt(dx*dx+dy*dy) - ringV.r );
+        const fvec d = abs( sqrt(dx*dx+dy*dy) - ringV.r );
         validHit = validHit & ( d <= HitSize );
         if ( validHit.isEmpty() ) continue;
         ringV.chi2 += d*d;
diff --git a/reco/L1/ParticleFinder/CbmL1PFFitter.cxx b/reco/L1/ParticleFinder/CbmL1PFFitter.cxx
index d3c53cb8bd..a1f47d7b8e 100644
--- a/reco/L1/ParticleFinder/CbmL1PFFitter.cxx
+++ b/reco/L1/ParticleFinder/CbmL1PFFitter.cxx
@@ -525,8 +525,8 @@ void CbmL1PFFitter::GetChiToVertex(vector<CbmStsTrack>& Tracks, vector<L1FieldRe
     c[1] += fvec(Cv[1]);
     c[2] += fvec(Cv[2]);
     fvec d   = c[0] * c[2] - c[1] * c[1];
-    fvec chi = sqrt(fabs(0.5 * (dx * dx * c[0] - 2 * dx * dy * c[1] + dy * dy * c[2]) / d));
-    chi.setZero(fabs(d) < fvec(1.e-20));
+    fvec chi = sqrt(abs(0.5 * (dx * dx * c[0] - 2 * dx * dy * c[1] + dy * dy * c[2]) / d));
+    chi.setZero(abs(d) < fvec(1.e-20));
 
     for (int iVec = 0; iVec < nTracks_SIMD; iVec++) {
       chiToVtx.push_back(chi[iVec]);
diff --git a/reco/L1/vectors/L1vecPseudo.h b/reco/L1/vectors/L1vecPseudo.h
index e4130b84a7..b2dd05849a 100644
--- a/reco/L1/vectors/L1vecPseudo.h
+++ b/reco/L1/vectors/L1vecPseudo.h
@@ -266,8 +266,6 @@ public:
 #define _fvecalignment __attribute__((aligned(fvec::Size * sizeof(fscal))))
 
 
-inline fvec fabs(const fvec& a) { return abs(a); }
-
 /// 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
diff --git a/reco/L1/vectors/L1vecVc.h b/reco/L1/vectors/L1vecVc.h
index 1ff387d535..996307e175 100644
--- a/reco/L1/vectors/L1vecVc.h
+++ b/reco/L1/vectors/L1vecVc.h
@@ -27,13 +27,6 @@ inline fvec operator-(fscal a, const fvec& b) { return fvec(a) - b; }
 inline fvec operator-(const fvec& a, fscal b) { return a - fvec(b); }
 
 
-inline fvec fabs(const fvec& a) { return abs(a); }
-
-//inline fvec mask2int(const fmask& mask)
-//{  // mask returned
-//return iif(mask, fvec::One(), fvec::Zero());
-//}
-
 /// 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
-- 
GitLab