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