DSPLIB User Guide
DSPLIB_blk_eswap_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_blk_eswap_priv.h"
30 
32  DSPLIB_bufParams1D_t *bufParamsIn,
33  DSPLIB_bufParams1D_t *bufParamsOut,
34  const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
35 {
37  return status;
38 }
39 
40 template <uint32_t implementationType>
41 inline void blk_eswap_compute(uint8_t *restrict srcPtr, uint8_t *restrict dstPtr, uint32_t blockSize);
42 
43 template <>
44 inline void blk_eswap_compute<DSPLIB_UINT16>(uint8_t *restrict srcPtr, uint8_t *restrict dstPtr, uint32_t blockSize)
45 {
46  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering template function for 16-bit data");
47 
48  uint8_t tempBuff[2];
49  for (uint32_t cntr = 0; cntr < blockSize; cntr++) {
50  tempBuff[0] = srcPtr[cntr * 2 + 1];
51  tempBuff[1] = srcPtr[cntr * 2 + 0];
52 
53  dstPtr[cntr * 2 + 0] = tempBuff[0];
54  dstPtr[cntr * 2 + 1] = tempBuff[1];
55  }
56  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Exiting template function for 16-bit data");
57 }
58 
59 template <>
60 inline void blk_eswap_compute<DSPLIB_UINT32>(uint8_t *restrict srcPtr, uint8_t *restrict dstPtr, uint32_t blockSize)
61 {
62  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering template function for 32-bit data");
63 
64  uint8_t tempBuff[4];
65  for (uint32_t cntr = 0; cntr < blockSize; cntr++) {
66  tempBuff[0] = srcPtr[cntr * 4 + 3];
67  tempBuff[1] = srcPtr[cntr * 4 + 2];
68  tempBuff[2] = srcPtr[cntr * 4 + 1];
69  tempBuff[3] = srcPtr[cntr * 4 + 0];
70 
71  dstPtr[cntr * 4 + 0] = tempBuff[0];
72  dstPtr[cntr * 4 + 1] = tempBuff[1];
73  dstPtr[cntr * 4 + 2] = tempBuff[2];
74  dstPtr[cntr * 4 + 3] = tempBuff[3];
75  }
76  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Exiting template function for 32-bit data");
77 }
78 
79 template <>
80 inline void blk_eswap_compute<DSPLIB_UINT64>(uint8_t *restrict srcPtr, uint8_t *restrict dstPtr, uint32_t blockSize)
81 {
82  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering template function for 64-bit data");
83 
84  uint8_t tempBuff[8];
85  for (uint32_t cntr = 0; cntr < blockSize; cntr++) {
86  tempBuff[0] = srcPtr[cntr * 8 + 7];
87  tempBuff[1] = srcPtr[cntr * 8 + 6];
88  tempBuff[2] = srcPtr[cntr * 8 + 5];
89  tempBuff[3] = srcPtr[cntr * 8 + 4];
90  tempBuff[4] = srcPtr[cntr * 8 + 3];
91  tempBuff[5] = srcPtr[cntr * 8 + 2];
92  tempBuff[6] = srcPtr[cntr * 8 + 1];
93  tempBuff[7] = srcPtr[cntr * 8 + 0];
94 
95  dstPtr[cntr * 8 + 0] = tempBuff[0];
96  dstPtr[cntr * 8 + 1] = tempBuff[1];
97  dstPtr[cntr * 8 + 2] = tempBuff[2];
98  dstPtr[cntr * 8 + 3] = tempBuff[3];
99  dstPtr[cntr * 8 + 4] = tempBuff[4];
100  dstPtr[cntr * 8 + 5] = tempBuff[5];
101  dstPtr[cntr * 8 + 6] = tempBuff[6];
102  dstPtr[cntr * 8 + 7] = tempBuff[7];
103  }
104  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Exiting template function for 64-bit data");
105 }
106 
107 template <typename dataType, uint32_t implementationType>
108 DSPLIB_STATUS DSPLIB_blk_eswap_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
109 {
110  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
111 
112  DSPLIB_STATUS status = DSPLIB_SUCCESS;
113 
114  DSPLIB_blk_eswap_PrivArgs *pKerPrivArgs = (DSPLIB_blk_eswap_PrivArgs *) handle;
115  uint32_t blockSize = pKerPrivArgs->blockSize;
116 
117  uint8_t *srcPtr = (uint8_t *) pIn;
118  uint8_t *dstPtr = (uint8_t *) pOut;
119  if (!dstPtr) {
120  dstPtr = srcPtr; /* In-place swaping */
121  }
122 
123  DSPLIB_DEBUGPRINTFN(0, "srcPtr: %p dstPtr: %p blockSize: %d\n", srcPtr, dstPtr, blockSize);
124 
125  blk_eswap_compute<implementationType>(srcPtr, dstPtr, blockSize);
126 
127  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
128 
129  return status;
130 }
131 
132 // explicit instantiation for the different data type versions
133 
135 DSPLIB_blk_eswap_exec_cn<uint16_t, DSPLIB_UINT16>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
136 
138 DSPLIB_blk_eswap_exec_cn<uint32_t, DSPLIB_UINT32>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
140 DSPLIB_blk_eswap_exec_cn<uint64_t, DSPLIB_UINT64>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
141 
143 DSPLIB_blk_eswap_exec_cn<int16_t, DSPLIB_UINT16>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
144 
146 DSPLIB_blk_eswap_exec_cn<int32_t, DSPLIB_UINT32>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
148 DSPLIB_blk_eswap_exec_cn<int64_t, DSPLIB_UINT64>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
150 DSPLIB_blk_eswap_exec_cn<float, DSPLIB_UINT32>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
151 
153 DSPLIB_blk_eswap_exec_cn<double, DSPLIB_UINT64>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_cn< float, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
void blk_eswap_compute< DSPLIB_UINT16 >(uint8_t *restrict srcPtr, uint8_t *restrict dstPtr, uint32_t blockSize)
DSPLIB_STATUS DSPLIB_blk_eswap_init_cn(DSPLIB_kernelHandle handle, DSPLIB_bufParams1D_t *bufParamsIn, DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_blk_eswap_InitArgs *pKerInitArgs)
This function is the initialization function for the natural C implementation of the kernel....
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_cn< int32_t, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_cn< uint32_t, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_cn< uint16_t, DSPLIB_UINT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_cn< uint64_t, DSPLIB_UINT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
void blk_eswap_compute< DSPLIB_UINT32 >(uint8_t *restrict srcPtr, uint8_t *restrict dstPtr, uint32_t blockSize)
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_cn< int64_t, DSPLIB_UINT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
void blk_eswap_compute< DSPLIB_UINT64 >(uint8_t *restrict srcPtr, uint8_t *restrict dstPtr, uint32_t blockSize)
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_cn< int16_t, DSPLIB_UINT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
void blk_eswap_compute(uint8_t *restrict srcPtr, uint8_t *restrict dstPtr, uint32_t blockSize)
DSPLIB_STATUS DSPLIB_blk_eswap_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....
template DSPLIB_STATUS DSPLIB_blk_eswap_exec_cn< double, DSPLIB_UINT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
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.
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.