DSPLIB User Guide
DSPLIB_bexp.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * *
3  * module name : DSPLIB bexp *
4  * *
5  * module descripton : Finds the minimum left shift for integer typed input *
6  * array such that the information in the input array is *
7  * preserved upto a scale factor. For signed numbers the *
8  * most negative value - 1 is considered for calculating *
9  * this left shift. *
10  * *
11  * Copyright (c) 2023 Texas Instruments Incorporated - https://www.ti.com/ *
12  * ALL RIGHTS RESERVED *
13  * *
14  ******************************************************************************/
15 
27 #include "DSPLIB_bexp_priv.h"
28 
30 {
31  int32_t privBufSize = sizeof(DSPLIB_bexp_PrivArgs);
32  return privBufSize;
33 }
34 
36  const DSPLIB_bufParams1D_t *bufParamsIn,
37  const DSPLIB_bufParams1D_t *bufParamsOut,
38  const DSPLIB_bexp_InitArgs *pKerInitArgs)
39 {
41 
42  DSPLIB_DEBUGPRINTFN(0, "%s", "Enter DSPLIB_bexp_init_checkParams\n");
43 
44  if (handle == NULL) {
45  status = DSPLIB_ERR_NULL_POINTER;
46  }
47 
48  if (status == DSPLIB_SUCCESS) {
49  if ((bufParamsIn->data_type != DSPLIB_INT8) && (bufParamsIn->data_type != DSPLIB_INT16) &&
50  (bufParamsIn->data_type != DSPLIB_INT32) && (bufParamsIn->data_type != DSPLIB_INT64) &&
51  (bufParamsIn->data_type != DSPLIB_UINT8) && (bufParamsIn->data_type != DSPLIB_UINT16) &&
52  (bufParamsIn->data_type != DSPLIB_UINT32) && (bufParamsIn->data_type != DSPLIB_UINT64)) {
53  DSPLIB_DEBUGPRINTFN(0, "%s", "bufParamsIn->data_type is not int type\n");
54  status = DSPLIB_ERR_INVALID_TYPE;
55  }
56  else if ((bufParamsOut->data_type != DSPLIB_INT32)) {
57  DSPLIB_DEBUGPRINTFN(0, "%s", "bufParamsOut->data_type is not DSPLIB_INT32\n");
58  status = DSPLIB_ERR_INVALID_TYPE;
59  }
60  else {
61  /* Nothing to do here */
62  }
63  }
64 
65  DSPLIB_DEBUGPRINTFN(0, "Exit with status: %d\n", status);
66  return status;
67 }
68 
70 DSPLIB_bexp_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
71 {
72  DSPLIB_STATUS status;
73 
74  DSPLIB_DEBUGPRINTFN(0, "%s", "Enter DSPLIB_bexp_exec_checkParams\n");
75  if ((pIn == NULL) || (pOut == NULL)) {
76  status = DSPLIB_ERR_NULL_POINTER;
77  }
78  else {
79  status = DSPLIB_SUCCESS;
80  }
81 
82  DSPLIB_DEBUGPRINTFN(0, "Exit with status: %d\n", status);
83  return status;
84 }
85 
87  DSPLIB_bufParams1D_t *bufParamsIn,
88  DSPLIB_bufParams1D_t *bufParamsOut,
89  const DSPLIB_bexp_InitArgs *pKerInitArgs)
90 {
92  DSPLIB_bexp_PrivArgs *pKerPrivArgs = (DSPLIB_bexp_PrivArgs *) handle;
93 
94  pKerPrivArgs->blockSize = pKerInitArgs->dataSize;
95 
96  DSPLIB_DEBUGPRINTFN(0, "pKerPrivArgs->blockSize %d bufParamsIn->data_type %d\n",
97  pKerPrivArgs->blockSize, bufParamsIn->data_type);
98 
99  if (pKerInitArgs->funcStyle == DSPLIB_FUNCTION_NATC) {
100  if (bufParamsIn->data_type == DSPLIB_INT8) {
101  pKerPrivArgs->execute = DSPLIB_bexp_exec_cn<int8_t>;
102  }
103  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
104  pKerPrivArgs->execute = DSPLIB_bexp_exec_cn<uint8_t>;
105  }
106  else if (bufParamsIn->data_type == DSPLIB_INT16) {
107  pKerPrivArgs->execute = DSPLIB_bexp_exec_cn<int16_t>;
108  }
109  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
110  pKerPrivArgs->execute = DSPLIB_bexp_exec_cn<uint16_t>;
111  }
112  else if (bufParamsIn->data_type == DSPLIB_INT32) {
113  pKerPrivArgs->execute = DSPLIB_bexp_exec_cn<int32_t>;
114  }
115  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
116  pKerPrivArgs->execute = DSPLIB_bexp_exec_cn<uint32_t>;
117  }
118  else if (bufParamsIn->data_type == DSPLIB_INT64) {
119  pKerPrivArgs->execute = DSPLIB_bexp_exec_cn<int64_t>;
120  }
121  else if (bufParamsIn->data_type == DSPLIB_UINT64) {
122  pKerPrivArgs->execute = DSPLIB_bexp_exec_cn<uint64_t>;
123  }
124  else {
125  status = DSPLIB_ERR_INVALID_TYPE;
126  DSPLIB_DEBUGPRINTFN(0, "DSPLIB_DEBUGPRINT CP 2 status %d\n", status);
127  }
128  }
129  else {
130  if (bufParamsIn->data_type == DSPLIB_INT8) {
131  pKerPrivArgs->execute = DSPLIB_bexp_exec_ci<int8_t>;
132  status = DSPLIB_bexp_init_ci<int8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
133  }
134  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
135  pKerPrivArgs->execute = DSPLIB_bexp_exec_ci<uint8_t>;
136  status = DSPLIB_bexp_init_ci<uint8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
137  }
138  else if (bufParamsIn->data_type == DSPLIB_INT16) {
139  pKerPrivArgs->execute = DSPLIB_bexp_exec_ci<int16_t>;
140  status = DSPLIB_bexp_init_ci<int16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
141  }
142  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
143  pKerPrivArgs->execute = DSPLIB_bexp_exec_ci<uint16_t>;
144  status = DSPLIB_bexp_init_ci<uint16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
145  }
146  else if (bufParamsIn->data_type == DSPLIB_INT32) {
147  pKerPrivArgs->execute = DSPLIB_bexp_exec_ci<int32_t>;
148  status = DSPLIB_bexp_init_ci<int32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
149  }
150  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
151  pKerPrivArgs->execute = DSPLIB_bexp_exec_ci<uint32_t>;
152  status = DSPLIB_bexp_init_ci<uint32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
153  }
154  else if (bufParamsIn->data_type == DSPLIB_INT64) {
155  pKerPrivArgs->execute = DSPLIB_bexp_exec_ci<int64_t>;
156  status = DSPLIB_bexp_init_ci<int64_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
157  }
158  else if (bufParamsIn->data_type == DSPLIB_UINT64) {
159  pKerPrivArgs->execute = DSPLIB_bexp_exec_ci<uint64_t>;
160  status = DSPLIB_bexp_init_ci<uint64_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
161  }
162  else {
163  status = DSPLIB_ERR_INVALID_TYPE;
164  }
165  }
166  DSPLIB_DEBUGPRINTFN(0, "Exit with status: %d\n", status);
167  return status;
168 }
169 
170 DSPLIB_STATUS DSPLIB_bexp_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
171 {
172  DSPLIB_DEBUGPRINTFN(0, "%s", "Entering function\n");
173  DSPLIB_STATUS status;
174 
175  DSPLIB_bexp_PrivArgs *pKerPrivArgs = (DSPLIB_bexp_PrivArgs *) handle;
176 
177  DSPLIB_DEBUGPRINTFN(0, "pKerPrivArgs->blockSize %d\n", pKerPrivArgs->blockSize);
178  status = pKerPrivArgs->execute(handle, pIn, pOut);
179 
180  DSPLIB_DEBUGPRINTFN(0, "Exit with status: %d\n", status);
181  return status;
182 }
template DSPLIB_STATUS DSPLIB_bexp_init_ci< uint32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_bexp_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_bexp_exec_ci< uint64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_bexp_exec_ci< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_bexp_exec_ci< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_init_ci< uint16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_bexp_init_ci< uint64_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_bexp_exec_ci< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_bexp_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_bexp_init_ci< uint8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_bexp_exec_ci< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_bexp_exec_ci< int64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_bexp_exec_ci< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_init_ci< int64_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_bexp_exec_ci< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_exec_cn< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_exec_cn< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_exec_cn< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_exec_cn< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_exec_cn< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_exec_cn< uint64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_exec_cn< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_bexp_exec_cn< int64_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_bexp.
#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_FUNCTION_NATC
Definition: DSPLIB_types.h:176
@ DSPLIB_UINT64
@ DSPLIB_UINT8
@ DSPLIB_UINT16
@ DSPLIB_INT32
@ DSPLIB_INT16
@ DSPLIB_INT64
@ DSPLIB_UINT32
@ DSPLIB_INT8
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152
@ DSPLIB_ERR_NULL_POINTER
Definition: DSPLIB_types.h:157
@ DSPLIB_ERR_INVALID_TYPE
Definition: DSPLIB_types.h:155
DSPLIB_STATUS DSPLIB_bexp_init_checkParams(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to DSPLIB_bexp_init function....
Definition: DSPLIB_bexp.cpp:35
int32_t DSPLIB_bexp_getHandleSize(DSPLIB_bexp_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
Definition: DSPLIB_bexp.cpp:29
DSPLIB_STATUS DSPLIB_bexp_init(DSPLIB_kernelHandle handle, DSPLIB_bufParams1D_t *bufParamsIn, DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_bexp_InitArgs *pKerInitArgs)
This function should be called before the DSPLIB_bexp_exec function is called. This function takes ca...
Definition: DSPLIB_bexp.cpp:86
DSPLIB_STATUS DSPLIB_bexp_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
This function checks the validity of the parameters passed to DSPLIB_bexp_exec function....
Definition: DSPLIB_bexp.cpp:70
DSPLIB_STATUS DSPLIB_bexp_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main kernel compute function.
Structure containing the parameters to initialize the kernel.
Definition: DSPLIB_bexp.h:112
int8_t funcStyle
Variant of the function refer to DSPLIB_FUNCTION_STYLE
Definition: DSPLIB_bexp.h:114
uint32_t dataSize
Size of input data
Definition: DSPLIB_bexp.h:116
Structure that is reserved for internal use by the kernel.
pFxnDSPLIB_bexp_exec execute
Function pointer to point to the right execution variant between DSPLIB_bexp_exec_cn and DSPLIB_bexp_...
uint32_t blockSize
Size of input buffer for different batches DSPLIB_bexp_init that will be retrieved and used by DSPLIB...
A structure for a 1 dimensional buffer descriptor.
uint32_t data_type
Values are of type DSPLIB_data_type_e.