From a77eaa448c0a38dce5d1a840b13b15d8d792f150 Mon Sep 17 00:00:00 2001 From: Mahesh Madhav <67384846+heshpdx@users.noreply.github.com> Date: Sat, 7 Sep 2024 12:20:24 -0700 Subject: [PATCH] Change FDIV to FMUL (#831) * Change FDIV to FMUL Some small performance improvement from safely changing a couple floating point divides to floating point multiplies. * Update src/lib/alp/sls_basic.hpp Use calculated value to ensure no functional change. --- src/lib/alp/sls_basic.hpp | 3 ++- src/masking/tantan.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/alp/sls_basic.hpp b/src/lib/alp/sls_basic.hpp index 036f6a18..b937e86c 100644 --- a/src/lib/alp/sls_basic.hpp +++ b/src/lib/alp/sls_basic.hpp @@ -52,6 +52,7 @@ Contents: Some basic functions and types namespace Sls { const double pi=3.1415926535897932384626433832795; + const double invsqrttwo=sqrt(0.5); const double const_val=1/sqrt(2.0*pi); const long int quick_tests_trials_number=100; @@ -189,7 +190,7 @@ namespace Sls { static double normal_probability(double x_) { - return 0.5*erfc(-sqrt(0.5)*x_); + return 0.5*erfc(-invsqrttwo*x_); } static double normal_probability( diff --git a/src/masking/tantan.cpp b/src/masking/tantan.cpp index 014df4e2..33b44960 100644 --- a/src/masking/tantan.cpp +++ b/src/masking/tantan.cpp @@ -98,12 +98,13 @@ Mask::Ranges mask(Letter *seq, } const float z = b * b2b + f.sum() * p_repeat_end; + const float zinv = 1.0/z; b = b2b; f = p_repeat_end; Mask::Ranges ranges; for (int i = len - 1; i >= 0; --i) { - const float pf = 1 - (pb[i] * b / z); + const float pf = 1 - (pb[i] * b * zinv); if ((i & 15) == 15) { const float s = scale[i / 16];