DSPLIB User Guide
DSPLIB_svd_small_singular_sort.h
Go to the documentation of this file.
1 
2 /******************************************************************************/
6 /* Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the
18  * distribution.
19  *
20  * Neither the name of Texas Instruments Incorporated nor the names of
21  * its contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  ******************************************************************************/
37 
38 /******************************************************************************
39  * Version 1.0 Date Aug 2023 Author: Asheesh Bhardwaj
40  *****************************************************************************/
41 
42 /*******************************************************************************
43  *
44  * INCLUDES
45  *
46  ******************************************************************************/
47 
48 #include "DSPLIB_svd_small_priv.h"
49 
50 
51 /* *****************************************************************************
52  *
53  * IMPLEMENTATION
54  *
55  ***************************************************************************** */
56 #if (__C7X_VEC_SIZE_BITS__ == 512)
57 
58 template <typename dataType>
59 inline void sort_singular_vals(dataType *diag,
60  dataType *U,
61  dataType *V,
62  const int Nrows,
63  const int Ncols,
64  const int colUStride,
65  const int colVStride);
66 
67 template <>
68 inline void sort_singular_vals<float>(float *diag,
69  float *U,
70  float *V,
71  const int Nrows,
72  const int Ncols,
73  const int colUStride,
74  const int colVStride)
75 {
76  return;
77 }
78 
79 template <>
80 inline void sort_singular_vals<double>(double *singular_values,
81  double *U,
82  double *V,
83  const int Nrows,
84  const int Ncols,
85  const int colUStride,
86  const int colVStride)
87 {
88 
89  typedef typename c7x::make_full_vector<double>::type vec_dp;
90  typedef typename c7x::make_full_vector<float>::type vec_sp;
91 
92  __vpred pred_diag_elems = __mask_long((uint32_t) Ncols);
93 
94  vec_dp vec_diag = __vload_pred(pred_diag_elems, (vec_dp *) singular_values);
95 
96  vec_sp vec_diag_temp = __double_to_float(vec_diag);
97 
98  vec_sp test_vec_1 = c7x::as_float_vec(__shift_left_full(c7x::as_ulong_vec(vec_diag_temp), 32u));
99 
100  vec_sp test_vec_2 = vec_diag_temp + test_vec_1;
101 
102  c7x::uchar_vec vec_rearrange = __sort_desc_perm(test_vec_2);
103 
104  vec_rearrange = c7x::as_uchar_vec(__swap(c7x::as_uint_vec(vec_rearrange)));
105 
106  vec_sp vec_sorted_temp = __sort_desc(test_vec_2);
107  vec_dp vec_sorted_sv = __low_float_to_double(vec_sorted_temp);
108  __vstore_pred(pred_diag_elems, (vec_dp *)singular_values, vec_sorted_sv);
109 
110 
111 /* ---------------------------------------------------------------------------- */
112 /* REARRANGE V MATRIX */
113 /* ---------------------------------------------------------------------------- */
114  vec_dp vec_v_in0 = __vload_pred(pred_diag_elems, (vec_dp *) (V + 0 * colVStride));
115  vec_dp vec_v_in1 = __vload_pred(pred_diag_elems, (vec_dp *) (V + 1 * colVStride));
116  vec_dp vec_v_in2 = __vload_pred(pred_diag_elems, (vec_dp *) (V + 2 * colVStride));
117  vec_dp vec_v_in3 = __vload_pred(pred_diag_elems, (vec_dp *) (V + 3 * colVStride));
118  vec_dp vec_v_in4 = __vload_pred(pred_diag_elems, (vec_dp *) (V + 4 * colVStride));
119  vec_dp vec_v_in5 = __vload_pred(pred_diag_elems, (vec_dp *) (V + 5 * colVStride));
120 
121  vec_v_in0 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_v_in0)));
122  vec_v_in1 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_v_in1)));
123  vec_v_in2 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_v_in2)));
124  vec_v_in3 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_v_in3)));
125  vec_v_in4 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_v_in4)));
126  vec_v_in5 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_v_in5)));
127 
128  __vstore_pred(pred_diag_elems, (vec_dp *)(V + 0 * colVStride), vec_v_in0);
129  __vstore_pred(pred_diag_elems, (vec_dp *)(V + 1 * colVStride), vec_v_in1);
130  __vstore_pred(pred_diag_elems, (vec_dp *)(V + 2 * colVStride), vec_v_in2);
131  __vstore_pred(pred_diag_elems, (vec_dp *)(V + 3 * colVStride), vec_v_in3);
132  __vstore_pred(pred_diag_elems, (vec_dp *)(V + 4 * colVStride), vec_v_in4);
133  __vstore_pred(pred_diag_elems, (vec_dp *)(V + 5 * colVStride), vec_v_in5);
134 
135 
136 
137 /* ---------------------------------------------------------------------------- */
138 /* REARRANGE U MATRIX */
139 /* ---------------------------------------------------------------------------- */
140  vec_dp vec_u_in0 = __vload_pred(pred_diag_elems, (vec_dp *) (U + 0 * colUStride));
141  vec_dp vec_u_in1 = __vload_pred(pred_diag_elems, (vec_dp *) (U + 1 * colUStride));
142  vec_dp vec_u_in2 = __vload_pred(pred_diag_elems, (vec_dp *) (U + 2 * colUStride));
143  vec_dp vec_u_in3 = __vload_pred(pred_diag_elems, (vec_dp *) (U + 3 * colUStride));
144  vec_dp vec_u_in4 = __vload_pred(pred_diag_elems, (vec_dp *) (U + 4 * colUStride));
145  vec_dp vec_u_in5 = __vload_pred(pred_diag_elems, (vec_dp *) (U + 5 * colUStride));
146 
147  vec_u_in0 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_u_in0)));
148  vec_u_in1 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_u_in1)));
149  vec_u_in2 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_u_in2)));
150  vec_u_in3 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_u_in3)));
151  vec_u_in4 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_u_in4)));
152  vec_u_in5 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_u_in5)));
153 
154  __vstore_pred(pred_diag_elems, (vec_dp *)(U + 0 * colUStride), vec_u_in0);
155  __vstore_pred(pred_diag_elems, (vec_dp *)(U + 1 * colUStride), vec_u_in1);
156  __vstore_pred(pred_diag_elems, (vec_dp *)(U + 2 * colUStride), vec_u_in2);
157  __vstore_pred(pred_diag_elems, (vec_dp *)(U + 3 * colUStride), vec_u_in3);
158  __vstore_pred(pred_diag_elems, (vec_dp *)(U + 4 * colUStride), vec_u_in4);
159  __vstore_pred(pred_diag_elems, (vec_dp *)(U + 5 * colUStride), vec_u_in5);
160 
161 
162 if (Nrows == 7){
163  vec_dp vec_u_in6 = __vload_pred(pred_diag_elems, (vec_dp *) (U + 6 * colUStride));
164  vec_u_in6 = c7x::as_double_vec(__permute(vec_rearrange, c7x::as_uchar_vec(vec_u_in6)));
165  __vstore_pred(pred_diag_elems, (vec_dp *)(U + 6 * colUStride), vec_u_in6);
166 }
167 
168 
169  return;
170 }
171 
172 #endif /* #if (__C7X_VEC_SIZE_BITS__ == 512) */
173 
174 /* ======================================================================== */
175 /* End of file: DSPLIB_svd_small_singular_sort.h */
176 /* ======================================================================== */
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_svd.