Skip to content

Commit def4996

Browse files
authored
Fix handling of NAN and INF arguments
1 parent e48627c commit def4996

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

kernel/x86_64/zscal.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3939
#endif
4040

4141
#include "common.h"
42-
42+
#include <float.h>
4343

4444
#if defined (SKYLAKEX) || defined (COOPERLAKE) || defined (SAPPHIRERAPIDS)
4545
#include "zscal_microk_skylakex-2.c"
@@ -222,12 +222,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
222222

223223
if ( da_r == 0.0 )
224224
{
225-
226225
BLASLONG n1 = n & -2;
227226

228227
if ( da_i == 0.0 )
229228
{
230-
231229
while(j < n1)
232230
{
233231

@@ -253,7 +251,6 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
253251
}
254252
else
255253
{
256-
257254
while(j < n1)
258255
{
259256

@@ -356,49 +353,59 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
356353

357354
alpha[0] = da_r;
358355
alpha[1] = da_i;
359-
356+
360357
if ( da_r == 0.0 )
361358
if ( da_i == 0 )
362359
zscal_kernel_8_zero(n1 , alpha , x);
363360
else
364-
zscal_kernel_8_zero_r(n1 , alpha , x);
361+
// zscal_kernel_8_zero_r(n1 , alpha , x);
362+
zscal_kernel_8(n1 , alpha , x);
365363
else
366-
if ( da_i == 0 )
364+
if ( da_i == 0 && da_r == da_r)
367365
zscal_kernel_8_zero_i(n1 , alpha , x);
368366
else
369367
zscal_kernel_8(n1 , alpha , x);
370-
368+
}
371369
i = n1 << 1;
372370
j = n1;
373-
}
374-
375-
376-
if ( da_r == 0.0 )
371+
372+
if ( da_r == 0.0 || da_r != da_r )
377373
{
378-
379374
if ( da_i == 0.0 )
380375
{
381-
376+
FLOAT res=0.0;
377+
if (da_r != da_r) res= da_r;
382378
while(j < n)
383379
{
384-
385-
x[i]=0.0;
386-
x[i+1]=0.0;
380+
x[i]=res;
381+
x[i+1]=res;
387382
i += 2 ;
388383
j++;
389384

390385
}
391386

392387
}
393-
else
388+
else if (da_r < -FLT_MAX || da_r > FLT_MAX) {
389+
while(j < n)
390+
{
391+
x[i]=SNAN;
392+
x[i+1]=da_r;
393+
i += 2 ;
394+
j++;
395+
396+
}
397+
398+
} else
394399
{
395400

396401
while(j < n)
397402
{
398-
399403
temp0 = -da_i * x[i+1];
404+
if (x[i] < -FLT_MAX || x[i] > FLT_MAX)
405+
temp0 = SNAN;
400406
x[i+1] = da_i * x[i];
401-
x[i] = temp0;
407+
if ( x[i] == x[i]) //preserve NaN
408+
x[i] = temp0;
402409
i += 2 ;
403410
j++;
404411

@@ -409,28 +416,24 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
409416
}
410417
else
411418
{
412-
413-
if ( da_i == 0.0 )
419+
if (da_i == 0.0)
414420
{
415-
416-
while(j < n)
417-
{
421+
while(j < n)
422+
{
418423

419424
temp0 = da_r * x[i];
420425
x[i+1] = da_r * x[i+1];
421426
x[i] = temp0;
422427
i += 2 ;
423428
j++;
424429

425-
}
426-
430+
}
427431
}
428432
else
429433
{
430434

431435
while(j < n)
432436
{
433-
434437
temp0 = da_r * x[i] - da_i * x[i+1];
435438
x[i+1] = da_r * x[i+1] + da_i * x[i];
436439
x[i] = temp0;
@@ -445,5 +448,3 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
445448

446449
return(0);
447450
}
448-
449-

kernel/x86_64/zscal_sse2.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
pxor %xmm15, %xmm15
8383
comisd %xmm0, %xmm15
8484
jne .L100
85+
jp .L100
8586

8687
comisd %xmm1, %xmm15
8788
jne .L100

0 commit comments

Comments
 (0)