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

Fix handling of INF or NAN arguments in S/D/C SCAL #4729

Merged
merged 20 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
020b3e1
fix handling of INF arguments
martin-frbg May 31, 2024
ffc1ab3
Test corner cases of all SCAL variants
martin-frbg Jun 6, 2024
1abafcd
handle corner cases involving NAN and/or INF
martin-frbg Jun 6, 2024
2bd43ad
Merge branch 'OpenMathLib:develop' into issue4728
martin-frbg Jun 6, 2024
5ed4f24
Handle corner cases with INF and NAN arguments
martin-frbg Jun 7, 2024
c7cacd9
disable the shortcut for da=0 to ensure proper handling of INF and NAN
martin-frbg Jun 7, 2024
6ffaf99
disable da=0 shortcut to handle NAN and INF correctly
martin-frbg Jun 7, 2024
a2ee4b1
Merge branch 'OpenMathLib:develop' into issue4728
martin-frbg Jun 21, 2024
f1248b8
handle INF and NAN in input
martin-frbg Jun 22, 2024
7f8f037
handle INF and NAN in input
martin-frbg Jun 22, 2024
0a744a9
temporarily(?) disable the alpha=0 branch to handle NaN/Inf in x
martin-frbg Jun 22, 2024
68f2501
temporarily(?) disable the alpha=0 branch to handle Inf/NaN in x
martin-frbg Jun 22, 2024
bd47630
exclude the alpha=0 branch as it does not handle NaN or Inf in x
martin-frbg Jun 22, 2024
c08113c
fix special cases of x= NAN or INF
martin-frbg Jun 22, 2024
541e1b6
disable the fast path for inc=1, alpha=0 as it does not handle x=NaN …
martin-frbg Jun 23, 2024
a11f086
Update sscal_msa.c
martin-frbg Jun 23, 2024
9e24121
temporarily(?) disable da=0 shortcut to handle x=Inf or NAN
martin-frbg Jun 23, 2024
c1019d5
Handle INF and NAN in inputs
martin-frbg Jun 27, 2024
2a5fe97
temporarily(?) disable the alpha=0 branch as it does not handle INF,NAN
martin-frbg Jun 27, 2024
f3c364c
temporarily(?) disable the alpha=0 branch as it fails to handle INF,NAN
martin-frbg Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kernel/arm64/scal.S
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmp N, xzr
ble .Lscal_kernel_L999

fcmp DA, #0.0
beq .Lscal_kernel_zero
//fcmp DA, #0.0
//beq .Lscal_kernel_zero

cmp INC_X, #1
bne .Lscal_kernel_S_BEGIN
Expand Down
10 changes: 6 additions & 4 deletions kernel/mips/dscal_msa.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,

