Skip to content

Commit 9349dcd

Browse files
authored
Merge pull request #2956 from RajalakshmiSR/caxpy_p10
Optimize caxpy for POWER10
2 parents 9a058f2 + b435491 commit 9349dcd

File tree

3 files changed

+315
-5
lines changed

3 files changed

+315
-5
lines changed

kernel/power/KERNEL.POWER10

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,7 @@ ZASUMKERNEL = zasum.c
143143
#
144144
SAXPYKERNEL = saxpy_power10.c
145145
DAXPYKERNEL = daxpy_power10.c
146-
ifneq ($(GCCVERSIONGTEQ9),1)
147-
CAXPYKERNEL = caxpy_power9.S
148-
else
149-
CAXPYKERNEL = caxpy.c
150-
endif
146+
CAXPYKERNEL = caxpy_power10.c
151147
ZAXPYKERNEL = zaxpy_power10.c
152148
#
153149
SCOPYKERNEL = scopy_power10.c

kernel/power/caxpy_microk_power10.c

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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+
static void caxpy_kernel_8 (long n, float *x, float *y,
30+
float alpha_r, float alpha_i)
31+
{
32+
#if !defined(CONJ)
33+
static const float mvec[4] = { -1.0, 1.0, -1.0, 1.0 };
34+
#else
35+
static const float mvec[4] = { 1.0, -1.0, 1.0, -1.0 };
36+
#endif
37+
const float *mvecp = mvec;
38+
/* We have to load reverse mask for big endian. */
39+
/* __vector unsigned char mask={ 4,5,6,7,0,1,2,3,12,13,14,15,8,9,10,11}; */
40+
41+
__vector unsigned char mask = { 11,10,9,8,15,14,13,12,3,2,1,0,7,6,5,4};
42+
long ytmp;
43+
44+
__asm__
45+
(
46+
"xscvdpspn 32, %7 \n\t"
47+
"xscvdpspn 33, %8 \n\t"
48+
"xxspltw 32, 32, 0 \n\t"
49+
"xxspltw 33, 33, 0 \n\t"
50+
"lxvd2x 36, 0, %9 \n\t" // mvec
51+
52+
#if !defined(CONJ)
53+
"xvmulsp 33, 33, 36 \n\t" // alpha_i * mvec
54+
#else
55+
"xvmulsp 32, 32, 36 \n\t" // alpha_r * mvec
56+
#endif
57+
"mr %4, %3 \n\t"
58+
"dcbt 0, %2 \n\t"
59+
"dcbt 0, %3 \n\t"
60+
61+
"lxvp 40, 0(%2) \n\t" // x0
62+
"lxvp 42, 32(%2) \n\t" // x2
63+
"lxvp 48, 0(%3) \n\t" // y0
64+
"lxvp 50, 32(%3) \n\t" // y2
65+
66+
"xxperm 52, 40, %x10 \n\t" // exchange real and imag part
67+
"xxperm 53, 41, %x10 \n\t" // exchange real and imag part
68+
"xxperm 54, 42, %x10 \n\t" // exchange real and imag part
69+
"xxperm 55, 43, %x10 \n\t" // exchange real and imag part
70+
71+
"lxvp 44, 64(%2) \n\t" // x4
72+
"lxvp 46, 96(%2) \n\t" // x6
73+
"lxvp 34, 64(%3) \n\t" // y4
74+
"lxvp 38, 96(%3) \n\t" // y6
75+
76+
"xxperm 56, 44, %x10 \n\t" // exchange real and imag part
77+
"xxperm 57, 45, %x10 \n\t" // exchange real and imag part
78+
"xxperm 58, 46, %x10 \n\t" // exchange real and imag part
79+
"xxperm 59, 47, %x10 \n\t" // exchange real and imag part
80+
81+
"addi %2, %2, 128 \n\t"
82+
"addi %3, %3, 128 \n\t"
83+
84+
"addic. %1, %1, -16 \n\t"
85+
"ble two%= \n\t"
86+
87+
".align 5 \n"
88+
"one%=: \n\t"
89+
90+
"xvmaddasp 48, 40, 32 \n\t" // alpha_r * x0_r , alpha_r * x0_i
91+
"xvmaddasp 49, 41, 32 \n\t"
92+
"lxvp 40, 0(%2) \n\t" // x0
93+
"xvmaddasp 50, 42, 32 \n\t"
94+
"xvmaddasp 51, 43, 32 \n\t"
95+
"lxvp 42, 32(%2) \n\t" // x2
96+
97+
"xvmaddasp 34, 44, 32 \n\t"
98+
"xvmaddasp 35, 45, 32 \n\t"
99+
"lxvp 44, 64(%2) \n\t" // x4
100+
"xvmaddasp 38, 46, 32 \n\t"
101+
"xvmaddasp 39, 47, 32 \n\t"
102+
"lxvp 46, 96(%2) \n\t" // x6
103+
104+
"xvmaddasp 48, 52, 33 \n\t" // alpha_i * x0_i , alpha_i * x0_r
105+
"addi %2, %2, 128 \n\t"
106+
"xvmaddasp 49, 53, 33 \n\t"
107+
"xvmaddasp 50, 54, 33 \n\t"
108+
"xvmaddasp 51, 55, 33 \n\t"
109+
110+
"xvmaddasp 34, 56, 33 \n\t"
111+
"xvmaddasp 35, 57, 33 \n\t"
112+
"xvmaddasp 38, 58, 33 \n\t"
113+
"xvmaddasp 39, 59, 33 \n\t"
114+
115+
"stxvp 48, 0(%4) \n\t"
116+
"stxvp 50, 32(%4) \n\t"
117+
"stxvp 34, 64(%4) \n\t"
118+
"stxvp 38, 96(%4) \n\t"
119+
120+
"addi %4, %4, 128 \n\t"
121+
"xxperm 52, 40, %x10 \n\t" // exchange real and imag part
122+
"xxperm 53, 41, %x10 \n\t" // exchange real and imag part
123+
124+
"lxvp 48, 0(%3) \n\t" // y0
125+
"xxperm 54, 42, %x10 \n\t" // exchange real and imag part
126+
"xxperm 55, 43, %x10 \n\t" // exchange real and imag part
127+
"lxvp 50, 32(%3) \n\t" // y2
128+
129+
"xxperm 56, 44, %x10 \n\t" // exchange real and imag part
130+
"xxperm 57, 45, %x10 \n\t" // exchange real and imag part
131+
"lxvp 34, 64(%3) \n\t" // y4
132+
"xxperm 58, 46, %x10 \n\t" // exchange real and imag part
133+
"xxperm 59, 47, %x10 \n\t" // exchange real and imag part
134+
"lxvp 38, 96(%3) \n\t" // y6
135+
136+
"addi %3, %3, 128 \n\t"
137+
138+
"addic. %1, %1, -16 \n\t"
139+
"bgt one%= \n"
140+
141+
"two%=: \n\t"
142+
"xvmaddasp 48, 40, 32 \n\t" // alpha_r * x0_r , alpha_r * x0_i
143+
"xvmaddasp 49, 41, 32 \n\t"
144+
"xvmaddasp 50, 42, 32 \n\t"
145+
"xvmaddasp 51, 43, 32 \n\t"
146+
147+
"xvmaddasp 34, 44, 32 \n\t"
148+
"xvmaddasp 35, 45, 32 \n\t"
149+
"xvmaddasp 38, 46, 32 \n\t"
150+
"xvmaddasp 39, 47, 32 \n\t"
151+
152+
"xvmaddasp 48, 52, 33 \n\t" // alpha_i * x0_i , alpha_i * x0_r
153+
"xvmaddasp 49, 53, 33 \n\t"
154+
"xvmaddasp 50, 54, 33 \n\t"
155+
"xvmaddasp 51, 55, 33 \n\t"
156+
157+
"xvmaddasp 34, 56, 33 \n\t"
158+
"xvmaddasp 35, 57, 33 \n\t"
159+
"xvmaddasp 38, 58, 33 \n\t"
160+
"xvmaddasp 39, 59, 33 \n\t"
161+
162+
"stxvp 48, 0(%4) \n\t"
163+
"stxvp 50, 32(%4) \n\t"
164+
"stxvp 34, 64(%4) \n\t"
165+
"stxvp 38, 96(%4) \n\t"
166+
167+
"#n=%1 x=%5=%2 y=%0=%3 alpha=(%7,%8) mvecp=%6=%9 ytmp=%4\n"
168+
:
169+
"+m" (*y),
170+
"+r" (n), // 1
171+
"+b" (x), // 2
172+
"+b" (y), // 3
173+
"=b" (ytmp) // 4
174+
:
175+
"m" (*x),
176+
"m" (*mvecp),
177+
"d" (alpha_r), // 7
178+
"d" (alpha_i), // 8
179+
"4" (mvecp), // 9
180+
"wa" (mask)
181+
:
182+
"cr0",
183+
"vs32","vs33","vs34","vs35","vs36","vs37","vs38","vs39",
184+
"vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47",
185+
"vs48","vs49","vs50","vs51","vs52","vs53","vs54","vs55",
186+
"vs56","vs57","vs58","vs59"
187+
);
188+
}

