From 3e6dd11467643fbc2cb45c13cec8dd6024232833 Mon Sep 17 00:00:00 2001 From: "Field G. Van Zee" Date: Tue, 3 Nov 2015 10:30:08 -0600 Subject: [PATCH] Minor re-expression in quadratic partitioning code. Details: - Minor change to quadratic equation solution code that avoids recomputation of the sqrt() parameter when the compiler is not smart enough to perform this optimization automatically. --- frame/base/bli_threading.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frame/base/bli_threading.c b/frame/base/bli_threading.c index b21c0448c..168679ef0 100644 --- a/frame/base/bli_threading.c +++ b/frame/base/bli_threading.c @@ -461,14 +461,15 @@ dim_t bli_get_range_width_l( doff_t diagoff_j, const double c = -0.5 * ( ( double )diagoff_j * ( ( double )diagoff_j + 1.0 ) ) - area_per_thr; + const double r = b * b - 4.0 * a * c; // If the quadratic solution is not imaginary, round it and use that // as our width, but make sure it didn't round to zero. Otherwise, // discard the quadratic solution and leave width, as previously // computed, unchanged. - if ( b * b - 4.0 * a * c >= 0 ) + if ( r >= 0.0 ) { - const double x = ( -b + sqrt( b * b - 4.0 * a * c ) ) / ( 2.0 * a ); + const double x = ( -b + sqrt( r ) ) / ( 2.0 * a ); width = ( dim_t )bli_round( x ); if ( width == 0 ) width = 1;