]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - dense-linear-algebra-libraries/linalg.git/blob - blis/frame/2/trsv/bli_trsv_unb_var1.c
TI Linear Algebra Library (LINALG) Rlease 1.0.0
[dense-linear-algebra-libraries/linalg.git] / blis / frame / 2 / trsv / bli_trsv_unb_var1.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 trsv_fp
39 typedef void (*FUNCPTR_T)(
40                            uplo_t  uplo,
41                            trans_t trans,
42                            diag_t  diag,
43                            dim_t   m,
44                            void*   alpha,
45                            void*   a, inc_t rs_a, inc_t cs_a,
46                            void*   x, inc_t incx
47                          );
49 // If some mixed datatype functions will not be compiled, we initialize
50 // the corresponding elements of the function array to NULL.
51 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
52 static FUNCPTR_T GENARRAY2_ALL(ftypes,trsv_unb_var1);
53 #else
54 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
55 static FUNCPTR_T GENARRAY2_EXT(ftypes,trsv_unb_var1);
56 #else
57 static FUNCPTR_T GENARRAY2_MIN(ftypes,trsv_unb_var1);
58 #endif
59 #endif
62 void bli_trsv_unb_var1( obj_t*  alpha,
63                         obj_t*  a,
64                         obj_t*  x,
65                         trsv_t* cntl )
66 {
67         num_t     dt_a      = bli_obj_datatype( *a );
68         num_t     dt_x      = bli_obj_datatype( *x );
70         uplo_t    uplo      = bli_obj_uplo( *a );
71         trans_t   trans     = bli_obj_conjtrans_status( *a );
72         diag_t    diag      = bli_obj_diag( *a );
74         dim_t     m         = bli_obj_length( *a );
76         void*     buf_a     = bli_obj_buffer_at_off( *a );
77         inc_t     rs_a      = bli_obj_row_stride( *a );
78         inc_t     cs_a      = bli_obj_col_stride( *a );
80         void*     buf_x     = bli_obj_buffer_at_off( *x );
81         inc_t     incx      = bli_obj_vector_inc( *x );
83         num_t     dt_alpha;
84         void*     buf_alpha;
86         FUNCPTR_T f;
88         // The datatype of alpha MUST be the type union of a and x. This is to
89         // prevent any unnecessary loss of information during computation.
90         dt_alpha  = bli_datatype_union( dt_a, dt_x );
91         buf_alpha = bli_obj_buffer_for_1x1( dt_alpha, *alpha );
93         // Index into the type combination array to extract the correct
94         // function pointer.
95         f = ftypes[dt_a][dt_x];
97         // Invoke the function.
98         f( uplo,
99            trans,
100            diag,
101            m,
102            buf_alpha,
103            buf_a, rs_a, cs_a,
104            buf_x, incx );
108 #undef  GENTFUNC2U
109 #define GENTFUNC2U( ctype_a, ctype_x, ctype_ax, cha, chx, chax, varname, kername ) \
111 void PASTEMAC2(cha,chx,varname)( \
112                                  uplo_t  uplo, \
113                                  trans_t trans, \
114                                  diag_t  diag, \
115                                  dim_t   m, \
116                                  void*   alpha, \
117                                  void*   a, inc_t rs_a, inc_t cs_a, \
118                                  void*   x, inc_t incx  \
119                                ) \
120 { \
121         ctype_ax* alpha_cast = alpha; \
122         ctype_a*  a_cast     = a; \
123         ctype_x*  x_cast     = x; \
124         ctype_a*  a10t; \
125         ctype_a*  alpha11; \
126         ctype_a*  a12t; \
127         ctype_x*  x0; \
128         ctype_x*  chi1; \
129         ctype_x*  x2; \
130         ctype_ax  alpha11_conj; \
131         ctype_ax  rho; \
132         dim_t     iter, i; \
133         dim_t     n_behind; \
134         inc_t     rs_at, cs_at; \
135         uplo_t    uplo_trans; \
136         conj_t    conja; \
138         if ( bli_zero_dim1( m ) ) return; \
140         if      ( bli_does_notrans( trans ) ) \
141         { \
142                 rs_at = rs_a; \
143                 cs_at = cs_a; \
144                 uplo_trans = uplo; \
145         } \
146         else /* if ( bli_does_trans( trans ) ) */ \
147         { \
148                 rs_at = cs_a; \
149                 cs_at = rs_a; \
150                 uplo_trans = bli_uplo_toggled( uplo ); \
151         } \
153         conja = bli_extract_conj( trans ); \
155         /* x = alpha * x; */ \
156         PASTEMAC2(chax,chx,scalv)( BLIS_NO_CONJUGATE, \
157                                    m, \
158                                    alpha_cast, \
159                                    x, incx ); \
161         /* We reduce all of the possible cases down to just lower/upper. */ \
162         if      ( bli_is_upper( uplo_trans ) ) \
163         { \
164                 for ( iter = 0; iter < m; ++iter ) \
165                 { \
166                         i        = m - iter - 1; \
167                         n_behind = iter; \
168                         alpha11  = a_cast + (i  )*rs_at + (i  )*cs_at; \
169                         a12t     = a_cast + (i  )*rs_at + (i+1)*cs_at; \
170                         chi1     = x_cast + (i  )*incx; \
171                         x2       = x_cast + (i+1)*incx; \
173                         /* chi1 = chi1 - a12t * x2; */ \
174                         PASTEMAC3(cha,chx,chax,kername)( conja, \
175                                                          BLIS_NO_CONJUGATE, \
176                                                          n_behind, \
177                                                          a12t, cs_at, \
178                                                          x2,   incx, \
179                                                          &rho ); \
180                         PASTEMAC2(chax,chx,subs)( rho, *chi1 ); \
182                         /* chi1 = chi1 / alpha11; */ \
183                         if ( bli_is_nonunit_diag( diag ) ) \
184                         { \
185                                 PASTEMAC2(cha,chax,copycjs)( conja, *alpha11, alpha11_conj ); \
186                                 PASTEMAC2(chax,chx,invscals)( alpha11_conj, *chi1 ); \
187                         } \
188                 } \
189         } \
190         else /* if ( bli_is_lower( uplo_trans ) ) */ \
191         { \
192                 for ( iter = 0; iter < m; ++iter ) \
193                 { \
194                         i        = iter; \
195                         n_behind = i; \
196                         alpha11  = a_cast + (i  )*rs_at + (i  )*cs_at; \
197                         a10t     = a_cast + (i  )*rs_at + (0  )*cs_at; \
198                         chi1     = x_cast + (i  )*incx; \
199                         x0       = x_cast + (0  )*incx; \
201                         /* chi1 = chi1 - a10t * x0; */ \
202                         PASTEMAC3(cha,chx,chax,kername)( conja, \
203                                                          BLIS_NO_CONJUGATE, \
204                                                          n_behind, \
205                                                          a10t, cs_at, \
206                                                          x0,   incx, \
207                                                          &rho ); \
208                         PASTEMAC2(chax,chx,subs)( rho, *chi1 ); \
210                         /* chi1 = chi1 / alpha11; */ \
211                         if ( bli_is_nonunit_diag( diag ) ) \
212                         { \
213                                 PASTEMAC2(cha,chax,copycjs)( conja, *alpha11, alpha11_conj ); \
214                                 PASTEMAC2(chax,chx,invscals)( alpha11_conj, *chi1 ); \
215                         } \
216                 } \
217         } \
220 // Define the basic set of functions unconditionally, and then also some
221 // mixed datatype functions if requested.
222 INSERT_GENTFUNC2U_BASIC( trsv_unb_var1, DOTV_KERNEL )
224 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
225 INSERT_GENTFUNC2U_MIX_D( trsv_unb_var1, DOTV_KERNEL )
226 #endif
228 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
229 INSERT_GENTFUNC2U_MIX_P( trsv_unb_var1, DOTV_KERNEL )
230 #endif