Skip to content

Commit e114880

Browse files
committed
kernel/generic: Fixed cscal and zscal
1 parent 7c3a920 commit e114880

File tree

2 files changed

+42
-51
lines changed

2 files changed

+42
-51
lines changed

interface/zscal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void CNAME(blasint n, FLOAT alpha_r, void *vx, blasint incx){
9898
if (nthreads == 1) {
9999
#endif
100100

101-
SCAL_K(n, 0, 0, alpha[0], alpha[1], x, incx, NULL, 0, NULL, 0);
101+
SCAL_K(n, 0, 0, alpha[0], alpha[1], x, incx, NULL, 0, NULL, 1);
102102

103103
#ifdef SMP
104104
} else {
@@ -108,7 +108,7 @@ void CNAME(blasint n, FLOAT alpha_r, void *vx, blasint incx){
108108
mode = BLAS_SINGLE | BLAS_COMPLEX;
109109
#endif
110110

111-
blas_level1_thread(mode, n, 0, 0, alpha, x, incx, NULL, 0, NULL, 0, (int (*)(void))SCAL_K, nthreads);
111+
blas_level1_thread(mode, n, 0, 0, alpha, x, incx, NULL, 0, NULL, 1, (int (*)(void))SCAL_K, nthreads);
112112

113113
}
114114
#endif

kernel/arm/zscal.c

+40-49
Original file line numberDiff line numberDiff line change
@@ -27,65 +27,56 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727

2828
/**************************************************************************************
2929
* 2013/09/14 Saar
30-
* BLASTEST float : OK
31-
* BLASTEST double : OK
32-
* CTEST : OK
33-
* TEST : OK
30+
* BLASTEST float : OK
31+
* BLASTEST double : OK
32+
* CTEST : OK
33+
* TEST : OK
3434
*
3535
**************************************************************************************/
3636

3737
#include "common.h"
3838

39+
// The c/zscal_k function is called not only by cblas_c/zscal but also by other upper-level interfaces.
40+
// In certain cases, the expected return values for cblas_s/zscal differ from those of other upper-level interfaces.
41+
// To handle this, we use the dummy2 parameter to differentiate between them.
3942
int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r,FLOAT da_i, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *dummy, BLASLONG dummy2)
4043
{
41-
BLASLONG i=0;
42-
BLASLONG inc_x2;
43-
BLASLONG ip = 0;
44-
FLOAT temp;
44+
BLASLONG i = 0;
45+
BLASLONG inc_x2;
46+
BLASLONG ip = 0;
47+
FLOAT temp;
4548

46-
if ( (n <= 0) || (inc_x <= 0))
47-
return(0);
49+
if ((n <= 0) || (inc_x <= 0))
50+
return(0);
4851

52+
inc_x2 = 2 * inc_x;
53+
if (dummy2 == 0) {
54+
for (i = 0; i < n; i++)
55+
{
56+
if (da_r == 0.0 && da_i == 0.0)
57+
{
58+
x[ip] = 0.0;
59+
x[ip+1] = 0.0;
60+
}
61+
else
62+
{
63+
temp = da_r * x[ip] - da_i * x[ip+1];
64+
x[ip+1] = da_r * x[ip+1] + da_i * x[ip] ;
65+
x[ip] = temp;
66+
}
4967

50-
inc_x2 = 2 * inc_x;
51-
for ( i=0; i<n; i++ )
52-
{
53-
if ( da_r == 0.0 )
54-
{
55-
if ( da_i == 0.0 )
56-
{
57-
temp = 0.0;
58-
x[ip+1] = 0.0 ;
59-
}
60-
else
61-
{
62-
temp = - da_i * x[ip+1] ;
63-
if (isnan(x[ip]) || isinf(x[ip])) temp = NAN;
64-
if (!isinf(x[ip+1]))
65-
x[ip+1] = da_i * x[ip] ;
66-
else x[ip+1] = NAN;
67-
}
68-
}
69-
else
70-
{
71-
if ( da_i == 0.0 )
72-
{
73-
temp = da_r * x[ip] ;
74-
x[ip+1] = da_r * x[ip+1];
75-
}
76-
else
77-
{
78-
temp = da_r * x[ip] - da_i * x[ip+1] ;
79-
x[ip+1] = da_r * x[ip+1] + da_i * x[ip] ;
80-
}
81-
}
82-
x[ip] = temp;
68+
ip += inc_x2;
69+
}
70+
return(0);
71+
}
72+
for (i = 0; i < n; i++)
73+
{
74+
temp = da_r * x[ip] - da_i * x[ip+1];
75+
x[ip+1] = da_r * x[ip+1] + da_i * x[ip] ;
8376

84-
ip += inc_x2;
85-
}
86-
87-
return(0);
77+
x[ip] = temp;
78+
ip += inc_x2;
79+
}
8880

81+
return(0);
8982
}
90-
91-

0 commit comments

Comments
 (0)