Update zarch SCAL kernels to handle INF and NAN arguments (#4829)

* handle INF and NAN in input (for S/D only if DUMMY2 argument is set)
This commit is contained in:
Martin Kroeker 2024-07-31 19:45:15 +02:00 committed by GitHub
parent 136a4edc5f
commit edbf093c98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 152 additions and 70 deletions

View File

@ -234,12 +234,23 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
} else { } else {
while (j < n1) { while (j < n1) {
if (isnan(x[i]) || isinf(x[i]))
temp0 = NAN;
else
temp0 = -da_i * x[i + 1]; temp0 = -da_i * x[i + 1];
if (!isinf(x[i + 1]))
x[i + 1] = da_i * x[i]; x[i + 1] = da_i * x[i];
else
x[i + 1] = NAN;
x[i] = temp0; x[i] = temp0;
if (isnan(x[i+inc_x]) || isinf(x[i+inc_x]))
temp1 = NAN;
else
temp1 = -da_i * x[i + 1 + inc_x]; temp1 = -da_i * x[i + 1 + inc_x];
if (!isinf(x[i + 1 + inc_x]))
x[i + 1 + inc_x] = da_i * x[i + inc_x]; x[i + 1 + inc_x] = da_i * x[i + inc_x];
else
x[i + 1 + inc_x] = NAN;
x[i + inc_x] = temp1; x[i + inc_x] = temp1;
i += 2 * inc_x; i += 2 * inc_x;
j += 2; j += 2;
@ -247,8 +258,13 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
} }
while (j < n) { while (j < n) {
if (isnan(x[i]) || isinf(x[i]))
temp0 = NAN;
else
temp0 = -da_i * x[i + 1]; temp0 = -da_i * x[i + 1];
if (isinf(x[i + 1]))
x[i + 1] = NAN;
else
x[i + 1] = da_i * x[i]; x[i + 1] = da_i * x[i];
x[i] = temp0; x[i] = temp0;
i += inc_x; i += inc_x;
@ -332,14 +348,25 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
j = n1; j = n1;
} }
if (da_r == 0.0) { if (da_r == 0.0 || isnan(da_r)) {
if (da_i == 0.0) { if (da_i == 0.0) {
float res = 0.0;
if (isnan(da_r)) res = da_r;
while (j < n) { while (j < n) {
x[i] = 0.0; x[i] = res;
x[i + 1] = 0.0; x[i + 1] = res;
i += 2;
j++;
}
} else if (isinf(da_r)) {
while(j < n)
{
x[i]= NAN;
x[i+1] = da_r;
i += 2 ; i += 2 ;
j++; j++;
@ -350,7 +377,12 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
while (j < n) { while (j < n) {
temp0 = -da_i * x[i + 1]; temp0 = -da_i * x[i + 1];
if (isinf(x[i])) temp0 = NAN;
if (!isinf(x[i + 1]))
x[i + 1] = da_i * x[i]; x[i + 1] = da_i * x[i];
else
x[i + 1] = NAN;
if (x[i] == x[i])
x[i] = temp0; x[i] = temp0;
i += 2; i += 2;
j++; j++;

View File

@ -97,18 +97,26 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
if (da == 0.0) { if (da == 0.0) {
if (dummy2 == 0) {
BLASLONG n1 = n & -16; BLASLONG n1 = n & -16;
if (n1 > 0) { if (n1 > 0) {
dscal_kernel_16_zero(n1, x); dscal_kernel_16_zero(n1, x);
j = n1; j = n1;
} }
while (j < n) { while (j < n) {
x[j] = 0.0; x[j] = 0.0;
j++; j++;
} }
} else {
while (j < n) {
if (isfinite(x[j]))
x[j] = 0.0;
else
x[j] = NAN;
j++;
}
}
} else { } else {
@ -127,11 +135,9 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
} else { } else {
if (da == 0.0) { if (da == 0.0) {
if (dummy2 == 0) {
BLASLONG n1 = n & -4; BLASLONG n1 = n & -4;
while (j < n1) { while (j < n1) {
x[i] = 0.0; x[i] = 0.0;
x[i + inc_x] = 0.0; x[i + inc_x] = 0.0;
x[i + 2 * inc_x] = 0.0; x[i + 2 * inc_x] = 0.0;
@ -139,11 +145,13 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
i += inc_x * 4; i += inc_x * 4;
j += 4; j += 4;
}
} }
while (j < n) { while (j < n) {
if (dummy2==0 || isfinite(x[i]))
x[i] = 0.0; x[i] = 0.0;
else
x[i] = NAN;
i += inc_x; i += inc_x;
j++; j++;
} }

View File

@ -95,8 +95,8 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
if (inc_x == 1) { if (inc_x == 1) {
if (da == 0.0) { if (da == 0.0 || !isfinite(da)) {
if (dummy2 == 0) {
BLASLONG n1 = n & -32; BLASLONG n1 = n & -32;
if (n1 > 0) { if (n1 > 0) {
@ -109,7 +109,17 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
x[j] = 0.0; x[j] = 0.0;
j++; j++;
} }
} else {
float res = 0.0;
if (!isfinite(da)) res = NAN;
while (j < n) {
if (isfinite(x[i]))
x[j] = res;
else
x[j] = NAN;
j++;
}
}
} else { } else {
BLASLONG n1 = n & -32; BLASLONG n1 = n & -32;
@ -126,8 +136,8 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
} else { } else {
if (da == 0.0) { if (da == 0.0 || !isfinite(da)) {
if (dummy2 == 0) {
BLASLONG n1 = n & -2; BLASLONG n1 = n & -2;
while (j < n1) { while (j < n1) {
@ -145,7 +155,18 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
i += inc_x; i += inc_x;
j++; j++;
} }
} else {
while (j < n) {
float res = 0.0;
if (!isfinite(da)) res = NAN;
if (isfinite(x[i]))
x[i] = res;
else
x[i] = NAN;
i += inc_x;
j++;
}
}
} else { } else {
BLASLONG n1 = n & -2; BLASLONG n1 = n & -2;

View File

@ -237,13 +237,19 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
temp0 = NAN; temp0 = NAN;
else else
temp0 = -da_i * x[i + 1]; temp0 = -da_i * x[i + 1];
if (!isinf(x[i + 1]))
x[i + 1] = da_i * x[i]; x[i + 1] = da_i * x[i];
else
x[i + 1] = NAN;
x[i] = temp0; x[i] = temp0;
if (isnan(x[i + inc_x]) || isinf(x[i + inc_x])) if (isnan(x[i + inc_x]) || isinf(x[i + inc_x]))
temp1 = NAN; temp1 = NAN;
else else
temp1 = -da_i * x[i + 1 + inc_x]; temp1 = -da_i * x[i + 1 + inc_x];
if (!isinf(x[i + 1 + inc_x]))
x[i + 1 + inc_x] = da_i * x[i + inc_x]; x[i + 1 + inc_x] = da_i * x[i + inc_x];
else
x[i + 1 + inc_x] = NAN;
x[i + inc_x] = temp1; x[i + inc_x] = temp1;
i += 2 * inc_x; i += 2 * inc_x;
j += 2; j += 2;
@ -256,7 +262,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
temp0 = NAN; temp0 = NAN;
else else
temp0 = -da_i * x[i + 1]; temp0 = -da_i * x[i + 1];
if (!isinf(x[i +1]))
x[i + 1] = da_i * x[i]; x[i + 1] = da_i * x[i];
else
x[i + 1] = NAN;
x[i] = temp0; x[i] = temp0;
i += inc_x; i += inc_x;
j++; j++;
@ -330,7 +339,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
zscal_kernel_8_zero(n1, x); zscal_kernel_8_zero(n1, x);
else else
zscal_kernel_8(n1, da_r, da_i, x); zscal_kernel_8(n1, da_r, da_i, x);
else if (da_i == 0) else if (da_i == 0 && da_r == da_r)
zscal_kernel_8_zero_i(n1, alpha, x); zscal_kernel_8_zero_i(n1, alpha, x);
else else
zscal_kernel_8(n1, da_r, da_i, x); zscal_kernel_8(n1, da_r, da_i, x);
@ -339,28 +348,40 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
j = n1; j = n1;
} }
if (da_r == 0.0) { if (da_r == 0.0 || isnan(da_r)) {
if (da_i == 0.0) { if (da_i == 0.0) {
double res= 0.0;
if (isnan(da_r)) res = da_r;
while (j < n) { while (j < n) {
x[i] = 0.0; x[i] = res;
x[i + 1] = 0.0; x[i + 1] = res;
i += 2; i += 2;
j++; j++;
} }
} else if (isinf(da_r)) {
while (j < n) {
x[i] = NAN;
x[i + 1] = da_r;
i += 2;
j++;
}
} else { } else {
while (j < n) { while (j < n) {
if (isnan(x[i]) || isinf(x[i])) if (isinf(x[i]))
temp0 = NAN; temp0 = NAN;
else else
temp0 = -da_i * x[i + 1]; temp0 = -da_i * x[i + 1];
if (!isinf(x[i + 1]))
x[i + 1] = da_i * x[i]; x[i + 1] = da_i * x[i];
else
x[i + 1] = NAN;
if (x[i]==x[i])
x[i] = temp0; x[i] = temp0;
i += 2; i += 2;
j++; j++;