-
Notifications
You must be signed in to change notification settings - Fork 0
/
daxpy.c
57 lines (50 loc) · 1.24 KB
/
daxpy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "blas.h"
#ifdef __cplusplus
extern "C" {
#endif
int daxpy_(int *n, float *sa, float *sx, int *incx, float *sy,
int *incy)
{
long int i, m, ix, iy, nn, iincx, iincy;
register float ssa;
/* constant times a vector plus a vector.
uses unrolled loop for increments equal to one.
jack dongarra, linpack, 3/11/78.
modified 12/3/93, array(1) declarations changed to array(*) */
/* Dereference inputs */
nn = *n;
ssa = *sa;
iincx = *incx;
iincy = *incy;
if( nn > 0 && ssa != 0.0 )
{
if (iincx == 1 && iincy == 1) /* code for both increments equal to 1 */
{
m = nn-3;
for (i = 0; i < m; i += 4)
{
sy[i] += ssa * sx[i];
sy[i+1] += ssa * sx[i+1];
sy[i+2] += ssa * sx[i+2];
sy[i+3] += ssa * sx[i+3];
}
for ( ; i < nn; ++i) /* clean-up loop */
sy[i] += ssa * sx[i];
}
else /* code for unequal increments or equal increments not equal to 1 */
{
ix = iincx >= 0 ? 0 : (1 - nn) * iincx;
iy = iincy >= 0 ? 0 : (1 - nn) * iincy;
for (i = 0; i < nn; i++)
{
sy[iy] += ssa * sx[ix];
ix += iincx;
iy += iincy;
}
}
}
return 0;
} /* daxpy_ */
#ifdef __cplusplus
}
#endif