From 6355c25dde1ccba0fe6521dc0b36c0fcdddda0ef Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Sun, 29 Sep 2019 22:03:12 -0700 Subject: [PATCH] Avoid taking root of negative number in symv_thread.c This is similar to fixes in gh-1929, but there was one remaining occurance of this type of pattern in the driver/level2/*_thread.c files. --- driver/level2/symv_thread.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/driver/level2/symv_thread.c b/driver/level2/symv_thread.c index ab783de2b..d7cc01768 100644 --- a/driver/level2/symv_thread.c +++ b/driver/level2/symv_thread.c @@ -166,7 +166,11 @@ int CNAME(BLASLONG m, FLOAT *alpha, FLOAT *a, BLASLONG lda, FLOAT *x, BLASLONG i if (nthreads - num_cpu > 1) { double di = (double)i; - width = ((BLASLONG)(sqrt(di * di + dnum) - di) + mask) & ~mask; + if (di * di - dnum > 0) { + width = ((BLASLONG)(-sqrt(di * di - dnum) + di) + mask) & ~mask; + } else { + width = m - i; + } if (width < 4) width = 4; if (width > m - i) width = m - i; @@ -212,9 +216,9 @@ int CNAME(BLASLONG m, FLOAT *alpha, FLOAT *a, BLASLONG lda, FLOAT *x, BLASLONG i double di = (double)(m - i); if (di * di - dnum > 0) { - width = ((BLASLONG)(-sqrt(di * di - dnum) + di) + mask) & ~mask; + width = ((BLASLONG)(-sqrt(di * di - dnum) + di) + mask) & ~mask; } else { - width = m - i; + width = m - i; } if (width < 4) width = 4;