Skip to content

Commit 439b93f

Browse files
author
Rajalakshmi Srinivasaraghavan
committed
Optimize s/drot function for POWER10
This patch makes use of new POWER10 vector pair instructions for loads and stores.
1 parent d6cf677 commit 439b93f

File tree

4 files changed

+341
-2
lines changed

4 files changed

+341
-2
lines changed

kernel/power/drot.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3939

4040
#pragma GCC optimize "O1"
4141

42-
#if defined(POWER8) || defined(POWER9) || defined(POWER10)
4342
#if defined(__VEC__) || defined(__ALTIVEC__)
43+
#if defined(POWER8) || defined(POWER9)
4444
#include "drot_microk_power8.c"
45+
#elif defined(POWER10)
46+
#include "drot_microk_power10.c"
4547
#endif
4648
#endif
4749

@@ -115,12 +117,30 @@ int CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT
115117
if ( (inc_x == 1) && (inc_y == 1) )
116118
{
117119

120+
#if defined(POWER10)
121+
if ( n >= 16 )
122+
{
123+
BLASLONG align = ((32 - ((uintptr_t)y & (uintptr_t)0x1F)) >> 3) & 0x3;
124+
for (i = 0; i < align; i++) {
125+
temp = c*x[i] + s*y[i] ;
126+
y[i] = c*y[i] - s*x[i] ;
127+
x[i] = temp ;
128+
}
129+
}
130+
BLASLONG n1 = (n-i) & -16;
131+
if ( n1 > 0 )
132+
{
133+
drot_kernel_16(n1,&x[i], &y[i], c, s);
134+
i+=n1;
135+
}
136+
#else
118137
BLASLONG n1 = n & -16;
119138
if ( n1 > 0 )
120139
{
121140
drot_kernel_16(n1, x1, y1, c, s);
122141
i=n1;
123142
}
143+
#endif
124144

125145
while(i < n)
126146
{

kernel/power/drot_microk_power10.c

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/***************************************************************************
2+
Copyright (c) 2021, 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_16 1
29+
30+
static void drot_kernel_16 (long n, double *x, double *y, double c, double s)
31+
{
32+
__asm__
33+
(
34+
XXSPLTD_S(36,%x5,0) // load c to both dwords
35+
XXSPLTD_S(37,%x6,0) // load s to both dwords
36+
"lxvp 32, 0(%3) \n\t" // load x
37+
"lxvp 34, 32(%3) \n\t"
38+
"lxvp 48, 0(%4) \n\t" // load y
39+
"lxvp 50, 32(%4) \n\t"
40+
41+
"addic. %2, %2, -8 \n\t"
42+
"ble two%= \n\t"
43+
44+
".align 5 \n"
45+
"one%=: \n\t"
46+
47+
"xvmuldp 40, 32, 36 \n\t" // c * x
48+
"xvmuldp 41, 33, 36 \n\t"
49+
"xvmuldp 42, 34, 36 \n\t"
50+
"xvmuldp 43, 35, 36 \n\t"
51+
52+
"xvmuldp 44, 32, 37 \n\t" // s * x
53+
"xvmuldp 45, 33, 37 \n\t"
54+
"xvmuldp 46, 34, 37 \n\t"
55+
"xvmuldp 47, 35, 37 \n\t"
56+
57+
"lxvp 32, 64(%3) \n\t" // load x
58+
"lxvp 34, 96(%3) \n\t"
59+
"xvmuldp 52, 48, 36 \n\t" // c * y
60+
"xvmuldp 53, 49, 36 \n\t"
61+
"xvmuldp 54, 50, 36 \n\t"
62+
"xvmuldp 55, 51, 36 \n\t"
63+
64+
"xvmuldp 38, 48, 37 \n\t" // s * y
65+
"xvmuldp 39, 49, 37 \n\t"
66+
"xvmuldp 56, 50, 37 \n\t"
67+
"xvmuldp 57, 51, 37 \n\t"
68+
69+
"lxvp 48, 64(%4) \n\t" // load y
70+
"lxvp 50, 96(%4) \n\t"
71+
72+
"xvadddp 40, 40, 38 \n\t" // c * x + s * y
73+
"xvadddp 41, 41, 39 \n\t" // c * x + s * y
74+
"xvadddp 42, 42, 56 \n\t" // c * x + s * y
75+
"xvadddp 43, 43, 57 \n\t" // c * x + s * y
76+
77+
"stxvp 40, 0(%3) \n\t" // store x
78+
"stxvp 42, 32(%3) \n\t"
79+
80+
"xvsubdp 52, 52, 44 \n\t" // c * y - s * x
81+
"xvsubdp 53, 53, 45 \n\t" // c * y - s * x
82+
"xvsubdp 54, 54, 46 \n\t" // c * y - s * x
83+
"xvsubdp 55, 55, 47 \n\t" // c * y - s * x
84+
85+
"stxvp 52, 0(%4) \n\t" // store y
86+
"stxvp 54, 32(%4) \n\t"
87+
88+
"addi %3, %3, 64 \n\t"
89+
"addi %4, %4, 64 \n\t"
90+
91+
"addic. %2, %2, -8 \n\t"
92+
"bgt one%= \n"
93+
94+
"two%=: \n\t"
95+
96+
"xvmuldp 40, 32, 36 \n\t" // c * x
97+
"xvmuldp 41, 33, 36 \n\t"
98+
"xvmuldp 42, 34, 36 \n\t"
99+
"xvmuldp 43, 35, 36 \n\t"
100+
101+
"xvmuldp 52, 48, 36 \n\t" // c * y
102+
"xvmuldp 53, 49, 36 \n\t"
103+
"xvmuldp 54, 50, 36 \n\t"
104+
"xvmuldp 55, 51, 36 \n\t"
105+
106+
"xvmuldp 44, 32, 37 \n\t" // s * x
107+
"xvmuldp 45, 33, 37 \n\t"
108+
"xvmuldp 46, 34, 37 \n\t"
109+
"xvmuldp 47, 35, 37 \n\t"
110+
111+
"xvmuldp 38, 48, 37 \n\t" // s * y
112+
"xvmuldp 39, 49, 37 \n\t"
113+
"xvmuldp 56, 50, 37 \n\t"
114+
"xvmuldp 57, 51, 37 \n\t"
115+
116+
"xvadddp 40, 40, 38 \n\t" // c * x + s * y
117+
"xvadddp 41, 41, 39 \n\t" // c * x + s * y
118+
"xvadddp 42, 42, 56 \n\t" // c * x + s * y
119+
"xvadddp 43, 43, 57 \n\t" // c * x + s * y
120+
121+
"stxvp 40, 0(%3) \n\t" // store x
122+
"stxvp 42, 32(%3) \n\t"
123+
"xvsubdp 52, 52, 44 \n\t" // c * y - s * x
124+
"xvsubdp 53, 53, 45 \n\t" // c * y - s * x
125+
"xvsubdp 54, 54, 46 \n\t" // c * y - s * x
126+
"xvsubdp 55, 55, 47 \n\t" // c * y - s * x
127+
128+
"stxvp 52, 0(%4) \n\t" // store y
129+
"stxvp 54, 32(%4) \n\t"
130+
131+
"#n=%2 x=%0=%3 y=%1=%4 c=%5 s=%6\n"
132+
:
133+
"+m" (*x),
134+
"+m" (*y),
135+
"+r" (n), // 2
136+
"+b" (x), // 3
137+
"+b" (y) // 4
138+
:
139+
"d" (c), // 5
140+
"d" (s) // 6
141+
:
142+
"cr0",
143+
"vs32","vs33","vs34","vs35","vs36","vs37","vs38","vs39",
144+
"vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47",
145+
"vs48","vs49","vs50","vs51","vs52","vs53","vs54","vs55",
146+
"vs56","vs57"
147+
);
148+
}

kernel/power/srot.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3939

4040
#pragma GCC optimize "O1"
4141

42-
#if defined(POWER8) || defined(POWER9) || defined(POWER10)
4342
#if defined(__VEC__) || defined(__ALTIVEC__)
43+
#if defined(POWER8) || defined(POWER9)
4444
#include "srot_microk_power8.c"
45+
#elif defined(POWER10)
46+
#include "srot_microk_power10.c"
4547
#endif
4648
#endif
4749

@@ -115,13 +117,31 @@ int CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT
115117
if ( (inc_x == 1) && (inc_y == 1) )
116118
{
117119

120+
#if defined(POWER10)
121+
if ( n >= 16 )
122+
{
123+
BLASLONG align = ((32 - ((uintptr_t)y & (uintptr_t)0x1F)) >> 2) & 0x7;
124+
for (i = 0; i < align; i++) {
125+
temp = c*x[i] + s*y[i] ;
126+
y[i] = c*y[i] - s*x[i] ;
127+
x[i] = temp ;
128+
}
129+
}
130+
BLASLONG n1 = (n-i) & -16;
131+
if ( n1 > 0 )
132+
{
133+
srot_kernel_16(n1, &x1[i], &y1[i], c, s);
134+
i+=n1;
135+
}
136+
#else
118137
BLASLONG n1 = n & -16;
119138
if ( n1 > 0 )
120139
{
121140
srot_kernel_16(n1, x1, y1, c, s);
122141
i=n1;
123142
}
124143

144+
#endif
125145
while(i < n)
126146
{
127147
temp = c*x[i] + s*y[i] ;

kernel/power/srot_microk_power10.c

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/***************************************************************************
2+
Copyright (c) 2021, 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_16 1
29+
30+
static void srot_kernel_16 (long n, float *x, float *y, float c, float s)
31+
{
32+
__asm__
33+
(
34+
"xscvdpspn 36, %x5 \n\t" // load c to all words
35+
"xxspltw 36, 36, 0 \n\t"
36+
37+
"xscvdpspn 37, %x6 \n\t" // load s to all words
38+
"xxspltw 37, 37, 0 \n\t"
39+
"lxvp 32, 0(%3) \n\t" // load x
40+
"lxvp 34, 32(%3) \n\t"
41+
"lxvp 48, 0(%4) \n\t" // load y
42+
"lxvp 50, 32(%4) \n\t"
43+
44+
"addic. %2, %2, -16 \n\t"
45+
"ble two%= \n\t"
46+
47+
".align 5 \n"
48+
"one%=: \n\t"
49+
50+
"xvmulsp 40, 32, 36 \n\t" // c * x
51+
"xvmulsp 41, 33, 36 \n\t"
52+
"xvmulsp 42, 34, 36 \n\t"
53+
"xvmulsp 43, 35, 36 \n\t"
54+
55+
"xvmulsp 44, 32, 37 \n\t" // s * x
56+
"xvmulsp 45, 33, 37 \n\t"
57+
"xvmulsp 46, 34, 37 \n\t"
58+
"xvmulsp 47, 35, 37 \n\t"
59+
60+
"lxvp 32, 64(%3) \n\t" // load x
61+
"lxvp 34, 96(%3) \n\t"
62+
"xvmulsp 52, 48, 36 \n\t" // c * y
63+
"xvmulsp 53, 49, 36 \n\t"
64+
"xvmulsp 54, 50, 36 \n\t"
65+
"xvmulsp 55, 51, 36 \n\t"
66+
67+
"xvmulsp 38, 48, 37 \n\t" // s * y
68+
"xvmulsp 39, 49, 37 \n\t"
69+
"xvmulsp 56, 50, 37 \n\t"
70+
"xvmulsp 57, 51, 37 \n\t"
71+
72+
"lxvp 48, 64(%4) \n\t" // load y
73+
"lxvp 50, 96(%4) \n\t"
74+
75+
"xvaddsp 40, 40, 38 \n\t" // c * x + s * y
76+
"xvaddsp 41, 41, 39 \n\t" // c * x + s * y
77+
"xvaddsp 42, 42, 56 \n\t" // c * x + s * y
78+
"xvaddsp 43, 43, 57 \n\t" // c * x + s * y
79+
80+
"stxvp 40, 0(%3) \n\t" // store x
81+
"stxvp 42, 32(%3) \n\t"
82+
83+
"xvsubsp 52, 52, 44 \n\t" // c * y - s * x
84+
"xvsubsp 53, 53, 45 \n\t" // c * y - s * x
85+
"xvsubsp 54, 54, 46 \n\t" // c * y - s * x
86+
"xvsubsp 55, 55, 47 \n\t" // c * y - s * x
87+
88+
"stxvp 52, 0(%4) \n\t" // store y
89+
"stxvp 54, 32(%4) \n\t"
90+
91+
"addi %3, %3, 64 \n\t"
92+
"addi %4, %4, 64 \n\t"
93+
94+
"addic. %2, %2, -16 \n\t"
95+
"bgt one%= \n"
96+
97+
"two%=: \n\t"
98+
99+
"xvmulsp 40, 32, 36 \n\t" // c * x
100+
"xvmulsp 41, 33, 36 \n\t"
101+
"xvmulsp 42, 34, 36 \n\t"
102+
"xvmulsp 43, 35, 36 \n\t"
103+
104+
"xvmulsp 52, 48, 36 \n\t" // c * y
105+
"xvmulsp 53, 49, 36 \n\t"
106+
"xvmulsp 54, 50, 36 \n\t"
107+
"xvmulsp 55, 51, 36 \n\t"
108+
109+
"xvmulsp 44, 32, 37 \n\t" // s * x
110+
"xvmulsp 45, 33, 37 \n\t"
111+
"xvmulsp 46, 34, 37 \n\t"
112+
"xvmulsp 47, 35, 37 \n\t"
113+
114+
"xvmulsp 38, 48, 37 \n\t" // s * y
115+
"xvmulsp 39, 49, 37 \n\t"
116+
"xvmulsp 56, 50, 37 \n\t"
117+
"xvmulsp 57, 51, 37 \n\t"
118+
119+
"xvaddsp 40, 40, 38 \n\t" // c * x + s * y
120+
"xvaddsp 41, 41, 39 \n\t" // c * x + s * y
121+
"xvaddsp 42, 42, 56 \n\t" // c * x + s * y
122+
"xvaddsp 43, 43, 57 \n\t" // c * x + s * y
123+
124+
"stxvp 40, 0(%3) \n\t" // store x
125+
"stxvp 42, 32(%3) \n\t"
126+
"xvsubsp 52, 52, 44 \n\t" // c * y - s * x
127+
"xvsubsp 53, 53, 45 \n\t" // c * y - s * x
128+
"xvsubsp 54, 54, 46 \n\t" // c * y - s * x
129+
"xvsubsp 55, 55, 47 \n\t" // c * y - s * x
130+
131+
"stxvp 52, 0(%4) \n\t" // store y
132+
"stxvp 54, 32(%4) \n\t"
133+
134+
"#n=%2 x=%0=%3 y=%1=%4 c=%5 s=%6\n"
135+
:
136+
"+m" (*x),
137+
"+m" (*y),
138+
"+r" (n), // 2
139+
"+b" (x), // 3
140+
"+b" (y) // 4
141+
:
142+
"f" (c), // 5
143+
"f" (s) // 6
144+
:
145+
"cr0",
146+
"vs32","vs33","vs34","vs35","vs36","vs37","vs38","vs39",
147+
"vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47",
148+
"vs48","vs49","vs50","vs51","vs52","vs53","vs54","vs55",
149+
"vs56","vs57"
150+
);
151+
}

0 commit comments

Comments
 (0)