]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - dense-linear-algebra-libraries/linalg.git/blob - blis/frame/2/hemv/bli_hemv_unf_var1a.c
TI Linear Algebra Library (LINALG) Rlease 1.0.0
[dense-linear-algebra-libraries/linalg.git] / blis / frame / 2 / hemv / bli_hemv_unf_var1a.c
1 /*
3    BLIS    
4    An object-based framework for developing high-performance BLAS-like
5    libraries.
7    Copyright (C) 2014, The University of Texas at Austin
9    Redistribution and use in source and binary forms, with or without
10    modification, are permitted provided that the following conditions are
11    met:
12     - Redistributions of source code must retain the above copyright
13       notice, this list of conditions and the following disclaimer.
14     - Redistributions in binary form must reproduce the above copyright
15       notice, this list of conditions and the following disclaimer in the
16       documentation and/or other materials provided with the distribution.
17     - Neither the name of The University of Texas at Austin nor the names
18       of its contributors may be used to endorse or promote products
19       derived from this software without specific prior written permission.
21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25    HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
35 #include "blis.h"
37 #define FUNCPTR_T hemv_fp
39 typedef void (*FUNCPTR_T)(
40                            uplo_t  uplo,
41                            conj_t  conja,
42                            conj_t  conjx,
43                            conj_t  conjh,
44                            dim_t   m,
45                            void*   alpha,
46                            void*   a, inc_t rs_a, inc_t cs_a,
47                            void*   x, inc_t incx,
48                            void*   beta,
49                            void*   y, inc_t incy
50                          );
52 // If some mixed datatype functions will not be compiled, we initialize
53 // the corresponding elements of the function array to NULL.
54 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
55 static FUNCPTR_T GENARRAY3_ALL(ftypes,hemv_unf_var1a);
56 #else
57 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
58 static FUNCPTR_T GENARRAY3_EXT(ftypes,hemv_unf_var1a);
59 #else
60 static FUNCPTR_T GENARRAY3_MIN(ftypes,hemv_unf_var1a);
61 #endif
62 #endif
65 void bli_hemv_unf_var1a( conj_t  conjh,
66                          obj_t*  alpha,
67                          obj_t*  a,
68                          obj_t*  x,
69                          obj_t*  beta,
70                          obj_t*  y,
71                          hemv_t* cntl )
72 {
73         num_t     dt_a      = bli_obj_datatype( *a );
74         num_t     dt_x      = bli_obj_datatype( *x );
75         num_t     dt_y      = bli_obj_datatype( *y );
77         uplo_t    uplo      = bli_obj_uplo( *a );
78         conj_t    conja     = bli_obj_conj_status( *a );
79         conj_t    conjx     = bli_obj_conj_status( *x );
81         dim_t     m         = bli_obj_length( *a );
83         void*     buf_a     = bli_obj_buffer_at_off( *a );
84         inc_t     rs_a      = bli_obj_row_stride( *a );
85         inc_t     cs_a      = bli_obj_col_stride( *a );
87         void*     buf_x     = bli_obj_buffer_at_off( *x );
88         inc_t     incx      = bli_obj_vector_inc( *x );
90         void*     buf_y     = bli_obj_buffer_at_off( *y );
91         inc_t     incy      = bli_obj_vector_inc( *y );
93         num_t     dt_alpha;
94         void*     buf_alpha;
96         num_t     dt_beta;
97         void*     buf_beta;
99         FUNCPTR_T f;
101         // The datatype of alpha MUST be the type union of a and x. This is to
102         // prevent any unnecessary loss of information during computation.
103         dt_alpha  = bli_datatype_union( dt_a, dt_x );
104         buf_alpha = bli_obj_buffer_for_1x1( dt_alpha, *alpha );
106         // The datatype of beta MUST be the same as the datatype of y.
107         dt_beta   = dt_y;
108         buf_beta  = bli_obj_buffer_for_1x1( dt_beta, *beta );
110         // Index into the type combination array to extract the correct
111         // function pointer.
112         f = ftypes[dt_a][dt_x][dt_y];
114         // Invoke the function.
115         f( uplo,
116            conja,
117            conjx,
118            conjh,
119            m,
120            buf_alpha,
121            buf_a, rs_a, cs_a,
122            buf_x, incx,
123            buf_beta,
124            buf_y, incy );
128 #undef  GENTFUNC3U12
129 #define GENTFUNC3U12( ctype_a, ctype_x, ctype_y, ctype_ax, cha, chx, chy, chax, varname, kername ) \
131 void PASTEMAC3(cha,chx,chy,varname)( \
132                                      uplo_t  uplo, \
133                                      conj_t  conja, \
134                                      conj_t  conjx, \
135                                      conj_t  conjh, \
136                                      dim_t   m, \
137                                      void*   alpha, \
138                                      void*   a, inc_t rs_a, inc_t cs_a, \
139                                      void*   x, inc_t incx, \
140                                      void*   beta, \
141                                      void*   y, inc_t incy  \
142                                    ) \
143 { \
144         ctype_ax* alpha_cast = alpha; \
145         ctype_y*  beta_cast  = beta; \
146         ctype_a*  a_cast     = a; \
147         ctype_x*  x_cast     = x; \
148         ctype_y*  y_cast     = y; \
149         ctype_y*  zero       = PASTEMAC(chy,0); \
150         ctype_a*  a10t; \
151         ctype_a*  alpha11; \
152         ctype_x*  x0; \
153         ctype_x*  chi1; \
154         ctype_y*  y0; \
155         ctype_y*  psi1; \
156         ctype_ax  rho; \
157         ctype_x   conjx_chi1; \
158         ctype_ax  alpha_chi1; \
159         ctype_a   alpha11_temp; \
160         dim_t     i; \
161         dim_t     n_behind; \
162         inc_t     rs_at, cs_at; \
163         conj_t    conj0, conj1; \
165         if ( bli_zero_dim1( m ) ) return; \
167         /* The algorithm will be expressed in terms of the lower triangular case;
168            the upper triangular case is supported by swapping the row and column
169            strides of A and toggling some conj parameters. */ \
170         if      ( bli_is_lower( uplo ) ) \
171         { \
172                 rs_at = rs_a; \
173                 cs_at = cs_a; \
175                 conj0 = conja; \
176                 conj1 = bli_apply_conj( conjh, conja ); \
177         } \
178         else /* if ( bli_is_upper( uplo ) ) */ \
179         { \
180                 rs_at = cs_a; \
181                 cs_at = rs_a; \
183                 conj0 = bli_apply_conj( conjh, conja ); \
184                 conj1 = conja; \
185         } \
187         /* If beta is zero, use setv. Otherwise, scale by beta. */ \
188         if ( PASTEMAC(chy,eq0)( *beta_cast ) ) \
189         { \
190                 /* y = 0; */ \
191                 PASTEMAC2(chy,chy,setv)( m, \
192                                          zero, \
193                                          y_cast, incy ); \
194         } \
195         else \
196         { \
197                 /* y = beta * y; */ \
198                 PASTEMAC2(chy,chy,scalv)( BLIS_NO_CONJUGATE, \
199                                           m, \
200                                           beta_cast, \
201                                           y_cast, incy ); \
202         } \
204         for ( i = 0; i < m; ++i ) \
205         { \
206                 n_behind = i; \
207                 a10t     = a_cast + (i  )*rs_at + (0  )*cs_at; \
208                 alpha11  = a_cast + (i  )*rs_at + (i  )*cs_at; \
209                 x0       = x_cast + (0  )*incx; \
210                 chi1     = x_cast + (i  )*incx; \
211                 y0       = y_cast + (0  )*incy; \
212                 psi1     = y_cast + (i  )*incy; \
214                 /* Apply conjx to chi1 and and scale by alpha. */ \
215                 PASTEMAC2(chx,chx,copycjs)( conjx, *chi1, conjx_chi1 ); \
216                 PASTEMAC3(chax,chx,chax,scal2s)( *alpha_cast, conjx_chi1, alpha_chi1 ); \
218                 /* psi1 = psi1 + alpha * a10t * x0;     (dotv) */ \
219                 /* y0   = y0   + alpha * a10t' * chi1;  (axpyv) */ \
220                 PASTEMAC3(cha,chx,chy,kername)( conj0, \
221                                                 conj1, \
222                                                 conjx, \
223                                                 n_behind, \
224                                                 &alpha_chi1, \
225                                                 a10t, cs_at, \
226                                                 x0,   incx, \
227                                                 &rho, \
228                                                 y0,   incy ); \
229                 PASTEMAC3(chax,chax,chy,axpys)( *alpha_cast, rho, *psi1 ); \
231                 /* For hemv, explicitly set the imaginary component of alpha11 to
232                    zero. */ \
233                 PASTEMAC2(cha,cha,copycjs)( conja, *alpha11, alpha11_temp ); \
234                 if ( bli_is_conj( conjh ) ) \
235                         PASTEMAC(cha,seti0s)( alpha11_temp ); \
237                 /* psi1 = psi1 + alpha * alpha11 * chi1; */ \
238                 PASTEMAC3(chax,cha,chy,axpys)( alpha_chi1, alpha11_temp, *psi1 ); \
240         } \
243 // Define the basic set of functions unconditionally, and then also some
244 // mixed datatype functions if requested.
245 INSERT_GENTFUNC3U12_BASIC( hemv_unf_var1a, DOTAXPYV_KERNEL )
247 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
248 INSERT_GENTFUNC3U12_MIX_D( hemv_unf_var1a, DOTAXPYV_KERNEL )
249 #endif
251 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
252 INSERT_GENTFUNC3U12_MIX_P( hemv_unf_var1a, DOTAXPYV_KERNEL )
253 #endif