DSPLIB User Guide
DSPLIB_sqrAdd_cn.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 **+--------------------------------------------------------------------------+**
3 **| **** |**
4 **| **** |**
5 **| ******o*** |**
6 **| ********_///_**** |**
7 **| ***** /_//_/ **** |**
8 **| ** ** (__/ **** |**
9 **| ********* |**
10 **| **** |**
11 **| *** |**
12 **| |**
13 **| Copyright (c) 2016 Texas Instruments Incorporated |**
14 **| ALL RIGHTS RESERVED |**
15 **| |**
16 **| Permission to use, copy, modify, or distribute this software, |**
17 **| whether in part or in whole, for any purpose is forbidden without |**
18 **| a signed licensing agreement and NDA from Texas Instruments |**
19 **| Incorporated (TI). |**
20 **| |**
21 **| TI makes no representation or warranties with respect to the |**
22 **| performance of this computer program, and specifically disclaims |**
23 **| any responsibility for any damages, special or consequential, |**
24 **| connected with the use of this program. |**
25 **| |**
26 **+--------------------------------------------------------------------------+**
27 *******************************************************************************/
28 
29 #include "DSPLIB_sqrAdd_priv.h"
30 
31 /**********************************************************************/
32 /* Execute for datatypes float and double */
33 /**********************************************************************/
34 
35 // This is the generic implementation of exec_ci. It is used for float and double.
36 // Other datatypes have their own explicet implementation.
37 template <typename dataType>
38 DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
39 {
41 
42  DSPLIB_sqrAdd_PrivArgs *pKerPrivArgs = (DSPLIB_sqrAdd_PrivArgs *) handle;
43  uint32_t blockSize = pKerPrivArgs->blockSize;
44 
45 #if DSPLIB_DEBUGPRINT
46  printf("Enter DSPLIB_sqrAdd_exec_cn\n");
47 #endif
48 
49  dataType *pInLocal1 = (dataType *) pIn;
50  dataType *pOutLocal = (dataType *) pOut;
51 
52 #if DSPLIB_DEBUGPRINT
53  printf("Enter pInLocal1 %p pOut %p\n", pInLocal1, pOut);
54 #endif
55 
56  dataType a;
57  dataType out = 0;
58 
59  for (int32_t counter = 0; counter < blockSize; counter++) {
60  a = *pInLocal1++;
61 #if DSPLIB_DEBUGPRINT
62  if (counter <= 8)
63  printf("counter %d a %f\n", counter, a);
64 #endif
65 
66  out += (a * a);
67  }
68  *pOutLocal = out;
69 
70 #if DSPLIB_DEBUGPRINT
71  printf("DSPLIB_DEBUGPRINT DSPLIB_sqrAdd_exec_cn result %lf\n", out);
72 #endif
73  return (status);
74 }
75 
76 /**********************************************************************/
77 /* Execute for datatype int8_t */
78 /**********************************************************************/
79 template <>
80 DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn<int8_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
81 {
83 
84  DSPLIB_sqrAdd_PrivArgs *pKerPrivArgs = (DSPLIB_sqrAdd_PrivArgs *) handle;
85  uint32_t blockSize = pKerPrivArgs->blockSize;
86 
87 #if DSPLIB_DEBUGPRINT
88  printf("Enter DSPLIB_sqrAdd_exec_cn\n");
89 #endif
90 
91  int8_t *pInLocal1 = (int8_t *) pIn;
92  int32_t *pOutLocal = (int32_t *) pOut;
93 
94 #if DSPLIB_DEBUGPRINT
95  printf("Enter pInLocal1 %p pOut %p\n", pInLocal1, pOut);
96 #endif
97 
98  int8_t a;
99  int32_t out = 0;
100 
101  for (int32_t counter = 0; counter < blockSize; counter++) {
102  a = *pInLocal1++;
103 #if DSPLIB_DEBUGPRINT
104  if (counter <= 8)
105  printf("counter %d a %f\n", counter, a);
106 #endif
107 
108  out += ((int32_t) a * (int32_t) a);
109  }
110  *pOutLocal = out;
111 
112 #if DSPLIB_DEBUGPRINT
113  printf("DSPLIB_DEBUGPRINT DSPLIB_sqrAdd_exec_cn result %lf\n", out);
114 #endif
115  return (status);
116 }
117 
118 /**********************************************************************/
119 /* Execute for datatype uint8_t */
120 /**********************************************************************/
121 template <>
122 DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn<uint8_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
123 {
124  DSPLIB_STATUS status = DSPLIB_SUCCESS;
125 
126  DSPLIB_sqrAdd_PrivArgs *pKerPrivArgs = (DSPLIB_sqrAdd_PrivArgs *) handle;
127  uint32_t blockSize = pKerPrivArgs->blockSize;
128 
129 #if DSPLIB_DEBUGPRINT
130  printf("Enter DSPLIB_sqrAdd_exec_cn\n");
131 #endif
132 
133  uint8_t *pInLocal1 = (uint8_t *) pIn;
134  uint32_t *pOutLocal = (uint32_t *) pOut;
135 
136 #if DSPLIB_DEBUGPRINT
137  printf("Enter pInLocal1 %p pOut %p\n", pInLocal1, pOut);
138 #endif
139 
140  uint8_t a;
141  uint32_t out = 0;
142 
143  for (int32_t counter = 0; counter < blockSize; counter++) {
144  a = *pInLocal1++;
145 #if DSPLIB_DEBUGPRINT
146  if (counter <= 8)
147  printf("counter %d a %f\n", counter, a);
148 #endif
149 
150  out += ((uint32_t) a * (uint32_t) a);
151  }
152  *pOutLocal = out;
153 
154 #if DSPLIB_DEBUGPRINT
155  printf("DSPLIB_DEBUGPRINT DSPLIB_sqrAdd_exec_cn result %lf\n", out);
156 #endif
157  return (status);
158 }
159 
160 /**********************************************************************/
161 /* Execute for datatype int16_t */
162 /**********************************************************************/
163 template <>
164 DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn<int16_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
165 {
166  DSPLIB_STATUS status = DSPLIB_SUCCESS;
167 
168  DSPLIB_sqrAdd_PrivArgs *pKerPrivArgs = (DSPLIB_sqrAdd_PrivArgs *) handle;
169  uint32_t blockSize = pKerPrivArgs->blockSize;
170 
171 #if DSPLIB_DEBUGPRINT
172  printf("Enter DSPLIB_sqrAdd_exec_cn\n");
173 #endif
174 
175  int16_t *pInLocal1 = (int16_t *) pIn;
176  int64_t *pOutLocal = (int64_t *) pOut;
177 
178 #if DSPLIB_DEBUGPRINT
179  printf("Enter pInLocal1 %p pOut %p\n", pInLocal1, pOut);
180 #endif
181 
182  int16_t a;
183  int64_t out = 0;
184 
185  for (int32_t counter = 0; counter < blockSize; counter++) {
186  a = *pInLocal1++;
187 #if DSPLIB_DEBUGPRINT
188  if (counter <= 8)
189  printf("counter %d a %f\n", counter, a);
190 #endif
191 
192  out += ((int64_t) a * (int64_t) a);
193  }
194  *pOutLocal = out;
195 
196 #if DSPLIB_DEBUGPRINT
197  printf("DSPLIB_DEBUGPRINT DSPLIB_sqrAdd_exec_cn result %lf\n", out);
198 #endif
199  return (status);
200 }
201 
202 /**********************************************************************/
203 /* Execute for datatype uint16_t */
204 /**********************************************************************/
205 template <>
206 DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn<uint16_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
207 {
208  DSPLIB_STATUS status = DSPLIB_SUCCESS;
209 
210  DSPLIB_sqrAdd_PrivArgs *pKerPrivArgs = (DSPLIB_sqrAdd_PrivArgs *) handle;
211  uint32_t blockSize = pKerPrivArgs->blockSize;
212 
213 #if DSPLIB_DEBUGPRINT
214  printf("Enter DSPLIB_sqrAdd_exec_cn\n");
215 #endif
216 
217  uint16_t *pInLocal1 = (uint16_t *) pIn;
218  uint64_t *pOutLocal = (uint64_t *) pOut;
219 
220 #if DSPLIB_DEBUGPRINT
221  printf("Enter pInLocal1 %p pOut %p\n", pInLocal1, pOut);
222 #endif
223 
224  uint16_t a;
225  uint64_t out = 0;
226 
227  for (int32_t counter = 0; counter < blockSize; counter++) {
228  a = *pInLocal1++;
229 #if DSPLIB_DEBUGPRINT
230  if (counter <= 8)
231  printf("counter %d a %f\n", counter, a);
232 #endif
233 
234  out += ((uint64_t) a * (uint64_t) a);
235  }
236  *pOutLocal = out;
237 
238 #if DSPLIB_DEBUGPRINT
239  printf("DSPLIB_DEBUGPRINT DSPLIB_sqrAdd_exec_cn result %lf\n", out);
240 #endif
241  return (status);
242 }
243 
244 /**********************************************************************/
245 /* Execute for datatype int32_t */
246 /**********************************************************************/
247 template <>
248 DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn<int32_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
249 {
250  DSPLIB_STATUS status = DSPLIB_SUCCESS;
251 
252  DSPLIB_sqrAdd_PrivArgs *pKerPrivArgs = (DSPLIB_sqrAdd_PrivArgs *) handle;
253  uint32_t blockSize = pKerPrivArgs->blockSize;
254 
255 #if DSPLIB_DEBUGPRINT
256  printf("Enter DSPLIB_sqrAdd_exec_cn\n");
257 #endif
258 
259  int32_t *pInLocal1 = (int32_t *) pIn;
260  int64_t *pOutLocal = (int64_t *) pOut;
261 
262 #if DSPLIB_DEBUGPRINT
263  printf("Enter pInLocal1 %p pOut %p\n", pInLocal1, pOut);
264 #endif
265 
266  int32_t a;
267  int64_t out = 0;
268 
269  for (int32_t counter = 0; counter < blockSize; counter++) {
270  a = *pInLocal1++;
271 #if DSPLIB_DEBUGPRINT
272  if (counter <= 8)
273  printf("counter %d a %f\n", counter, a);
274 #endif
275 
276  out += ((int64_t) a * (int64_t) a);
277  }
278  *pOutLocal = out;
279 
280 #if DSPLIB_DEBUGPRINT
281  printf("DSPLIB_DEBUGPRINT DSPLIB_sqrAdd_exec_cn result %lf\n", out);
282 #endif
283  return (status);
284 }
285 
286 /**********************************************************************/
287 /* Execute for datatype uint32_t */
288 /**********************************************************************/
289 template <>
290 DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn<uint32_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
291 {
292  DSPLIB_STATUS status = DSPLIB_SUCCESS;
293 
294  DSPLIB_sqrAdd_PrivArgs *pKerPrivArgs = (DSPLIB_sqrAdd_PrivArgs *) handle;
295  uint32_t blockSize = pKerPrivArgs->blockSize;
296 
297 #if DSPLIB_DEBUGPRINT
298  printf("Enter DSPLIB_sqrAdd_exec_cn\n");
299 #endif
300 
301  uint32_t *pInLocal1 = (uint32_t *) pIn;
302  uint64_t *pOutLocal = (uint64_t *) pOut;
303 
304 #if DSPLIB_DEBUGPRINT
305  printf("Enter pInLocal1 %p pOut %p\n", pInLocal1, pOut);
306 #endif
307 
308  uint32_t a;
309  uint64_t out = 0;
310 
311  for (int32_t counter = 0; counter < blockSize; counter++) {
312  a = *pInLocal1++;
313 #if DSPLIB_DEBUGPRINT
314  if (counter <= 8)
315  printf("counter %d a %f\n", counter, a);
316 #endif
317 
318  out += ((uint64_t) a * (uint64_t) a);
319  }
320  *pOutLocal = out;
321 
322 #if DSPLIB_DEBUGPRINT
323  printf("DSPLIB_DEBUGPRINT DSPLIB_sqrAdd_exec_cn result %lf\n", out);
324 #endif
325  return (status);
326 }
327 
328 // explicit inssqrAddtiation for the different data type versions
330 DSPLIB_sqrAdd_exec_cn<float>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
331 
333 DSPLIB_sqrAdd_exec_cn<double>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
334 template DSPLIB_STATUS
335 DSPLIB_sqrAdd_exec_cn<int8_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
336 template DSPLIB_STATUS
337 DSPLIB_sqrAdd_exec_cn<uint8_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
338 template DSPLIB_STATUS
339 DSPLIB_sqrAdd_exec_cn<int16_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
340 template DSPLIB_STATUS
341 DSPLIB_sqrAdd_exec_cn<uint16_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
342 template DSPLIB_STATUS
343 DSPLIB_sqrAdd_exec_cn<int32_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
344 template DSPLIB_STATUS
345 DSPLIB_sqrAdd_exec_cn<uint32_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main execution function for the natural C implementation of the kernel....
DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_sqrAdd_exec_cn< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_sqrAdd.
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
Structure that is reserved for internal use by the kernel.
int32_t blockSize
Size of input buffer for different batches DSPLIB_sqrAdd_init that will be retrieved and used by DSPL...