Skip to content

Commit 16dddb7

Browse files
authored
Merge pull request #3070 from RajalakshmiSR/cdot
Optimize cdot function for POWER10
2 parents e378b24 + eff7c91 commit 16dddb7

File tree

3 files changed

+185
-4
lines changed

3 files changed

+185
-4
lines changed

kernel/power/KERNEL.POWER10

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,7 @@ ZCOPYKERNEL = zcopy_power10.c
154154
SDOTKERNEL = sdot_power10.c
155155
DDOTKERNEL = ddot_power10.c
156156
DSDOTKERNEL = sdot_power10.c
157-
ifneq ($(GCCVERSIONGTEQ9),1)
158-
CDOTKERNEL = cdot_power9.S
159-
else
160157
CDOTKERNEL = cdot.c
161-
endif
162158
ZDOTKERNEL = zdot.c
163159
#
164160
SNRM2KERNEL = ../arm/nrm2.c

kernel/power/cdot.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
#else
2929

3030
#include "common.h"
31+
#if defined(POWER10)
32+
#include "cdot_microk_power10.c"
33+
#else
3134
#ifndef HAVE_KERNEL_8
3235
#include <altivec.h>
3336

@@ -99,6 +102,7 @@ static void cdot_kernel_8(BLASLONG n, FLOAT *x, FLOAT *y, float *dot)
99102

100103
}
101104
#endif
105+
#endif
102106

103107