kernel/power/caxpy_power10.c

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
#include "common.h"
29+
30+
31+
#if defined(__VEC__) || defined(__ALTIVEC__)
32+
#include "caxpy_microk_power10.c"
33+
#endif
34+
35+
36+
#ifndef HAVE_KERNEL_8
37+
38+
static void caxpy_kernel_8(BLASLONG n, FLOAT *x, FLOAT *y, FLOAT da_r,FLOAT da_i)
39+
{
40+
BLASLONG register i = 0;
41+
BLASLONG register ix = 0;
42+
43+
44+
45+
while(i < n)
46+
{
47+
#if !defined(CONJ)
48+
y[ix] += ( da_r * x[ix] - da_i * x[ix+1] ) ;
49+
y[ix+1] += ( da_r * x[ix+1] + da_i * x[ix] ) ;
50+
y[ix+2] += ( da_r * x[ix+2] - da_i * x[ix+3] ) ;
51+
y[ix+3] += ( da_r * x[ix+3] + da_i * x[ix+2] ) ;
52+
#else
53+
y[ix] += ( da_r * x[ix] + da_i * x[ix+1] ) ;
54+
y[ix+1] -= ( da_r * x[ix+1] - da_i * x[ix] ) ;
55+
y[ix+2] += ( da_r * x[ix+2] + da_i * x[ix+3] ) ;
56+
y[ix+3] -= ( da_r * x[ix+3] - da_i * x[ix+2] ) ;
57+
#endif
58+
59+
ix+=4 ;
60+
i+=2 ;
61+
62+
}
63+
64+
}
65+
66+
#endif
67+
68+
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)
69+
{
70+
BLASLONG i=0;
71+
BLASLONG ix=0,iy=0;
72+
73+
if ( n <= 0 ) return(0);
74+
75+
if ( (inc_x == 1) && (inc_y == 1) )
76+
{
77+
78+
BLASLONG n1 = n & -16;
79+
80+
if ( n1 )
81+
{
82+
caxpy_kernel_8 (n1, x, y, da_r, da_i);
83+
ix = 2 * n1;
84+
}
85+
i = n1;
86+
while(i < n)
87+
{
88+
#if !defined(CONJ)
89+
y[ix] += ( da_r * x[ix] - da_i * x[ix+1] ) ;
90+
y[ix+1] += ( da_r * x[ix+1] + da_i * x[ix] ) ;
91+
#else
92+
y[ix] += ( da_r * x[ix] + da_i * x[ix+1] ) ;
93+
y[ix+1] -= ( da_r * x[ix+1] - da_i * x[ix] ) ;
94+
#endif
95+
i++ ;
96+
ix += 2;
97+
98+
}
99+
return(0);
100+
101+
102+
}
103+
104+
inc_x *=2;
105+
inc_y *=2;
106+
107+
while(i < n)
108+
{
109+
110+
#if !defined(CONJ)
111+
y[iy] += ( da_r * x[ix] - da_i * x[ix+1] ) ;
112+
y[iy+1] += ( da_r * x[ix+1] + da_i * x[ix] ) ;
113+
#else
114+
y[iy] += ( da_r * x[ix] + da_i * x[ix+1] ) ;
115+
y[iy+1] -= ( da_r * x[ix+1] - da_i * x[ix] ) ;
116+
#endif
117+
ix += inc_x ;
118+
iy += inc_y ;
119+
i++ ;
120+
121+
}
122+
return(0);
123+
124+
}
125+
126+

0 commit comments

Comments
 (0)