DSPLIB User Guide
DSPLIB_mulConstant_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 10/2/22 Author: Asheesh Bhardwaj
39  *****************************************************************************/
40 
41 /*******************************************************************************
42  *
43  * INCLUDES
44  *
45  ******************************************************************************/
46 
47 #include "../common/c71/DSPLIB_inlines.h"
49 #include <float.h>
50 
51 /*******************************************************************************
52  *
53  * DEFINES
54  *
55  ******************************************************************************/
56 #define SE_PARAM_BASE (0x0000)
57 #define SE_SE0_PARAM_OFFSET (SE_PARAM_BASE)
58 #define SE_SA0_PARAM_OFFSET (SE_SE0_PARAM_OFFSET + SE_PARAM_SIZE)
59 
60 template <typename dataType>
62  const DSPLIB_bufParams1D_t *bufParamsIn,
63  const DSPLIB_bufParams1D_t *bufParamsOut,
64  const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
65 {
67  __SE_TEMPLATE_v1 se0Params;
68  __SA_TEMPLATE_v1 sa0Params;
69 
70  __SE_ELETYPE SE_ELETYPE;
71  __SE_VECLEN SE_VECLEN;
72  __SA_VECLEN SA_VECLEN;
73 
75 
76  uint8_t *pBlock = pKerPrivArgs->bufPblock;
77  uint32_t blockSize = pKerPrivArgs->blockSize;
78 
79  typedef typename c7x::make_full_vector<dataType>::type vec;
80  SE_VECLEN = c7x::se_veclen<vec>::value;
81  SA_VECLEN = c7x::sa_veclen<vec>::value;
82  SE_ELETYPE = c7x::se_eletype<vec>::value;
83 
84  /**********************************************************************/
85  /* Prepare streaming engine 1 to fetch the input */
86  /**********************************************************************/
87  se0Params = __gen_SE_TEMPLATE_v1();
88 
89  se0Params.ICNT0 = blockSize;
90  se0Params.ELETYPE = SE_ELETYPE;
91  se0Params.VECLEN = SE_VECLEN;
92  se0Params.DIMFMT = __SE_DIMFMT_1D;
93 
94  /**********************************************************************/
95  /* Prepare SA template to store output */
96  /**********************************************************************/
97  sa0Params = __gen_SA_TEMPLATE_v1();
98 
99  sa0Params.ICNT0 = blockSize;
100  sa0Params.DIM1 = blockSize;
101  sa0Params.VECLEN = SA_VECLEN;
102  sa0Params.DIMFMT = __SA_DIMFMT_1D;
103 
104  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET) = se0Params;
105  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET) = sa0Params;
106 
107  return status;
108 }
109 
111  const DSPLIB_bufParams1D_t *bufParamsIn,
112  const DSPLIB_bufParams1D_t *bufParamsOut,
113  const DSPLIB_mulConstant_InitArgs *pKerInitArgs);
114 
116  const DSPLIB_bufParams1D_t *bufParamsIn,
117  const DSPLIB_bufParams1D_t *bufParamsOut,
118  const DSPLIB_mulConstant_InitArgs *pKerInitArgs);
119 
121  const DSPLIB_bufParams1D_t *bufParamsIn,
122  const DSPLIB_bufParams1D_t *bufParamsOut,
123  const DSPLIB_mulConstant_InitArgs *pKerInitArgs);
124 
126  const DSPLIB_bufParams1D_t *bufParamsIn,
127  const DSPLIB_bufParams1D_t *bufParamsOut,
128  const DSPLIB_mulConstant_InitArgs *pKerInitArgs);
129 
131  const DSPLIB_bufParams1D_t *bufParamsIn,
132  const DSPLIB_bufParams1D_t *bufParamsOut,
133  const DSPLIB_mulConstant_InitArgs *pKerInitArgs);
134 
136  const DSPLIB_bufParams1D_t *bufParamsIn,
137  const DSPLIB_bufParams1D_t *bufParamsOut,
138  const DSPLIB_mulConstant_InitArgs *pKerInitArgs);
139 
141  const DSPLIB_bufParams1D_t *bufParamsIn,
142  const DSPLIB_bufParams1D_t *bufParamsOut,
143  const DSPLIB_mulConstant_InitArgs *pKerInitArgs);
144 
146  const DSPLIB_bufParams1D_t *bufParamsIn,
147  const DSPLIB_bufParams1D_t *bufParamsOut,
148  const DSPLIB_mulConstant_InitArgs *pKerInitArgs);
149 
150 template <typename dataType, int32_t dataIn>
152 DSPLIB_mulConstant_exec_ci(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
153 {
154  DSPLIB_mulConstant_PrivArgs *pKerPrivArgs = (DSPLIB_mulConstant_PrivArgs *) handle;
155  uint32_t blockSize = pKerPrivArgs->blockSize;
156 
157  __SE_TEMPLATE_v1 se0Params;
158  __SA_TEMPLATE_v1 sa0Params;
159 
160  dataType *restrict pInLocal1 = (dataType *) pIn1;
161  dataType *restrict pInLocal2 = (dataType *) pIn2;
162  dataType *restrict pOutLocal = (dataType *) pOut;
163 
164 #if DSPLIB_DEBUGPRINT
165  printf("Enter DSPLIB_mulConstant_exec_ci\n");
166 #endif
167 
168  typedef typename c7x::make_full_vector<dataType>::type vec;
169  int32_t eleCount = c7x::element_count_of<vec>::value;
170 
171 #if DSPLIB_DEBUGPRINT
172  printf("Enter eleCount %d\n", eleCount);
173 #endif
174 
175  uint8_t *pBlock = pKerPrivArgs->bufPblock;
176 
177  se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET);
178 
179  sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET);
180  __SA0_OPEN(sa0Params);
181 
182  // Input samples
183  __SE1_OPEN(pInLocal2, se0Params);
184 
185  // Output samples
186  __SA0_OPEN(sa0Params);
187 
188 #if DSPLIB_DEBUGPRINT
189  printf("DSPLIB_DEBUGPRINT blockSize %d\n", blockSize);
190 #endif
191 
192  vec out;
193 
194  dataType x = *pInLocal1;
195  vec a = (vec) x;
196  for (int32_t counter = 0; counter < blockSize; counter += eleCount) {
197  vec b = c7x::strm_eng<1, vec>::get_adv();
198 
199  out = a * b;
200 
201  __vpred tmp = c7x::strm_agen<0, vec>::get_vpred();
202  vec *VB1 = c7x::strm_agen<0, vec>::get_adv(pOutLocal);
203 
204  __vstore_pred(tmp, VB1, out);
205  }
206  __SE1_CLOSE();
207  __SA0_CLOSE();
208 
209  return DSPLIB_SUCCESS;
210 }
211 
213  void *restrict pIn1,
214  void *restrict pIn2,
215  void *restrict pOut);
216 
218  void *restrict pIn1,
219  void *restrict pIn2,
220  void *restrict pOut);
221 
223  void *restrict pIn1,
224  void *restrict pIn2,
225  void *restrict pOut);
226 
228  void *restrict pIn1,
229  void *restrict pIn2,
230  void *restrict pOut);
231 
233  void *restrict pIn1,
234  void *restrict pIn2,
235  void *restrict pOut);
236 
238  void *restrict pIn1,
239  void *restrict pIn2,
240  void *restrict pOut);
241 
243  void *restrict pIn1,
244  void *restrict pIn2,
245  void *restrict pOut);
246 
248  void *restrict pIn1,
249  void *restrict pIn2,
250  void *restrict pOut);
template DSPLIB_STATUS DSPLIB_mulConstant_exec_ci< int32_t, DSPLIB_INT32 >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_mulConstant_init_ci< uint16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_mulConstant_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_mulConstant_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_mulConstant_exec_ci< uint16_t, DSPLIB_UINT16 >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_mulConstant_init_ci< uint8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
#define SE_SE0_PARAM_OFFSET
DSPLIB_STATUS DSPLIB_mulConstant_init_ci(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
This function is the initialization function for the C7x implementation of the kernel....
DSPLIB_STATUS DSPLIB_mulConstant_exec_ci(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
This function is the main execution function for the C7x implementation of the kernel....
template DSPLIB_STATUS DSPLIB_mulConstant_exec_ci< uint8_t, DSPLIB_UINT8 >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_mulConstant_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_mulConstant_exec_ci< uint32_t, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_mulConstant_exec_ci< int8_t, DSPLIB_INT8 >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_mulConstant_exec_ci< float, DSPLIB_FLOAT32 >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_mulConstant_init_ci< uint32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_mulConstant_exec_ci< int16_t, DSPLIB_INT16 >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_mulConstant_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_mulConstant_exec_ci< double, DSPLIB_FLOAT64 >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_mulConstant_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_mulConstant_InitArgs *pKerInitArgs)
#define SE_SA0_PARAM_OFFSET
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_mulConstant.
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_MULCONSTANT_IXX_IXX_OXX_PBLOCK_SIZE]
int32_t blockSize
Size of input buffer for different batches DSPLIB_mulConstant_init that will be retrieved and used by...