104108
OPENBLAS_COMPLEX_FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y) {
@@ -116,7 +120,11 @@ OPENBLAS_COMPLEX_FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLA
116120

117121
if ((inc_x == 1) && (inc_y == 1)) {
118122

123+
#if defined(POWER10)
124+
BLASLONG n1 = n & -16;
125+
#else
119126
BLASLONG n1 = n & -8;
127+
#endif
120128
BLASLONG j=0;
121129

122130
if (n1){

kernel/power/cdot_microk_power10.c

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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_8 1
29+
30+
static void cdot_kernel_8 (long n, float *x, float *y, float *dot)
31+
{
32+
__vector unsigned char mask = { 11,10,9,8,15,14,13,12,3,2,1,0,7,6,5,4};
33+
__asm__
34+
(
35+
"dcbt 0, %2 \n\t"
36+
"dcbt 0, %3 \n\t"
37+
38+
"xxlxor 32, 32, 32 \n\t"
39+
"xxlxor 33, 33, 33 \n\t"
40+
"xxlxor 34, 34, 34 \n\t"
41+
"xxlxor 35, 35, 35 \n\t"
42+
"xxlxor 36, 36, 36 \n\t"
43+
"xxlxor 37, 37, 37 \n\t"
44+
"xxlxor 38, 38, 38 \n\t"
45+
"xxlxor 39, 39, 39 \n\t"
46+
47+
"lxvp 40, 0(%2) \n\t"
48+
"lxvp 42, 32(%2) \n\t"
49+
"lxvp 44, 64(%2) \n\t"
50+
"lxvp 46, 96(%2) \n\t"
51+
"lxvp 48, 0(%3) \n\t"
52+
"lxvp 50, 32(%3) \n\t"
53+
"lxvp 52, 64(%3) \n\t"
54+
"lxvp 54, 96(%3) \n\t"
55+
56+
"xxperm 56, 48, %x7 \n\t"
57+
"xxperm 57, 49, %x7 \n\t"
58+
"xxperm 58, 50, %x7 \n\t"
59+
"xxperm 59, 51, %x7 \n\t"
60+
61+
"xxperm 60, 52, %x7 \n\t"
62+
"xxperm 61, 53, %x7 \n\t"
63+
"xxperm 62, 54, %x7 \n\t"
64+
"xxperm 63, 55, %x7 \n\t"
65+
66+
"addi %2, %2, 128 \n\t"
67+
"addi %3, %3, 128 \n\t"
68+
69+
"addic. %1, %1, -16 \n\t"
70+
"ble two%= \n\t"
71+
72+
".align 5 \n"
73+
"one%=: \n\t"
74+
75+
"xvmaddasp 32, 40, 48 \n\t" // x0_r * y0_r , x0_i * y0_i
76+
"xvmaddasp 34, 41, 49 \n\t" // x1_r * y1_r , x1_i * y1_i
77+
"lxvp 48, 0(%3) \n\t"
78+
79+
"xvmaddasp 36, 42, 50 \n\t" // x2_r * y2_r , x2_i * y2_i
80+
"xvmaddasp 38, 43, 51 \n\t" // x3_r * y3_r , x3_i * y3_i
81+
"lxvp 50, 32(%3) \n\t"
82+
83+
"xvmaddasp 33, 40, 56 \n\t" // x0_r * y0_i , x0_i * y0_r
84+
"xvmaddasp 35, 41, 57 \n\t" // x1_r * y1_i , x1_i * y1_r
85+
"lxvp 40, 0(%2) \n\t"
86+
87+
"xvmaddasp 37, 42, 58 \n\t" // x2_r * y2_i , x2_i * y2_r
88+
"xvmaddasp 39, 43, 59 \n\t" // x3_r * y3_i , x3_i * y3_r
89+
"lxvp 42, 32(%2) \n\t"
90+
91+
"xxperm 56, 48, %x7 \n\t"
92+
"xxperm 57, 49, %x7 \n\t"
93+
"xxperm 58, 50, %x7 \n\t"
94+
"xxperm 59, 51, %x7 \n\t"
95+
96+
"xvmaddasp 32, 44, 52 \n\t" // x0_r * y0_r , x0_i * y0_i
97+
"xvmaddasp 34, 45, 53 \n\t" // x1_r * y1_r , x1_i * y1_i
98+
"lxvp 52, 64(%3) \n\t"
99+
100+
"xvmaddasp 36, 46, 54 \n\t" // x2_r * y2_r , x2_i * y2_i
101+
"xvmaddasp 38, 47, 55 \n\t" // x3_r * y3_r , x3_i * y3_i
102+
"lxvp 54, 96(%3) \n\t"
103+
104+
"xvmaddasp 33, 44, 60 \n\t" // x0_r * y0_i , x0_i * y0_r
105+
"xvmaddasp 35, 45, 61 \n\t" // x1_r * y1_i , x1_i * y1_r
106+
"lxvp 44, 64(%2) \n\t"
107+
"xvmaddasp 37, 46, 62 \n\t" // x2_r * y2_i , x2_i * y2_r
108+
"xvmaddasp 39, 47, 63 \n\t" // x3_r * y3_i , x3_i * y3_r
109+
"lxvp 46, 96(%2) \n\t"
110+
111+
"xxperm 60, 52, %x7 \n\t"
112+
"xxperm 61, 53, %x7 \n\t"
113+
"xxperm 62, 54, %x7 \n\t"
114+
"xxperm 63, 55, %x7 \n\t"
115+
116+
"addi %2, %2, 128 \n\t"
117+
"addi %3, %3, 128 \n\t"
118+
119+
"addic. %1, %1, -16 \n\t"
120+
"bgt one%= \n"
121+
122+
"two%=: \n\t"
123+
124+
"xvmaddasp 32, 40, 48 \n\t" // x0_r * y0_r , x0_i * y0_i
125+
"xvmaddasp 34, 41, 49 \n\t" // x1_r * y1_r , x1_i * y1_i
126+
"xvmaddasp 36, 42, 50 \n\t" // x2_r * y2_r , x2_i * y2_i
127+
"xvmaddasp 38, 43, 51 \n\t" // x3_r * y3_r , x3_i * y3_i
128+
129+
"xvmaddasp 33, 40, 56 \n\t" // x0_r * y0_i , x0_i * y0_r
130+
"xvmaddasp 35, 41, 57 \n\t" // x1_r * y1_i , x1_i * y1_r
131+
"xvmaddasp 37, 42, 58 \n\t" // x2_r * y2_i , x2_i * y2_r
132+
"xvmaddasp 39, 43, 59 \n\t" // x3_r * y3_i , x3_i * y3_r
133+
134+
"xvmaddasp 32, 44, 52 \n\t" // x0_r * y0_r , x0_i * y0_i
135+
"xvmaddasp 34, 45, 53 \n\t" // x1_r * y1_r , x1_i * y1_i
136+
"xvmaddasp 36, 46, 54 \n\t" // x2_r * y2_r , x2_i * y2_i
137+
"xvmaddasp 38, 47, 55 \n\t" // x3_r * y3_r , x3_i * y3_i
138+
139+
"xvmaddasp 33, 44, 60 \n\t" // x0_r * y0_i , x0_i * y0_r
140+
"xvmaddasp 35, 45, 61 \n\t" // x1_r * y1_i , x1_i * y1_r
141+
"xvmaddasp 37, 46, 62 \n\t" // x2_r * y2_i , x2_i * y2_r
142+
"xvmaddasp 39, 47, 63 \n\t" // x3_r * y3_i , x3_i * y3_r
143+
144+
"xvaddsp 32, 32, 34 \n\t"
145+
"xvaddsp 36, 36, 38 \n\t"
146+
147+
"xvaddsp 33, 33, 35 \n\t"
148+
"xvaddsp 37, 37, 39 \n\t"
149+
150+
"xvaddsp 35, 32, 36 \n\t"
151+
"xvaddsp 34, 33, 37 \n\t"
152+
"xxswapd 32, 35 \n\t"
153+
"xxswapd 33, 34 \n\t"
154+
"xvaddsp 35, 35, 32 \n\t"
155+
"xvaddsp 34, 34, 33 \n\t"
156+
"xxpermdi 34, 34, 35, 2 \n\t"
157+
"stxv 34, 0(%6) \n\t"
158+
159+
"#n=%1 x=%4=%2 y=%5=%3 dot=%0=%6"
160+
:
161+
"=m" (*dot),
162+
"+r" (n), // 1
163+
"+b" (x), // 2
164+
"+b" (y) // 3
165+
:
166+
"m" (*x),
167+
"m" (*y),
168+
"b" (dot), // 6
169+
"wa" (mask)
170+
:
171+
"cr0",
172+
"vs32","vs33","vs34","vs35","vs36","vs37","vs38","vs39",
173+
"vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47",
174+
"vs48","vs49","vs50","vs51","vs52","vs53","vs54","vs55",
175+
"vs56","vs57","vs58","vs59","vs60","vs61","vs62","vs63"
176+
);
177+
}

0 commit comments

Comments
 (0)