Skip to content

Commit 110c7a6

Browse files
authored
Merge pull request #2979 from RajalakshmiSR/dot_power10
Optimize sdot/ddot for POWER10
2 parents d2faa1b + 6e36498 commit 110c7a6

File tree

5 files changed

+553
-3
lines changed

5 files changed

+553
-3
lines changed

kernel/power/KERNEL.POWER10

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ DCOPYKERNEL = dcopy_power10.c
151151
CCOPYKERNEL = ccopy_power10.c
152152
ZCOPYKERNEL = zcopy_power10.c
153153
#
154-
SDOTKERNEL = sdot.c
155-
DDOTKERNEL = ddot.c
156-
DSDOTKERNEL = sdot.c
154+
SDOTKERNEL = sdot_power10.c
155+
DDOTKERNEL = ddot_power10.c
156+
DSDOTKERNEL = sdot_power10.c
157157
ifneq ($(GCCVERSIONGTEQ9),1)
158158
CDOTKERNEL = cdot_power9.S
159159
else

kernel/power/ddot_microk_power10.c

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/***************************************************************************
2+
Copyright (c) 2020, The OpenBLAS Project
3+
All rights reserved.
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in
11+
the documentation and/or other materials provided with the
12+
distribution.
13+
3. Neither the name of the OpenBLAS project nor the names of
14+
its contributors may be used to endorse or promote products
15+
derived from this software without specific prior written permission.
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*****************************************************************************/
27+
28+
#define HAVE_KERNEL_8 1
29+
30+
static double ddot_kernel_8 (long n, double *x, double *y)
31+
{
32+
double dot;
33+
34+
__asm__
35+
(
36+
"dcbt 0, %2 \n\t"
37+
"dcbt 0, %3 \n\t"
38+
39+
"xxlxor 32, 32, 32 \n\t"
40+
"xxlxor 33, 33, 33 \n\t"
41+
"xxlxor 34, 34, 34 \n\t"
42+
"xxlxor 35, 35, 35 \n\t"
43+
"xxlxor 36, 36, 36 \n\t"
44+
"xxlxor 37, 37, 37 \n\t"
45+
"xxlxor 38, 38, 38 \n\t"
46+
"xxlxor 39, 39, 39 \n\t"
47+
48+
"lxvp 40, 0(%2) \n\t"
49+
"lxvp 42, 32(%2) \n\t"
50+
"lxvp 44, 64(%2) \n\t"
51+
"lxvp 46, 96(%2) \n\t"
52+
"lxvp 48, 0(%3) \n\t"
53+
"lxvp 50, 32(%3) \n\t"
54+
"lxvp 52, 64(%3) \n\t"
55+
"lxvp 54, 96(%3) \n\t"
56+
57+
"addi %2, %2, 128 \n\t"
58+
"addi %3, %3, 128 \n\t"
59+
60+
"addic. %1, %1, -16 \n\t"
61+
"ble two%= \n\t"
62+
63+
".align 5 \n"
64+
"one%=: \n\t"
65+
66+
"xvmaddadp 32, 40, 48 \n\t"
67+
"xvmaddadp 33, 41, 49 \n\t"
68+
"lxvp 40, 0(%2) \n\t"
69+
"lxvp 48, 0(%3) \n\t"
70+
"xvmaddadp 34, 42, 50 \n\t"
71+
"xvmaddadp 35, 43, 51 \n\t"
72+
"lxvp 42, 32(%2) \n\t"
73+
"lxvp 50, 32(%3) \n\t"
74+
"xvmaddadp 36, 44, 52 \n\t"
75+
"xvmaddadp 37, 45, 53 \n\t"
76+
"lxvp 44, 64(%2) \n\t"
77+
"lxvp 52, 64(%3) \n\t"
78+
"xvmaddadp 38, 46, 54 \n\t"
79+
"xvmaddadp 39, 47, 55 \n\t"
80+
"lxvp 46, 96(%2) \n\t"
81+
"lxvp 54, 96(%3) \n\t"
82+
83+
"addi %2, %2, 128 \n\t"
84+
"addi %3, %3, 128 \n\t"
85+
86+
"addic. %1, %1, -16 \n\t"
87+
"bgt one%= \n"
88+
89+
"two%=: \n\t"
90+
91+
"xvmaddadp 32, 40, 48 \n\t"
92+
"xvmaddadp 33, 41, 49 \n\t"
93+
"xvmaddadp 34, 42, 50 \n\t"
94+
"xvmaddadp 35, 43, 51 \n\t"
95+
"xvmaddadp 36, 44, 52 \n\t"
96+
"xvmaddadp 37, 45, 53 \n\t"
97+
"xvmaddadp 38, 46, 54 \n\t"
98+
"xvmaddadp 39, 47, 55 \n\t"
99+
100+
"xvadddp 32, 32, 33 \n\t"
101+
"xvadddp 34, 34, 35 \n\t"
102+
"xvadddp 36, 36, 37 \n\t"
103+
"xvadddp 38, 38, 39 \n\t"
104+
105+
"xvadddp 32, 32, 34 \n\t"
106+
"xvadddp 36, 36, 38 \n\t"
107+
108+
"xvadddp 32, 32, 36 \n\t"
109+
110+
XXSWAPD_S(33,32)
111+
112+
"xsadddp %x0, 32, 33 \n"
113+
114+
"#dot=%0 n=%1 x=%4=%2 y=%5=%3\n"
115+
:
116+
"=d" (dot), // 0
117+
"+r" (n), // 1
118+
"+b" (x), // 2
119+
"+b" (y) // 3
120+
:
121+
"m" (*x),
122+
"m" (*y)
123+
:
124+
"cr0",
125+
"vs32","vs33","vs34","vs35","vs36","vs37","vs38","vs39",
126+
"vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47",
127+
"vs48","vs49","vs50","vs51","vs52","vs53","vs54","vs55"
128+
);
129+
130+
return dot;
131+
}