if (1 == inc_x)
{
if (0.0 == da)
if (0) //if (0.0 == da )
{
v2f64 zero_v = {0.0, 0.0};

Expand Down Expand Up @@ -243,9 +243,11 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
if (da == 0.0)
{
for (i = n; i--;)
{
*x = 0.0;

{
if (isfinite(*x))
*x = 0.0;
else
*x = NAN;
x += inc_x;
}
}
Expand Down
7 changes: 6 additions & 1 deletion kernel/mips/scal.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
{

if ( da == 0.0 )
x[i]=0.0;
if (isnan(x[i])||isinf(x[i]))
x[i]=NAN;
else
x[i]=0.0;
else if (isnan(da))
x[i]=NAN;
else
x[i] = da * x[i] ;

Expand Down
7 changes: 5 additions & 2 deletions kernel/mips/sscal_msa.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,

if (1 == inc_x)
{
if (0.0 == da)
if (0) // if (0.0 == da)
{
v4f32 zero_v = {0.0, 0.0, 0.0, 0.0};

Expand Down Expand Up @@ -259,7 +259,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
{
for (i = n; i--;)
{
*x = 0;
if (isfinite(*x))
*x = 0;
else
*x = NAN;
x += inc_x;
}
}
Expand Down
3 changes: 3 additions & 0 deletions kernel/mips64/scal.S
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
bc1f $fcc0, .L50
NOP

bc1t $fcc0, .L50
NOP

bne INCX, TEMP, .L20
dsra I, N, 3

Expand Down
57 changes: 44 additions & 13 deletions kernel/power/dscal.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,38 @@ static void dscal_kernel_8_zero (BLASLONG n, FLOAT *x)

for( i=0; i<n; i+=8 )
{
x[0] = alpha;
x[1] = alpha;
x[2] = alpha;
x[3] = alpha;
x[4] = alpha;
x[5] = alpha;
x[6] = alpha;
x[7] = alpha;
if(isfinite(x[0]))
x[0] = alpha;
else
x[0] = NAN;
if(isfinite(x[1]))
x[1] = alpha;
else
x[1] = NAN;
if (isfinite(x[2]))
x[2] = alpha;
else
x[2] = NAN;
if (isfinite(x[3]))
x[3] = alpha;
else
x[3] = NAN;
if (isfinite(x[4]))
x[4] = alpha;
else
x[4] = NAN;
if (isfinite(x[5]))
x[5] = alpha;
else
x[5] = NAN;
if (isfinite(x[6]))
x[6] = alpha;
else
x[6] = NAN;
if (isfinite(x[7]))
x[7] = alpha;
else
x[7] = NAN;
x+=8;
}

Expand All @@ -107,7 +131,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
{
BLASLONG align = ((32 - ((uintptr_t)x & (uintptr_t)0x1F)) >> 3) & 0x3;
for (j = 0; j < align; j++) {
x[j] = 0.0;
if (isfinite(x[j]))
x[j] = 0.0;
else
x[j] = NAN;
}
}
BLASLONG n1 = (n-j) & -16;
Expand All @@ -127,8 +154,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS

while(j < n)
{

x[j]=0.0;
if (!isfinite(x[j]))
x[j]=NAN;
else
x[j]=0.0;
j++;
}

Expand Down Expand Up @@ -176,8 +205,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS

while(j < n)
{

x[i]=0.0;
if (!isfinite(x[i]))
x[i]=NAN;
else
x[i]=0.0;
i += inc_x ;
j++;
}
Expand Down
5 changes: 3 additions & 2 deletions kernel/power/scal.S
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@
cmpwi cr0, N, 0
blelr- cr0

fcmpu cr0, FZERO, ALPHA
bne- cr0, LL(A1I1)
// fcmpu cr0, FZERO, ALPHA
// bne- cr0, LL(A1I1)
b LL(A1I1)

cmpwi cr0, INCX, SIZE
bne- cr0, LL(A0IN)
Expand Down
57 changes: 44 additions & 13 deletions kernel/power/sscal.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,38 @@ static void sscal_kernel_16_zero( BLASLONG n, FLOAT *x )

for( i=0; i<n; i+=8 )
{
x[0] = alpha;
x[1] = alpha;
x[2] = alpha;
x[3] = alpha;
x[4] = alpha;
x[5] = alpha;
x[6] = alpha;
x[7] = alpha;
if (isfinite(x[0]))
x[0] = alpha;
else
x[0] = NAN;
if (isfinite(x[1]))
x[1] = alpha;
else
x[1] = NAN;
if (isfinite(x[2]))
x[2] = alpha;
else
x[2] = NAN;
if (isfinite(x[3]))
x[3] = alpha;
else
x[3] = NAN;
if (isfinite(x[4]))
x[4] = alpha;
else
x[4] = NAN;
if (isfinite(x[5]))
x[5] = alpha;
else
x[5] = NAN;
if (isfinite(x[6]))
x[6] = alpha;
else
x[6] = NAN;
if (isfinite(x[7]))
x[7] = alpha;
else
x[7] = NAN;
x+=8;
}

Expand Down Expand Up @@ -109,7 +133,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
{
BLASLONG align = ((32 - ((uintptr_t)x & (uintptr_t)0x1F)) >> 2) & 0x7;
for (j = 0; j < align; j++) {
x[j] = 0.0;
if (isfinite(x[j]))
x[j] = 0.0;
else
x[j] = NAN;
}
}
BLASLONG n1 = (n-j) & -32;
Expand All @@ -129,8 +156,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS

while(j < n)
{

x[j]=0.0;
if (isfinite(x[j]))
x[j]=0.0;
else
x[j]=NAN;
j++;
}

Expand Down Expand Up @@ -178,8 +207,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS

while(j < n)
{

x[i]=0.0;
if (isfinite(x[i]))
x[i]=0.0;
else
x[i]=NAN;
i += inc_x ;
j++;
}
Expand Down
5 changes: 4 additions & 1 deletion kernel/riscv64/scal.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
{

if ( da == 0.0 )
x[i]=0.0;
if (isfinite(x[i]))
x[i]=0.0;
else
x[i]=NAN;
else
x[i] = da * x[i] ;

Expand Down
4 changes: 2 additions & 2 deletions kernel/riscv64/scal_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
FLOAT_V_T v0, v1;
unsigned int gvl = 0;
if(inc_x == 1){
if(da == 0.0){
if (0){ //if(da == 0.0){
memset(&x[0], 0, n * sizeof(FLOAT));
}else{
gvl = VSETVL(n);
Expand All @@ -96,7 +96,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
}
}
}else{
if(da == 0.0){
if (0) { //if(da == 0.0){
BLASLONG stride_x = inc_x * sizeof(FLOAT);
BLASLONG ix = 0;
gvl = VSETVL(n);
Expand Down
4 changes: 2 additions & 2 deletions kernel/riscv64/zscal.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r,FLOAT da_i, F
{
temp = - da_i * x[ip+1] ;
if (isnan(x[ip]) || isinf(x[ip])) temp = NAN;
if (!isinf(x[ip+1]))
if (!isinf(x[ip+1]))
x[ip+1] = da_i * x[ip] ;
else x[ip+1] = NAN;
else x[ip+1] = NAN;
}
}
else
Expand Down
6 changes: 4 additions & 2 deletions kernel/sparc/scal.S
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@

FCLR(29)

FCMP ALPHA, FZERO
fbne .LL100
// FCMP ALPHA, FZERO
// fbne .LL100
b .LL100

sll INCX, BASE_SHIFT, INCX

cmp INCX, SIZE
Expand Down
3 changes: 2 additions & 1 deletion kernel/x86/scal.S
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
ftst
fnstsw %ax
andb $68, %ah
je .L300 # Alpha != ZERO
// je .L300 # Alpha != ZERO
jmp .L300

/* Alpha == ZERO */
cmpl $1,%esi
Expand Down
Loading
Loading