Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct handling of NaN values in I[S/D]AMIN and I[S/D]AMAX to "return position of first NaN" #4191

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
4 changes: 3 additions & 1 deletion kernel/arm/iamax.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
BLASLONG max=0;

if (n <= 0 || inc_x <= 0) return(max);

if (n==1) return(1);
if (x[0]!=x[0]) return(1);
maxf=ABS(x[0]);
ix += inc_x;
i++;

while(i < n)
{
if (x[ix]!=x[ix]) return(i+1);
if( ABS(x[ix]) > maxf )
{
max = i;
Expand Down
6 changes: 4 additions & 2 deletions kernel/arm/iamin.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
BLASLONG min=0;

if (n <= 0 || inc_x <= 0) return(min);

minf=ABS(x[0]);
if (n==1) return(1);
if (x[0]!=x[0]) return(1);
minf=ABS(x[0]);
ix += inc_x;
i++;

while(i < n)
{
if (x[ix]!=x[ix]) return(i+1);
if( ABS(x[ix]) < ABS(minf) )
{
min = i;
Expand Down
15 changes: 13 additions & 2 deletions kernel/mips/iamax.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
Copyright (c) 2016, The OpenBLAS Project
Copyright (c) 2013, The OpenBLAS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
Expand All @@ -25,6 +25,15 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/

/**************************************************************************************
* 2013/09/14 Saar
* BLASTEST float : NoTest
* BLASTEST double : NoTest
* CTEST : OK
* TEST : OK
*
**************************************************************************************/

#include "common.h"
#include <math.h>

Expand All @@ -47,13 +56,15 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
BLASLONG max=0;

if (n <= 0 || inc_x <= 0) return(max);

if (n==1) return(1);
if (x[0]!=x[0]) return(1);
maxf=ABS(x[0]);
ix += inc_x;
i++;

while(i < n)
{
if (x[ix]!=x[ix]) return(i+1);
if( ABS(x[ix]) > maxf )
{
max = i;
Expand Down
17 changes: 14 additions & 3 deletions kernel/mips/iamin.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
Copyright (c) 2016, The OpenBLAS Project
Copyright (c) 2013, The OpenBLAS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
Expand All @@ -25,6 +25,15 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/

/**************************************************************************************
* 2013/09/14 Saar
* BLASTEST float : NoTest
* BLASTEST double : NoTest
* CTEST : NoTest
* TEST : NoTest
*
**************************************************************************************/

#include "common.h"
#include <math.h>

Expand All @@ -47,13 +56,15 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
BLASLONG min=0;

if (n <= 0 || inc_x <= 0) return(min);

minf=ABS(x[0]);
if (n==1) return(1);
if (x[0]!=x[0]) return(1);
minf=ABS(x[0]);
ix += inc_x;
i++;

while(i < n)
{
if (x[ix]!=x[ix]) return(i+1);
if( ABS(x[ix]) < ABS(minf) )
{
min = i;
Expand Down
114 changes: 111 additions & 3 deletions kernel/power/iamax.S
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,19 @@ LL(1000):
.align 4

LL(1010):
addi RET, RET, 1
fcmpu cr0, f24, f24
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f25, f25
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f26, f26
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f27, f27
bun cr0, LL(9999)

fabs f8, f24
fabs f9, f25
fabs f10, f26
Expand All @@ -529,6 +542,20 @@ LL(1010):
LFD f25, 9 * SIZE(XX)
LFD f26, 10 * SIZE(XX)
LFD f27, 11 * SIZE(XX)

addi RET, RET, 1
fcmpu cr0, f24, f24
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f25, f25
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f26, f26
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f27, f27
bun cr0, LL(9999)
subi RET, RET, 8

fabs f12, f28
fabs f13, f29
Expand Down Expand Up @@ -577,6 +604,32 @@ LL(1010):
.align 4

LL(1020):
addi RET, RET, 1
fcmpu cr0, f24, f24
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f25, f25
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f26, f26
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f27, f27
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f28, f28
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f29, f29
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f30, f30
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f31, f31
bun cr0, LL(9999)
subi RET, RET, 8

fabs f8, f24
fabs f9, f25
fabs f10, f26
Expand Down Expand Up @@ -631,8 +684,12 @@ LL(1050):
LL(1060):
LFD f8, 0 * SIZE(XX)
addi XX, XX, 1 * SIZE
addi RET, RET, 1
fcmpu cr0, f8, f8
bun cru, LL(9999)

fabs f8, f8
addi RET, RET, 1
//addi RET, RET, 1
fcmpu cr0, f1, f8
beq cr0, LL(9999)
bdnz LL(1060)
Expand All @@ -658,6 +715,18 @@ LL(1100):
.align 4

LL(1110):
addi RET, RET, 1
fcmpu cr0, f24, f24
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f25, f25
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f26, f26
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f27, f27
bun cr0, LL(9999)
fabs f8, f24
fabs f9, f25
fabs f10, f26
Expand All @@ -667,7 +736,19 @@ LL(1110):
LFDUX f25, XX, INCX
LFDUX f26, XX, INCX
LFDUX f27, XX, INCX

addi RET, RET, 1
fcmpu cr0, f24, f24
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f25, f25
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f26, f26
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f27, f27
bun cr0, LL(9999)
subi RET, RET, 8
fabs f12, f28
fabs f13, f29
fabs f14, f30
Expand Down Expand Up @@ -714,6 +795,30 @@ LL(1110):
.align 4

LL(1120):
addi RET, RET, 1
fcmpu cr0, f24, f24
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f25, f25
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f26, f26
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f27, f27
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f28, f28
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f29, f29
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f30, f30
bun cr0, LL(9999)
addi RET, RET, 1
fcmpu cr0, f31, f31
subi RET, RET, 8
fabs f8, f24
fabs f9, f25
fabs f10, f26
Expand Down Expand Up @@ -765,8 +870,11 @@ LL(1150):

LL(1160):
LFDUX f8, XX, INCX
fabs f8, f8
addi RET, RET, 1
fcmpu cr0, f8, f8
bun LL(9999)
fabs f8, f8
// addi RET, RET, 1
fcmpu cr0, f1, f8
beq cr0, LL(9999)
bdnz LL(1160)
Expand Down
9 changes: 8 additions & 1 deletion kernel/power/idamax.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x) {
BLASLONG max = 0;

if (n <= 0 || inc_x <= 0) return (max);
if (n == 1) return(1);

if (inc_x == 1) {

Expand All @@ -335,14 +336,15 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x) {

BLASLONG n1 = n & -32;
if (n1 > 0) {

for (int ii=i;ii<i+32;ii++) if (x[ii]!=x[ii]) return(ii+1);
max = diamax_kernel_32(n1, x, &maxf);

i = n1;
}
#endif
#endif
while (i < n) {
if (x[i] != x[i]) return(i+1);
if (ABS(x[i]) > maxf) {
max = i;
maxf = ABS(x[i]);
Expand All @@ -356,6 +358,10 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x) {
BLASLONG n1 = n & -4;
while (j < n1) {

if (x[i] != x[i]) return(i+1);
if (x[i+inc_x] != x[i+inc_x]) return(j+1);
if (x[i+2*inc_x] != x[i+2*inc_x]) return(j+2);
if (x[i+3*inc_x] != x[i+3*inc_x]) return(j+3);
if (ABS(x[i]) > maxf) {
max = j;
maxf = ABS(x[i]);
Expand All @@ -381,6 +387,7 @@ BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x) {


while (j < n) {
if (x[i] != x[i]) return(j+1);
if (ABS(x[i]) > maxf) {
max = j;
maxf = ABS(x[i]);
Expand Down
Loading