kernel/power/ddot_power10.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/***************************************************************************
2+
Copyright (c) 2013-2016, The OpenBLAS Project
3+
All rights reserved.
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in
11+
the documentation and/or other materials provided with the
12+
distribution.
13+
3. Neither the name of the OpenBLAS project nor the names of
14+
its contributors may be used to endorse or promote products
15+
derived from this software without specific prior written permission.
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*****************************************************************************/
27+
28+
#include "common.h"
29+
30+
31+
#if defined(__VEC__) || defined(__ALTIVEC__)
32+
#include "ddot_microk_power10.c"
33+
#endif
34+
35+
36+
#ifndef HAVE_KERNEL_8
37+
38+
static FLOAT ddot_kernel_8 (BLASLONG n, FLOAT *x, FLOAT *y)
39+
{
40+
BLASLONG register i = 0;
41+
FLOAT dot = 0.0;
42+
43+
while(i < n)
44+
{
45+
dot += y[i] * x[i]
46+
+ y[i+1] * x[i+1]
47+
+ y[i+2] * x[i+2]
48+
+ y[i+3] * x[i+3]
49+
+ y[i+4] * x[i+4]
50+
+ y[i+5] * x[i+5]
51+
+ y[i+6] * x[i+6]
52+
+ y[i+7] * x[i+7] ;
53+
54+
i+=8 ;
55+
56+
}
57+
return dot;
58+
}
59+
60+
#endif
61+
62+
FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
63+
{
64+
BLASLONG i=0;
65+
BLASLONG ix=0,iy=0;
66+
67+
FLOAT dot = 0.0 ;
68+
69+
if ( n <= 0 ) return(dot);
70+
71+
if ( (inc_x == 1) && (inc_y == 1) )
72+
{
73+
74+
BLASLONG n1 = n & -16;
75+
76+
if ( n1 )
77+
dot = ddot_kernel_8(n1, x, y);
78+
79+
i = n1;
80+
while(i < n)
81+
{
82+
83+
dot += y[i] * x[i] ;
84+
i++ ;
85+
86+
}
87+
return(dot);
88+
89+
90+
}
91+
92+
FLOAT temp1 = 0.0;
93+
FLOAT temp2 = 0.0;
94+
95+
BLASLONG n1 = n & -4;
96+
97+
while(i < n1)
98+
{
99+
100+
FLOAT m1 = y[iy] * x[ix] ;
101+
FLOAT m2 = y[iy+inc_y] * x[ix+inc_x] ;
102+
103+
FLOAT m3 = y[iy+2*inc_y] * x[ix+2*inc_x] ;
104+
FLOAT m4 = y[iy+3*inc_y] * x[ix+3*inc_x] ;
105+
106+
ix += inc_x*4 ;
107+
iy += inc_y*4 ;
108+
109+
temp1 += m1+m3;
110+
temp2 += m2+m4;
111+
112+
i+=4 ;
113+
114+
}
115+
116+
while(i < n)
117+
{
118+
119+
temp1 += y[iy] * x[ix] ;
120+
ix += inc_x ;
121+
iy += inc_y ;
122+
i++ ;
123+
124+
}
125+
dot = temp1 + temp2;
126+
return(dot);
127+
128+
}
129+
130+

0 commit comments

Comments
 (0)