DSPLIB User Guide
DSPLIB_negate_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  *
39  * INCLUDES
40  *
41  ******************************************************************************/
42 
43 #include "../common/c71/DSPLIB_inlines.h"
44 #include "DSPLIB_negate_priv.h"
45 #include <cstdint>
46 #include <float.h>
47 
48 template <typename dataType>
50  const DSPLIB_bufParams1D_t *bufParamsIn,
51  const DSPLIB_bufParams1D_t *bufParamsOut,
52  const DSPLIB_negate_InitArgs *pKerInitArgs)
53 {
55  DSPLIB_negate_PrivArgs *pKerPrivArgs = (DSPLIB_negate_PrivArgs *) handle;
56  uint32_t blockSize = pKerPrivArgs->blockSize;
57 
58  __SE_TEMPLATE_v1 se0Params;
59  __SA_TEMPLATE_v1 sa0Params;
60 
61  __SE_ELETYPE SE_ELETYPE;
62  __SE_VECLEN SE_VECLEN;
63  __SA_VECLEN SA_VECLEN;
64 
65  uint8_t *pBlock = pKerPrivArgs->bufPblock;
66 
67  typedef typename c7x::make_full_vector<dataType>::type vec;
68  SE_VECLEN = c7x::se_veclen<vec>::value;
69  SA_VECLEN = c7x::sa_veclen<vec>::value;
70  SE_ELETYPE = c7x::se_eletype<vec>::value;
71 
72 #if DSPLIB_DEBUGPRINT
73  int32_t eleCount = c7x::element_count_of<vec>::value;
74  printf("Enter eleCount %d\n", eleCount);
75 #endif
76 
77  /**********************************************************************/
78  /* Prepare streaming engine 0 to fetch the input */
79  /**********************************************************************/
80 
81  se0Params = __gen_SE_TEMPLATE_v1();
82 
83  se0Params.ICNT0 = blockSize;
84  se0Params.VECLEN = SE_VECLEN;
85  se0Params.ELETYPE = SE_ELETYPE;
86  se0Params.DIMFMT = __SE_DIMFMT_1D;
87 
88  /**********************************************************************/
89  /* Prepare SA template to store output */
90  /**********************************************************************/
91  sa0Params = __gen_SA_TEMPLATE_v1();
92 
93  sa0Params.ICNT0 = blockSize;
94  sa0Params.DIM1 = blockSize;
95  sa0Params.VECLEN = SA_VECLEN;
96  sa0Params.DIMFMT = __SA_DIMFMT_1D;
97 
98  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET) = se0Params;
99  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET) = sa0Params;
100 
101  return status;
102 }
103 
105  const DSPLIB_bufParams1D_t *bufParamsIn,
106  const DSPLIB_bufParams1D_t *bufParamsOut,
107  const DSPLIB_negate_InitArgs *pKerInitArgs);
108 
110  const DSPLIB_bufParams1D_t *bufParamsIn,
111  const DSPLIB_bufParams1D_t *bufParamsOut,
112  const DSPLIB_negate_InitArgs *pKerInitArgs);
113 
115  const DSPLIB_bufParams1D_t *bufParamsIn,
116  const DSPLIB_bufParams1D_t *bufParamsOut,
117  const DSPLIB_negate_InitArgs *pKerInitArgs);
118 
119 template <typename dataType, int32_t dataIn>
120 DSPLIB_STATUS DSPLIB_negate_exec_ci(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
121 {
122  DSPLIB_negate_PrivArgs *pKerPrivArgs = (DSPLIB_negate_PrivArgs *) handle;
123  uint32_t blockSize = pKerPrivArgs->blockSize;
124 
125  __SE_TEMPLATE_v1 se0Params;
126  __SA_TEMPLATE_v1 sa0Params;
127 
128  dataType *restrict pInLocal = (dataType *) pIn;
129  dataType *restrict pOutLocal = (dataType *) pOut;
130 
131 #if DSPLIB_DEBUGPRINT
132  printf("Enter DSPLIB_negate_exec_ci\n");
133 #endif
134 
135  typedef typename c7x::make_full_vector<dataType>::type vec;
136  int32_t eleCount = c7x::element_count_of<vec>::value;
137 
138  uint8_t *pBlock = pKerPrivArgs->bufPblock;
139 
140  se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET);
141  sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET);
142  // Input samples
143  __SE0_OPEN(pInLocal, se0Params);
144 
145  // Output samples
146  __SA0_OPEN(sa0Params);
147 
148  vec zero = (vec) 0;
149 
150  for (int32_t counter = 0; counter < blockSize; counter += eleCount) {
151 
152  vec a = c7x::strm_eng<0, vec>::get_adv();
153  /* printf("\ninput: \n"); */
154  /* a.print(); */
155  vec out = __sub_sat(zero, a);
156  /* printf("\noutput: \n"); */
157  /* out.print(); */
158  /* vec out = -a; */
159  __vpred tmp = c7x::strm_agen<0, vec>::get_vpred();
160  vec *VB1 = c7x::strm_agen<0, vec>::get_adv(pOutLocal);
161 
162  __vstore_pred(tmp, VB1, out);
163  }
164 
165  __SE0_CLOSE();
166  __SA0_CLOSE();
167 
168  return DSPLIB_SUCCESS;
169 }
170 
172 DSPLIB_negate_exec_ci<int32_t, DSPLIB_INT32>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
173 
175 DSPLIB_negate_exec_ci<int16_t, DSPLIB_INT16>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
176 
178 DSPLIB_negate_exec_ci<int8_t, DSPLIB_INT8>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
#define SE_SE0_PARAM_OFFSET
#define SE_SA0_PARAM_OFFSET
template DSPLIB_STATUS DSPLIB_negate_exec_ci< int16_t, DSPLIB_INT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_negate_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_negate_exec_ci< int32_t, DSPLIB_INT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_negate_exec_ci< int8_t, DSPLIB_INT8 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_negate_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_negate_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_negate_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_negate_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_negate_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_negate_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_negate_init_ci(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_negate_InitArgs *pKerInitArgs)
This function is the initialization function for the C7x implementation of the kernel....
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_negate.
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.
int32_t blockSize
Size of input buffer for different batches DSPLIB_negate_init that will be retrieved and used by DSPL...
uint8_t bufPblock[DSPLIB_NEGATE_IXX_IXX_OXX_PBLOCK_SIZE]