e4a2bd95b78e4f6cab9675eb776236e55fcd9c89
[platform/upstream/openblas.git] / kernel / zarch / ddot.c
1 /***************************************************************************
2 Copyright (c) 2013-2017, 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
29 #include "common.h"
30
31
32 #if  defined(Z13)
33 static void __attribute__ ((noinline))   ddot_kernel_8(BLASLONG n, FLOAT *x, FLOAT *y, FLOAT *d)
34 {
35    
36                  __asm__ volatile( 
37                     "pfd 1, 0(%1) \n\t"
38                     "pfd 1, 0(%2) \n\t"      
39                     "vzero %%v24  \n\t"
40                     "vzero %%v25  \n\t" 
41                     "vzero %%v26  \n\t"
42                     "vzero %%v27  \n\t"                  
43                     "srlg  %%r0,%0,4    \n\t" 
44                     "xgr   %%r1,%%r1    \n\t"
45                     ".align 16 \n\t"    
46                     "1: \n\t"
47                     "pfd 1, 256(%%r1,%1) \n\t"
48                     "pfd 1, 256(%%r1,%2) \n\t"                
49                     "vl  %%v16, 0(%%r1,%1)  \n\t"
50                     "vl  %%v17, 16(%%r1,%1) \n\t"
51                     "vl  %%v18, 32(%%r1,%1) \n\t"
52                     "vl  %%v19, 48(%%r1,%1) \n\t"
53
54                     "vl  %%v28, 0(%%r1,%2) \n\t"
55                     "vfmadb    %%v24,%%v16,%%v28,%%v24  \n\t"  
56                     "vl  %%v29, 16(%%r1,%2) \n\t"
57                     "vfmadb    %%v25,%%v17,%%v29,%%v25  \n\t"   
58              
59                     "vl  %%v30, 32(%%r1,%2) \n\t"
60                     "vfmadb    %%v26,%%v18,%%v30,%%v26  \n\t"      
61                     "vl  %%v31, 48(%%r1,%2) \n\t" 
62                     "vfmadb    %%v27,%%v19,%%v31,%%v27  \n\t"   
63          
64                     "vl  %%v16, 64(%%r1,%1)  \n\t"
65                     "vl  %%v17, 80(%%r1,%1)  \n\t"
66                     "vl  %%v18, 96(%%r1,%1)  \n\t"
67                     "vl  %%v19, 112(%%r1,%1) \n\t"
68
69                     "vl  %%v28, 64(%%r1,%2) \n\t"
70                     "vfmadb    %%v24,%%v16,%%v28,%%v24  \n\t"  
71                     "vl  %%v29, 80(%%r1,%2) \n\t"
72                     "vfmadb    %%v25,%%v17,%%v29,%%v25  \n\t"  
73                   
74              
75                     "vl  %%v30, 96(%%r1,%2)  \n\t"
76                     "vfmadb    %%v26,%%v18,%%v30,%%v26  \n\t" 
77                     "vl  %%v31, 112(%%r1,%2) \n\t" 
78                     "vfmadb    %%v27,%%v19,%%v31,%%v27  \n\t"  
79                      
80                     
81                     "la %%r1,128(%%r1) \n\t"
82                     "brctg %%r0,1b \n\t"
83                     "vfadb   %%v24,%%v25,%%v24    \n\t"
84                     "vfadb   %%v24,%%v26,%%v24    \n\t"
85                     "vfadb   %%v24,%%v27,%%v24    \n\t"                 
86                     "vrepg   %%v1,%%v24,1         \n\t"
87                     "vfadb   %%v1,%%v24,%%v1      \n\t"  
88                     " std    %%f1,0(%3)           \n\t"  
89                     :
90                     :"r"(n),"a"(x),"a"(y),"a"(d)
91                     :"cc" , "memory" ,"r0","r1","v16", "v17","v18","v19","v20","v21","v22","v23",
92                     "v24","v25","v26","v27","v28","v29","v30","v31"
93
94                  );
95
96 }
97
98
99 #else
100
101 static void ddot_kernel_8(BLASLONG n, FLOAT *x, FLOAT *y, FLOAT *d)
102 {
103     BLASLONG register i = 0;
104     FLOAT dot = 0.0;
105
106     while(i < n)
107         {
108               dot += y[i]  * x[i]
109                   + y[i+1] * x[i+1]
110                   + y[i+2] * x[i+2]
111                   + y[i+3] * x[i+3]
112                   + y[i+4] * x[i+4]
113                   + y[i+5] * x[i+5]
114                   + y[i+6] * x[i+6]
115                   + y[i+7] * x[i+7] ;
116
117               i+=8 ;
118
119        }
120        *d += dot;
121
122 }
123
124 #endif
125
126 FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
127 {
128     BLASLONG i=0;
129     BLASLONG ix=0,iy=0;
130
131     FLOAT  dot = 0.0 ;
132
133     if ( n <= 0 )  return(dot);
134
135     if ( (inc_x == 1) && (inc_y == 1) )
136     {
137
138         BLASLONG n1 = n & -16;
139
140         if ( n1 )
141             ddot_kernel_8(n1, x, y , &dot );
142
143         i = n1;
144         while(i < n)
145         {
146
147             dot += y[i] * x[i] ;
148             i++ ;
149
150         } 
151         return(dot);
152
153
154     }
155
156     FLOAT temp1 = 0.0;
157     FLOAT temp2 = 0.0;
158
159     BLASLONG n1 = n & -4;    
160
161     while(i < n1)
162     {
163
164         FLOAT m1 = y[iy]       * x[ix] ;
165         FLOAT m2 = y[iy+inc_y] * x[ix+inc_x] ;
166
167         FLOAT m3 = y[iy+2*inc_y] * x[ix+2*inc_x] ;
168         FLOAT m4 = y[iy+3*inc_y] * x[ix+3*inc_x] ;
169
170         ix  += inc_x*4 ;
171         iy  += inc_y*4 ;
172
173         temp1 += m1+m3;
174         temp2 += m2+m4;
175
176         i+=4 ;
177
178     }
179
180     while(i < n)
181     {
182
183         temp1 += y[iy] * x[ix] ;
184         ix  += inc_x ;
185         iy  += inc_y ;
186         i++ ;
187
188     }
189     dot = temp1 + temp2;
190     return(dot);
191
192 }
193
194