DSPLIB User Guide
DSPLIB_q15tofl_ci.cpp
Go to the documentation of this file.
1 /******************************************************************************/
5 /* Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
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
17  * distribution.
18  *
19  * Neither the name of Texas Instruments Incorporated nor the names of
20  * its contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  ******************************************************************************/
36 
37 /******************************************************************************
38  * Version 1.0 Date Aug 2023 Author: Asheesh Bhardwaj
39  *****************************************************************************/
40 
41 /*******************************************************************************
42  *
43  * INCLUDES
44  *
45  ******************************************************************************/
46 
47 #include "DSPLIB_q15tofl_priv.h"
48 
49 template <typename dataTypeOut> inline __SE_TEMPLATE_v1 q15tofl_se_init(int32_t blockSize);
50 
51 template <> inline __SE_TEMPLATE_v1 q15tofl_se_init<float>(int32_t blockSize)
52 {
53  typedef typename c7x::short_hvec vecIn;
54  typedef typename c7x::make_full_vector<float>::type vecOut;
55  __SE_ELETYPE SE_ELETYPE = c7x::se_eletype<vecIn>::value;
56  __SE_VECLEN SE_VECLEN = c7x::se_veclen<vecOut>::value;
57 
58  __SE_TEMPLATE_v1 se0Params = __gen_SE_TEMPLATE_v1();
59  se0Params.ICNT0 = blockSize;
60  se0Params.ELETYPE = SE_ELETYPE;
61  se0Params.VECLEN = SE_VECLEN;
62  se0Params.DIMFMT = __SE_DIMFMT_1D;
63  se0Params.PROMOTE = __SE_PROMOTE_2X_SIGNEXT;
64 
65  return se0Params;
66 }
67 
68 template <> inline __SE_TEMPLATE_v1 q15tofl_se_init<double>(int32_t blockSize)
69 {
70  typedef typename c7x::short_qvec vecIn;
71  typedef typename c7x::make_full_vector<double>::type vecOut;
72  __SE_ELETYPE SE_ELETYPE = c7x::se_eletype<vecIn>::value;
73  __SE_VECLEN SE_VECLEN = c7x::se_veclen<vecOut>::value;
74 
75  __SE_TEMPLATE_v1 se0Params = __gen_SE_TEMPLATE_v1();
76  se0Params.ICNT0 = blockSize;
77  se0Params.ELETYPE = SE_ELETYPE;
78  se0Params.VECLEN = SE_VECLEN;
79  se0Params.DIMFMT = __SE_DIMFMT_1D;
80  se0Params.PROMOTE = __SE_PROMOTE_4X_SIGNEXT;
81 
82  return se0Params;
83 }
84 
85 template <typename dataTypeOut>
87  const DSPLIB_bufParams1D_t *bufParamsIn,
88  const DSPLIB_bufParams1D_t *bufParamsOut,
89  const DSPLIB_q15tofl_InitArgs *pKerInitArgs)
90 {
91  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
92 
94  DSPLIB_q15tofl_PrivArgs *pKerPrivArgs = (DSPLIB_q15tofl_PrivArgs *) handle;
95  uint32_t blockSize = pKerPrivArgs->blockSize;
96  uint8_t *pBlock = pKerPrivArgs->bufPblock;
97 
98  typedef typename c7x::make_full_vector<dataTypeOut>::type vecOut;
99 
100  __SA_VECLEN SA_VECLEN = c7x::sa_veclen<vecOut>::value;
101 
102  /**********************************************************************/
103  /* Prepare streaming engine 0 to fetch the input */
104  /**********************************************************************/
105  __SE_TEMPLATE_v1 se0Params = q15tofl_se_init<dataTypeOut>(blockSize);
106  DSPLIB_DEBUGPRINTFN(0, "se0Params.PROMOTE: %d\n", se0Params.PROMOTE);
107 
108  /**********************************************************************/
109  /* Prepare SA template to store output */
110  /**********************************************************************/
111  __SA_TEMPLATE_v1 sa0Params = __gen_SA_TEMPLATE_v1();
112  sa0Params.ICNT0 = blockSize;
113  sa0Params.VECLEN = SA_VECLEN;
114  sa0Params.DIMFMT = __SA_DIMFMT_1D;
115 
116  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET) = se0Params;
117  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET) = sa0Params;
118 
119  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
120 
121  return status;
122 }
123 
125  const DSPLIB_bufParams1D_t *bufParamsIn,
126  const DSPLIB_bufParams1D_t *bufParamsOut,
127  const DSPLIB_q15tofl_InitArgs *pKerInitArgs);
129  const DSPLIB_bufParams1D_t *bufParamsIn,
130  const DSPLIB_bufParams1D_t *bufParamsOut,
131  const DSPLIB_q15tofl_InitArgs *pKerInitArgs);
132 
133 template <typename dataTypeOut> inline void q15tofl_convert(dataTypeOut *restrict pOutLocal, int32_t blockSize);
134 
135 template <> inline void q15tofl_convert<float>(float *restrict pOutLocal, int32_t blockSize)
136 {
137  typedef typename c7x::int_vec vecLoad;
138  typedef typename c7x::make_full_vector<float>::type vecOut;
139  int32_t eleCount = c7x::element_count_of<vecOut>::value;
140  vecOut outDat, scale;
141 
142  scale = (vecOut) (1.0 / 32768);
143 
144  for (int32_t counter = 0; counter < blockSize; counter += eleCount) {
145  vecLoad inDat = c7x::strm_eng<0, vecLoad>::get_adv();
146  vecOut inDatConv = __int_to_float(c7x::as_int_vec(inDat));
147  outDat = inDatConv * scale;
148 
149  /* Store the result */
150  __vpred vpred = c7x::strm_agen<0, vecOut>::get_vpred();
151  vecOut *addr = c7x::strm_agen<0, vecOut>::get_adv(pOutLocal);
152  __vstore_pred(vpred, addr, outDat);
153  }
154 }
155 
156 template <> inline void q15tofl_convert<double>(double *restrict pOutLocal, int32_t blockSize)
157 {
158  typedef typename c7x::long_vec vecLoad;
159  typedef typename c7x::make_full_vector<double>::type vecOut;
160  int32_t eleCount = c7x::element_count_of<vecOut>::value;
161  vecOut outDat, scale;
162 
163  scale = (vecOut) (1.0 / 32768);
164 
165  for (int32_t counter = 0; counter < blockSize; counter += eleCount) {
166  vecLoad inDat = c7x::strm_eng<0, vecLoad>::get_adv();
167  vecOut inDatConv = __low_int_to_double(c7x::as_int_vec(inDat));
168  outDat = inDatConv * scale;
169 
170  /* Store the result */
171  __vpred vpred = c7x::strm_agen<0, vecOut>::get_vpred();
172  vecOut *addr = c7x::strm_agen<0, vecOut>::get_adv(pOutLocal);
173  __vstore_pred(vpred, addr, outDat);
174  }
175 }
176 
177 template <typename dataTypeOut>
178 DSPLIB_STATUS DSPLIB_q15tofl_exec_ci(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
179 {
180  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
181 
182  DSPLIB_q15tofl_PrivArgs *pKerPrivArgs = (DSPLIB_q15tofl_PrivArgs *) handle;
183  int32_t blockSize = pKerPrivArgs->blockSize;
184 
185  __SE_TEMPLATE_v1 se0Params;
186  __SA_TEMPLATE_v1 sa0Params;
187 
188  int16_t *restrict pInLocal = (int16_t *) pIn;
189  dataTypeOut *restrict pOutLocal = (dataTypeOut *) pOut;
190 
191  DSPLIB_DEBUGPRINTFN(0, "pInLocal: %p pOutLocal: %p blockSize: %d\n", pInLocal, pOutLocal, blockSize);
192 
193  uint8_t *pBlock = pKerPrivArgs->bufPblock;
194  se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET);
195  sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET);
196 
197  __SE0_OPEN(pInLocal, se0Params);
198  __SA0_OPEN(sa0Params);
199 
200  q15tofl_convert<dataTypeOut>(pOutLocal, blockSize);
201 
202  __SE0_CLOSE();
203  __SA0_CLOSE();
204 
205  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", DSPLIB_SUCCESS);
206 
207  return DSPLIB_SUCCESS;
208 }
209 
211 DSPLIB_q15tofl_exec_ci<float>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
213 DSPLIB_q15tofl_exec_ci<double>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
#define SE_SE0_PARAM_OFFSET
#define SE_SA0_PARAM_OFFSET
DSPLIB_STATUS DSPLIB_q15tofl_exec_ci(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main execution function for the C7x implementation of the kernel....
template DSPLIB_STATUS DSPLIB_q15tofl_exec_ci< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_q15tofl_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_q15tofl_InitArgs *pKerInitArgs)
void q15tofl_convert< float >(float *restrict pOutLocal, int32_t blockSize)
__SE_TEMPLATE_v1 q15tofl_se_init(int32_t blockSize)
void q15tofl_convert(dataTypeOut *restrict pOutLocal, int32_t blockSize)
void q15tofl_convert< double >(double *restrict pOutLocal, int32_t blockSize)
template DSPLIB_STATUS DSPLIB_q15tofl_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_q15tofl_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_q15tofl_init_ci(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_q15tofl_InitArgs *pKerInitArgs)
This function is the initialization function for the C7x implementation of the kernel....
__SE_TEMPLATE_v1 q15tofl_se_init< float >(int32_t blockSize)
__SE_TEMPLATE_v1 q15tofl_se_init< double >(int32_t blockSize)
template DSPLIB_STATUS DSPLIB_q15tofl_exec_ci< double >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_q15tofl.
#define DSPLIB_DEBUGPRINTFN(N, fmt,...)
Definition: DSPLIB_types.h:83
DSPLIB_STATUS_NAME
The enumeration of all status codes.
Definition: DSPLIB_types.h:151
void * DSPLIB_kernelHandle
Handle type for DSPLIB operations.
Definition: DSPLIB_types.h:172
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152
A structure for a 1 dimensional buffer descriptor.
Structure containing the parameters to initialize the kernel.
Structure that is reserved for internal use by the kernel.
uint8_t bufPblock[DSPLIB_Q15TOFL_IXX_IXX_OXX_PBLOCK_SIZE]
Buffer to save SE & SA configuration parameters
int32_t blockSize
Size of input buffer for different batches DSPLIB_q15tofl_init that will be retrieved and used by DSP...