DSPLIB User Guide
DSPLIB_bexp_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_bexp_priv.h"
30 
35 template <typename dataType>
36 DSPLIB_STATUS DSPLIB_bexp_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
37 {
39 
40  DSPLIB_bexp_PrivArgs *pKerPrivArgs = (DSPLIB_bexp_PrivArgs *) handle;
41  uint32_t blockSize = pKerPrivArgs->blockSize;
42 
43  DSPLIB_DEBUGPRINTFN(0, "%s", "Entering function\n");
44 
45  // casting pOutLocal as int32_t since the data type
46  // of the output remains same regardless of the input data type
47  dataType *pInLocal = (dataType *) pIn;
48  int32_t *pOutLocal = (int32_t *) pOut;
49 
50  DSPLIB_DEBUGPRINTFN(0, "Enter pInLocal %p pOut %p\n", pInLocal, pOut);
51 
52  dataType x;
53 
54  using udataType = std::make_unsigned_t<dataType>;
55  udataType mask = 0;
56  int num_bits = sizeof(dataType) * 8;
57  int shift;
58 
59  // Handling signed and unsigned data types differently
60  if (std::numeric_limits<dataType>::is_signed) {
61  for (int32_t counter = 0; counter < (int32_t) blockSize; counter++) {
62  x = *pInLocal++;
63  if (x < 0) {
64  udataType x_abs;
65  // Handling min value separately. For example -128 in case of int8
66  if (x == (dataType) (1u << (uint32_t)(num_bits - 1))) {
67  x += 1;
68  }
69  // Taking the absolute value and doing an OR operation
70  x_abs = (udataType) (-(long long) x);
71  mask |= x_abs;
72  }
73  // For positive values, OR operation can be done with the original values itself
74  else {
75  mask |= x;
76  }
77  }
78  // Checking the least power of two that is larger than the overall mask value
79  for (shift = num_bits - 1; shift >= 0; shift--) {
80  if (((udataType) 1 << (udataType)shift) & mask){
81  break;
82  }
83  }
84 
85  // For signed values, we need an extra - 1 since the MSBit is ignored
86  *pOutLocal = (int32_t) (num_bits - 1 - shift - 1);
87  }
88  else {
89  for (int32_t counter = 0; counter < (int32_t) blockSize; counter++) {
90  x = *pInLocal++;
91  mask |= x;
92  }
93  for (shift = num_bits - 1; shift >= 0; shift--) {
94  if (((udataType) 1 << (udataType)shift) & mask){
95  break;
96  }
97  }
98 
99  *pOutLocal = (int32_t) (num_bits - 1 - shift);
100  }
101 
102  DSPLIB_DEBUGPRINTFN(0, "Exit with status: %d\n", status);
103  return (status);
104 }
105 
106 template DSPLIB_STATUS DSPLIB_bexp_exec_cn<int8_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
108 DSPLIB_bexp_exec_cn<uint8_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
110 DSPLIB_bexp_exec_cn<int16_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
112 DSPLIB_bexp_exec_cn<uint16_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
114 DSPLIB_bexp_exec_cn<int32_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
116 DSPLIB_bexp_exec_cn<uint32_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
118 DSPLIB_bexp_exec_cn<int64_t>(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut);
120 DSPLIB_bexp_exec_cn<uint64_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)
DSPLIB_STATUS DSPLIB_bexp_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_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_SUCCESS
Definition: DSPLIB_types.h:152
Structure that is reserved for internal use by the kernel.
uint32_t blockSize
Size of input buffer for different batches DSPLIB_bexp_init that will be retrieved and used by DSPLIB...