Skip to content

Commit c33bc84

Browse files
authored
Merge pull request #4729 from martin-frbg/issue4728
Fix handling of INF or NAN arguments in S/D/C SCAL
2 parents 8cbb797 + f3c364c commit c33bc84

File tree

19 files changed

+669
-89
lines changed

19 files changed

+669
-89
lines changed

kernel/arm64/scal.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
168168
cmp N, xzr
169169
ble .Lscal_kernel_L999
170170

171-
fcmp DA, #0.0
172-
beq .Lscal_kernel_zero
171+
//fcmp DA, #0.0
172+
//beq .Lscal_kernel_zero
173173

174174
cmp INC_X, #1
175175
bne .Lscal_kernel_S_BEGIN

kernel/mips/dscal_msa.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
4242

4343
if (1 == inc_x)
4444
{
45-
if (0.0 == da)
45+
if (0) //if (0.0 == da )
4646
{
4747
v2f64 zero_v = {0.0, 0.0};
4848

@@ -243,9 +243,11 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
243243
if (da == 0.0)
244244
{
245245
for (i = n; i--;)
246-
{
247-
*x = 0.0;
248-
246+
{
247+
if (isfinite(*x))
248+
*x = 0.0;
249+
else
250+
*x = NAN;
249251
x += inc_x;
250252
}
251253
}

kernel/mips/scal.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
3535
{
3636

3737
if ( da == 0.0 )
38-
x[i]=0.0;
38+
if (isnan(x[i])||isinf(x[i]))
39+
x[i]=NAN;
40+
else
41+
x[i]=0.0;
42+
else if (isnan(da))
43+
x[i]=NAN;
3944
else
4045
x[i] = da * x[i] ;
4146

kernel/mips/sscal_msa.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
4242

4343
if (1 == inc_x)
4444
{
45-
if (0.0 == da)
45+
if (0) // if (0.0 == da)
4646
{
4747
v4f32 zero_v = {0.0, 0.0, 0.0, 0.0};
4848

@@ -259,7 +259,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x,
259259
{
260260
for (i = n; i--;)
261261
{
262-
*x = 0;
262+
if (isfinite(*x))
263+
*x = 0;
264+
else
265+
*x = NAN;
263266
x += inc_x;
264267
}
265268
}

kernel/mips64/scal.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
bc1f $fcc0, .L50
8080
NOP
8181

82+
bc1t $fcc0, .L50
83+
NOP
84+
8285
bne INCX, TEMP, .L20
8386
dsra I, N, 3
8487

kernel/power/dscal.c

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,38 @@ static void dscal_kernel_8_zero (BLASLONG n, FLOAT *x)
7373

7474
for( i=0; i<n; i+=8 )
7575
{
76-
x[0] = alpha;
77-
x[1] = alpha;
78-
x[2] = alpha;
79-
x[3] = alpha;
80-
x[4] = alpha;
81-
x[5] = alpha;
82-
x[6] = alpha;
83-
x[7] = alpha;
76+
if(isfinite(x[0]))
77+
x[0] = alpha;
78+
else
79+
x[0] = NAN;
80+
if(isfinite(x[1]))
81+
x[1] = alpha;
82+
else
83+
x[1] = NAN;
84+
if (isfinite(x[2]))
85+
x[2] = alpha;
86+
else
87+
x[2] = NAN;
88+
if (isfinite(x[3]))
89+
x[3] = alpha;
90+
else
91+
x[3] = NAN;
92+
if (isfinite(x[4]))
93+
x[4] = alpha;
94+
else
95+
x[4] = NAN;
96+
if (isfinite(x[5]))
97+
x[5] = alpha;
98+
else
99+
x[5] = NAN;
100+
if (isfinite(x[6]))
101+
x[6] = alpha;
102+
else
103+
x[6] = NAN;
104+
if (isfinite(x[7]))
105+
x[7] = alpha;
106+
else
107+
x[7] = NAN;
84108
x+=8;
85109
}
86110

@@ -107,7 +131,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
107131
{
108132
BLASLONG align = ((32 - ((uintptr_t)x & (uintptr_t)0x1F)) >> 3) & 0x3;
109133
for (j = 0; j < align; j++) {
110-
x[j] = 0.0;
134+
if (isfinite(x[j]))
135+
x[j] = 0.0;
136+
else
137+
x[j] = NAN;
111138
}
112139
}
113140
BLASLONG n1 = (n-j) & -16;
@@ -127,8 +154,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
127154

128155
while(j < n)
129156
{
130-
131-
x[j]=0.0;
157+
if (!isfinite(x[j]))
158+
x[j]=NAN;
159+
else
160+
x[j]=0.0;
132161
j++;
133162
}
134163

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

177206
while(j < n)
178207
{
179-
180-
x[i]=0.0;
208+
if (!isfinite(x[i]))
209+
x[i]=NAN;
210+
else
211+
x[i]=0.0;
181212
i += inc_x ;
182213
j++;
183214
}

kernel/power/scal.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@
8484
cmpwi cr0, N, 0
8585
blelr- cr0
8686

87-
fcmpu cr0, FZERO, ALPHA
88-
bne- cr0, LL(A1I1)
87+
// fcmpu cr0, FZERO, ALPHA
88+
// bne- cr0, LL(A1I1)
89+
b LL(A1I1)
8990

9091
cmpwi cr0, INCX, SIZE
9192
bne- cr0, LL(A0IN)

kernel/power/sscal.c

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,38 @@ static void sscal_kernel_16_zero( BLASLONG n, FLOAT *x )
7474

7575
for( i=0; i<n; i+=8 )
7676
{
77-
x[0] = alpha;
78-
x[1] = alpha;
79-
x[2] = alpha;
80-
x[3] = alpha;
81-
x[4] = alpha;
82-
x[5] = alpha;
83-
x[6] = alpha;
84-
x[7] = alpha;
77+
if (isfinite(x[0]))
78+
x[0] = alpha;
79+
else
80+
x[0] = NAN;
81+
if (isfinite(x[1]))
82+
x[1] = alpha;
83+
else
84+
x[1] = NAN;
85+
if (isfinite(x[2]))
86+
x[2] = alpha;
87+
else
88+
x[2] = NAN;
89+
if (isfinite(x[3]))
90+
x[3] = alpha;
91+
else
92+
x[3] = NAN;
93+
if (isfinite(x[4]))
94+
x[4] = alpha;
95+
else
96+
x[4] = NAN;
97+
if (isfinite(x[5]))
98+
x[5] = alpha;
99+
else
100+
x[5] = NAN;
101+
if (isfinite(x[6]))
102+
x[6] = alpha;
103+
else
104+
x[6] = NAN;
105+
if (isfinite(x[7]))
106+
x[7] = alpha;
107+
else
108+
x[7] = NAN;
85109
x+=8;
86110
}
87111

@@ -109,7 +133,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
109133
{
110134
BLASLONG align = ((32 - ((uintptr_t)x & (uintptr_t)0x1F)) >> 2) & 0x7;
111135
for (j = 0; j < align; j++) {
112-
x[j] = 0.0;
136+
if (isfinite(x[j]))
137+
x[j] = 0.0;
138+
else
139+
x[j] = NAN;
113140
}
114141
}
115142
BLASLONG n1 = (n-j) & -32;
@@ -129,8 +156,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
129156

130157
while(j < n)
131158
{
132-
133-
x[j]=0.0;
159+
if (isfinite(x[j]))
160+
x[j]=0.0;
161+
else
162+
x[j]=NAN;
134163
j++;
135164
}
136165

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

179208
while(j < n)
180209
{
181-
182-
x[i]=0.0;
210+
if (isfinite(x[i]))
211+
x[i]=0.0;
212+
else
213+
x[i]=NAN;
183214
i += inc_x ;
184215
j++;
185216
}

kernel/riscv64/scal.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
4848
{
4949

5050
if ( da == 0.0 )
51-
x[i]=0.0;
51+
if (isfinite(x[i]))
52+
x[i]=0.0;
53+
else
54+
x[i]=NAN;
5255
else
5356
x[i] = da * x[i] ;
5457

kernel/riscv64/scal_vector.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
7171
FLOAT_V_T v0, v1;
7272
unsigned int gvl = 0;
7373
if(inc_x == 1){
74-
if(da == 0.0){
74+
if (0){ //if(da == 0.0){
7575
memset(&x[0], 0, n * sizeof(FLOAT));
7676
}else{
7777
gvl = VSETVL(n);
@@ -96,7 +96,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
9696
}
9797
}
9898
}else{
99-
if(da == 0.0){
99+
if (0) { //if(da == 0.0){
100100
BLASLONG stride_x = inc_x * sizeof(FLOAT);
101101
BLASLONG ix = 0;
102102
gvl = VSETVL(n);

kernel/riscv64/zscal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r,FLOAT da_i, F
6161
{
6262
temp = - da_i * x[ip+1] ;
6363
if (isnan(x[ip]) || isinf(x[ip])) temp = NAN;
64-
if (!isinf(x[ip+1]))
64+
if (!isinf(x[ip+1]))
6565
x[ip+1] = da_i * x[ip] ;
66-
else x[ip+1] = NAN;
66+
else x[ip+1] = NAN;
6767
}
6868
}
6969
else

kernel/sparc/scal.S

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@
120120

121121
FCLR(29)
122122

123-
FCMP ALPHA, FZERO
124-
fbne .LL100
123+
// FCMP ALPHA, FZERO
124+
// fbne .LL100
125+
b .LL100
126+
125127
sll INCX, BASE_SHIFT, INCX
126128

127129
cmp INCX, SIZE

kernel/x86/scal.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
ftst
6969
fnstsw %ax
7070
andb $68, %ah
71-
je .L300 # Alpha != ZERO
71+
// je .L300 # Alpha != ZERO
72+
jmp .L300
7273

7374
/* Alpha == ZERO */
7475
cmpl $1,%esi

0 commit comments

Comments
 (0)