DSPLIB User Guide
DSPLIB_blk_eswap_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 #include "DSPLIB_blk_eswap_priv.h"
47 
48 #if __C7X_VEC_SIZE_BITS__ == 256
49 uchar32 vMask16 = uchar32(1,
50  0,
51  3,
52  2,
53  5,
54  4,
55  7,
56  6,
57  9,
58  8,
59  11,
60  10,
61  13,
62  12,
63  15,
64  14,
65  17,
66  16,
67  19,
68  18,
69  21,
70  20,
71  23,
72  22,
73  25,
74  24,
75  27,
76  26,
77  29,
78  28,
79  31,
80  30);
81 uchar32 vMask32 = uchar32(3,
82  2,
83  1,
84  0,
85  7,
86  6,
87  5,
88  4,
89  11,
90  10,
91  9,
92  8,
93  15,
94  14,
95  13,
96  12,
97  19,
98  18,
99  17,
100  16,
101  23,
102  22,
103  21,
104  20,
105  27,
106  26,
107  25,
108  24,
109  31,
110  30,
111  29,
112  28);
113 uchar32 vMask64 = uchar32(7,
114  6,
115  5,
116  4,
117  3,
118  2,
119  1,
120  0,
121  15,
122  14,
123  13,
124  12,
125  11,
126  10,
127  9,
128  8,
129  23,
130  22,
131  21,
132  20,
133  19,
134  18,
135  17,
136  16,
137  31,
138  30,
139  29,
140  28,
141  27,
142  26,
143  25,
144  24);
145 #elif __C7X_VEC_SIZE_BITS__ == 512
146 uchar64 vMask16 = uchar64(1,
147  0,
148  3,
149  2,
150  5,
151  4,
152  7,
153  6,
154  9,
155  8,
156  11,
157  10,
158  13,
159  12,
160  15,
161  14,
162  17,
163  16,
164  19,
165  18,
166  21,
167  20,
168  23,
169  22,
170  25,
171  24,
172  27,
173  26,
174  29,
175  28,
176  31,
177  30,
178  33,
179  32,
180  35,
181  34,
182  37,
183  36,
184  39,
185  38,
186  41,
187  40,
188  43,
189  42,
190  45,
191  44,
192  47,
193  46,
194  49,
195  48,
196  51,
197  50,
198  53,
199  52,
200  55,
201  54,
202  57,
203  56,
204  59,
205  58,
206  61,
207  60,
208  63,
209  62);
210 uchar64 vMask32 = uchar64(3,
211  2,
212  1,
213  0,
214  7,
215  6,
216  5,
217  4,
218  11,
219  10,
220  9,
221  8,
222  15,
223  14,
224  13,
225  12,
226  19,
227  18,
228  17,
229  16,
230  23,
231  22,
232  21,
233  20,
234  27,
235  26,
236  25,
237  24,
238  31,
239  30,
240  29,
241  28,
242  35,
243  34,
244  33,
245  32,
246  39,
247  38,
248  37,
249  36,
250  43,
251  42,
252  41,
253  40,
254  47,
255  46,
256  45,
257  44,
258  51,
259  50,
260  49,
261  48,
262  55,
263  54,
264  53,
265  52,
266  59,
267  58,
268  57,
269  56,
270  63,
271  62,
272  61,
273  60);
274 
275 uchar64 vMask64 = uchar64(7,
276  6,
277  5,
278  4,
279  3,
280  2,
281  1,
282  0,
283  15,
284  14,
285  13,
286  12,
287  11,
288  10,
289  9,
290  8,
291  23,
292  22,
293  21,
294  20,
295  19,
296  18,
297  17,
298  16,
299  31,
300  30,
301  29,
302  28,
303  27,
304  26,
305  25,
306  24,
307  39,
308  38,
309  37,
310  36,
311  35,
312  34,
313  33,
314  32,
315  47,
316  46,
317  45,
318  44,
319  43,
320  42,
321  41,
322  40,
323  55,
324  54,
325  53,
326  52,
327  51,
328  50,
329  49,
330  48,
331  63,
332  62,
333  61,
334  60,
335  59,
336  58,
337  57,
338  56);
339 #endif
340 
341 // Define the mask template
342 template <uint32_t maskType> inline c7x::uchar_vec blk_eswap_mask();
343 
344 template <> inline c7x::uchar_vec blk_eswap_mask<DSPLIB_UINT16>() { return vMask16; }
345 
346 template <> inline c7x::uchar_vec blk_eswap_mask<DSPLIB_UINT32>() { return vMask32; }
347 
348 template <> inline c7x::uchar_vec blk_eswap_mask<DSPLIB_UINT64>() { return vMask64; }
349 
350 template <typename dataType>
352  const DSPLIB_bufParams1D_t *bufParamsIn,
353  const DSPLIB_bufParams1D_t *bufParamsOut,
354  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
355 {
356 
357  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
358 
359  DSPLIB_STATUS status = DSPLIB_SUCCESS;
360  DSPLIB_blk_eswap_PrivArgs *pKerPrivArgs = (DSPLIB_blk_eswap_PrivArgs *) handle;
361  uint32_t blockSize = pKerPrivArgs->blockSize;
362 
363  typedef typename c7x::make_full_vector<dataType>::type vec;
364 
365  uint8_t *pBlock = pKerPrivArgs->bufPblock;
366  __SE_VECLEN SE_VECLEN = c7x::se_veclen<vec>::value;
367  __SA_VECLEN SA_VECLEN = c7x::sa_veclen<vec>::value;
368  __SE_ELETYPE SE_ELETYPE = c7x::se_eletype<vec>::value;
369 
370  __SE_TEMPLATE_v1 se0Params = __gen_SE_TEMPLATE_v1();
371  se0Params.DIMFMT = __SE_DIMFMT_1D;
372  se0Params.ELETYPE = SE_ELETYPE;
373  se0Params.VECLEN = SE_VECLEN;
374  se0Params.ICNT0 = blockSize;
375 
376  __SA_TEMPLATE_v1 sa0Params = __gen_SA_TEMPLATE_v1();
377  sa0Params.DIMFMT = __SA_DIMFMT_1D;
378  sa0Params.VECLEN = SA_VECLEN;
379  sa0Params.ICNT0 = blockSize;
380 
381  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET) = se0Params;
382  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET) = sa0Params;
383 
384  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
385 
386  return status;
387 }
388 
390  const DSPLIB_bufParams1D_t *bufParamsIn,
391  const DSPLIB_bufParams1D_t *bufParamsOut,
392  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs);
393 
395  const DSPLIB_bufParams1D_t *bufParamsIn,
396  const DSPLIB_bufParams1D_t *bufParamsOut,
397  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs);
399  const DSPLIB_bufParams1D_t *bufParamsIn,
400  const DSPLIB_bufParams1D_t *bufParamsOut,
401  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs);
402 
404  const DSPLIB_bufParams1D_t *bufParamsIn,
405  const DSPLIB_bufParams1D_t *bufParamsOut,
406  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs);
407 
409  const DSPLIB_bufParams1D_t *bufParamsIn,
410  const DSPLIB_bufParams1D_t *bufParamsOut,
411  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs);
413  const DSPLIB_bufParams1D_t *bufParamsIn,
414  const DSPLIB_bufParams1D_t *bufParamsOut,
415  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs);
416 
418  const DSPLIB_bufParams1D_t *bufParamsIn,
419  const DSPLIB_bufParams1D_t *bufParamsOut,
420  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs);
422  const DSPLIB_bufParams1D_t *bufParamsIn,
423  const DSPLIB_bufParams1D_t *bufParamsOut,
424  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs);
425 
426 template <typename dataType, uint32_t maskType>
427 DSPLIB_STATUS DSPLIB_blk_eswap_exec_ci(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
428 {
429  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
430 
431  DSPLIB_STATUS status = DSPLIB_SUCCESS;
432  DSPLIB_blk_eswap_PrivArgs *pKerPrivArgs = (DSPLIB_blk_eswap_PrivArgs *) handle;
433  uint32_t blockSize = pKerPrivArgs->blockSize;
434  uint32_t cntr;
435  typedef typename c7x::make_full_vector<dataType>::type vec;
436  uint32_t eleCount = c7x::element_count_of<vec>::value;
437  __SE_TEMPLATE_v1 se0Params;
438  __SA_TEMPLATE_v1 sa0Params;
439 
440  dataType *srcPtr = (dataType *) pIn;
441  dataType *dstPtr = (dataType *) pOut;
442  if (!dstPtr) {
443  DSPLIB_DEBUGPRINTFN(0, "%s\n", "In-place swapping Enabled");
444  dstPtr = srcPtr; /* In-place swaping */
445  }
446 
447  DSPLIB_DEBUGPRINTFN(0, "srcPtr: %p dstPtr: %p blockSize: %d\n", srcPtr, dstPtr, blockSize);
448 
449  uint8_t *pBlock = pKerPrivArgs->bufPblock;
450 
451  se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET);
452  sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET);
453 
454  __SE0_OPEN(srcPtr, se0Params);
455  __SA0_OPEN(sa0Params);
456 
457  c7x::uchar_vec vMask = blk_eswap_mask<maskType>();
458  for (cntr = 0; cntr < blockSize; cntr += eleCount) {
459  vec inpBlock = c7x::strm_eng<0, vec>::get_adv();
460  vec swappedBlock = c7x::reinterpret<vec>(__permute(vMask, c7x::as_uchar_vec(inpBlock)));
461  __vpred vpStore = c7x::strm_agen<0, vec>::get_vpred();
462  vec *outVecPtr = c7x::strm_agen<0, vec>::get_adv(dstPtr);
463  __vstore_pred(vpStore, outVecPtr, swappedBlock);
464  }
465 
466  __SE0_CLOSE();
467  __SA0_CLOSE();
468 
469  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", DSPLIB_SUCCESS);
470 
471  return (status);
472 }
473 
475 DSPLIB_blk_eswap_exec_ci<uint16_t, DSPLIB_UINT16>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
476 
478 DSPLIB_blk_eswap_exec_ci<uint32_t, DSPLIB_UINT32>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
479 
481 DSPLIB_blk_eswap_exec_ci<uint64_t, DSPLIB_UINT64>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
483 DSPLIB_blk_eswap_exec_ci<int16_t, DSPLIB_UINT16>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
484 
486 DSPLIB_blk_eswap_exec_ci<int32_t, DSPLIB_UINT32>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
487 
489 DSPLIB_blk_eswap_exec_ci<int64_t, DSPLIB_UINT64>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
490 
492 DSPLIB_blk_eswap_exec_ci<float, DSPLIB_UINT32>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
493 
495 DSPLIB_blk_eswap_exec_ci<double, DSPLIB_UINT64>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
#define SE_SE0_PARAM_OFFSET
#define SE_SA0_PARAM_OFFSET
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_ci< int64_t, DSPLIB_UINT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_blk_eswap_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_ci< uint16_t, DSPLIB_UINT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
c7x::uchar_vec blk_eswap_mask< DSPLIB_UINT16 >()
template DSPLIB_STATUS DSPLIB_blk_eswap_init_ci< uint32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_ci< double, DSPLIB_UINT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_blk_eswap_init_ci< uint16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_blk_eswap_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_blk_eswap_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_blk_eswap_init_ci< uint64_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_ci< int32_t, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
c7x::uchar_vec blk_eswap_mask< DSPLIB_UINT64 >()
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_ci< uint32_t, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
c7x::uchar_vec blk_eswap_mask< DSPLIB_UINT32 >()
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_ci< int16_t, DSPLIB_UINT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_blk_eswap_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_ci< float, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_blk_eswap_init_ci(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
This function is the initialization function for the C7x implementation of the kernel....
template DSPLIB_STATUS DSPLIB_blk_eswap_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
c7x::uchar_vec blk_eswap_mask()
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_ci< uint64_t, DSPLIB_UINT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_blk_eswap_init_ci< int64_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_blk_eswap.
#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
Structure containing the parameters to initialize the kernel.
Structure that is reserved for internal use by the kernel.
uint8_t bufPblock[DSPLIB_BLK_ESWAP_IXX_IXX_OXX_PBLOCK_SIZE]
Buffer to save SE & SA configuration parameters
int32_t blockSize
Size of input buffer for different batches DSPLIB_blk_eswap_init that will be retrieved and used by D...
A structure for a 1 dimensional buffer descriptor.