47 #include "../common/c71/DSPLIB_inlines.h"
55 #define DSPLIB_CASCADEBIQUAD_IMPLEMENTED 0
57 template <
typename dataType>
66 __SE_TEMPLATE_v1 se0Params;
67 __SE_TEMPLATE_v1 se1Params;
68 __SA_TEMPLATE_v1 sa0Params;
69 __SA_TEMPLATE_v1 sa1Params;
72 uint8_t *pBlock = pKerPrivArgs->
bufPblock;
80 __SE_ELETYPE SE_ELETYPE;
81 __SE_VECLEN SE_VECLEN;
82 __SA_VECLEN SA_VECLEN;
84 typedef typename c7x::make_full_vector<dataType>::type vec;
85 SE_VECLEN = c7x::se_veclen<vec>::value;
86 SA_VECLEN = c7x::sa_veclen<vec>::value;
87 SE_ELETYPE = c7x::se_eletype<vec>::value;
89 uint32_t eleCount = c7x::element_count_of<vec>::value;
92 printf(
"DSPLIB_DEBUGPRINT SE_VECLEN: %d, SA_VECLEN: %d, SE_ELETYPE: %d "
93 "numChannels %d numStages %d\n",
94 SE_VECLEN, SA_VECLEN, SE_ELETYPE, numChannels, numStages);
95 printf(
"DSPLIB_DEBUGPRINT SE_VECLEN: %d, SA_VECLEN: %d, SE_ELETYPE: %d "
97 SE_VECLEN, SA_VECLEN, SE_ELETYPE, eleCount);
100 uint32_t icnt1Param = (numChannels > eleCount) ? eleCount : numChannels;
101 icnt1Param = (icnt1Param == 0) ? 1 : icnt1Param;
102 uint32_t icnt2Param =
103 (numChannels % eleCount == 0) ? (numChannels / eleCount) : (numChannels + eleCount) / eleCount;
108 se1Params = __gen_SE_TEMPLATE_v1();
110 se1Params.ICNT0 = icnt1Param;
111 se1Params.ICNT1 = dataSize;
112 se1Params.DIM1 = (int32_t) dataBufferInPitch;
113 se1Params.ICNT2 = icnt2Param;
114 se1Params.DIM2 = eleCount;
115 se1Params.ELETYPE = SE_ELETYPE;
116 se1Params.VECLEN = SE_VECLEN;
117 se1Params.DECDIM1_WIDTH = numChannels;
118 se1Params.DECDIM1 = __SE_DECDIM_DIM2;
119 se1Params.DIMFMT = __SE_DIMFMT_3D;
123 se0Params = __gen_SE_TEMPLATE_v1();
124 se0Params.ICNT0 = icnt1Param;
125 se0Params.ICNT1 = numStages * 2;
126 se0Params.DIM1 = (int32_t) filterVarPitch;
127 se0Params.ICNT2 = icnt2Param;
128 se0Params.DIM2 = eleCount;
129 se0Params.ELETYPE = SE_ELETYPE;
130 se0Params.VECLEN = SE_VECLEN;
131 se0Params.DECDIM1_WIDTH = numChannels;
132 se0Params.DECDIM1 = __SE_DECDIM_DIM2;
133 se0Params.DIMFMT = __SE_DIMFMT_3D;
138 sa0Params = __gen_SA_TEMPLATE_v1();
140 sa0Params.ICNT0 = icnt1Param;
141 sa0Params.ICNT1 = dataSize;
142 sa0Params.DIM1 = (int32_t) dataBufferOutPitch;
143 sa0Params.ICNT2 = icnt2Param;
144 sa0Params.DIM2 = eleCount;
145 sa0Params.DECDIM1_WIDTH = numChannels;
146 sa0Params.DECDIM1 = __SA_DECDIM_DIM2;
147 sa0Params.DECDIM2_WIDTH = dataBufferOutPitch * dataSize;
148 sa0Params.DECDIM2 = __SA_DECDIM_DIM2;
149 sa0Params.VECLEN = SA_VECLEN;
150 sa0Params.DIMFMT = __SA_DIMFMT_3D;
155 sa1Params = __gen_SA_TEMPLATE_v1();
157 sa1Params.ICNT0 = icnt1Param;
158 sa1Params.ICNT1 = numStages * 2;
159 sa1Params.DIM1 = (int32_t) filterVarPitch;
160 sa1Params.ICNT2 = icnt2Param;
161 sa1Params.DIM2 = eleCount;
162 sa1Params.DECDIM1_WIDTH = numChannels;
163 sa1Params.DECDIM1 = __SA_DECDIM_DIM2;
164 sa1Params.VECLEN = SA_VECLEN;
165 sa1Params.DIMFMT = __SA_DIMFMT_3D;
174 template <
typename dataType>
static inline dataType
fast_recip(dataType x)
176 typedef typename c7x::make_full_vector<dataType>::type vec;
183 vec out = f * (2 - a * f);
199 template <
typename dataType>
202 void *restrict pFilterCoeff,
203 void *restrict pFilterVar,
206 __SE_TEMPLATE_v1 se0Params;
207 __SE_TEMPLATE_v1 se1Params;
208 __SA_TEMPLATE_v1 sa0Params;
209 __SA_TEMPLATE_v1 sa1Params;
212 uint8_t *pBlock = pKerPrivArgs->
bufPblock;
217 dataType *pInLocal = (dataType *) pIn;
218 dataType *pFilterCoeffLocal = (dataType *) pFilterCoeff;
219 dataType *pFilterVarLocal = (dataType *) pFilterVar;
220 dataType *pOutLocal = (dataType *) pOut;
222 #if DSPLIB_DEBUGPRINT
223 printf(
"Enter DSPLIB_cascadeBiquad_exec_ci\n");
226 typedef typename c7x::make_full_vector<dataType>::type vec;
227 int eleCount = c7x::element_count_of<vec>::value;
232 #if DSPLIB_DEBUGPRINT
233 printf(
"Enter pFilter %p\n", pFilterCoeff);
238 __SE0_OPEN(pFilterVarLocal, se0Params);
242 __SE1_OPEN(pInLocal, se1Params);
246 __SA0_OPEN(sa0Params);
250 __SA1_OPEN(sa1Params);
252 #if DSPLIB_DEBUGPRINT
253 printf(
"DSPLIB_DEBUGPRINT dataSize %d numChannels %d numStages %d pOutLocal "
258 vec output1, output2, output3;
259 vec temp1_mul_1, temp0_mul_1, d0_temp_1, d1_mul_1;
260 vec temp1_mul_2, temp0_mul_2, d0_temp_2, d1_mul_2;
261 vec temp1_mul_3, temp0_mul_3, d0_temp_3, d1_mul_3;
262 vec temp1_add_1, temp1_add_2, temp1_add_3;
264 dataType coeff0 = pFilterCoeffLocal[0];
266 vec b10 = (vec) (coeff0);
267 vec r = (vec) (fast_recip<dataType>(coeff0));
268 vec b11 = pFilterCoeffLocal[1] * r;
269 vec b12 = pFilterCoeffLocal[2] * r;
270 vec a11 = (vec) (-1 * pFilterCoeffLocal[3]);
271 vec a12 = (vec) (-1 * pFilterCoeffLocal[4]);
273 vec b20, b21, b22, a21, a22;
275 #if DSPLIB_CASCADEBIQUAD_IMPLEMENTED
277 if (numStages >= 2) {
278 coeff0 = pFilterCoeffLocal[5];
279 b20 = (vec) (coeff0);
280 r = (vec) fast_recip<dataType>(coeff0);
281 b21 = pFilterCoeffLocal[6] * r;
282 b22 = pFilterCoeffLocal[7] * r;
283 a21 = -pFilterCoeffLocal[8];
284 a22 = -pFilterCoeffLocal[9];
296 coeff0 = pFilterCoeffLocal[5];
297 b20 = (vec) (coeff0);
298 r = (vec) fast_recip<dataType>(coeff0);
299 b21 = pFilterCoeffLocal[6] * r;
300 b22 = pFilterCoeffLocal[7] * r;
301 a21 = -pFilterCoeffLocal[8];
302 a22 = -pFilterCoeffLocal[9];
307 vec b30, b31, b32, a31, a32;
309 #if DSPLIB_CASCADEBIQUAD_IMPLEMENTED
312 if (numStages >= 3) {
313 coeff0 = pFilterCoeffLocal[10];
314 b30 = (vec) (coeff0);
315 r = (vec) fast_recip<dataType>(coeff0);
316 b31 = pFilterCoeffLocal[11] * r;
317 b32 = pFilterCoeffLocal[12] * r;
318 a31 = -pFilterCoeffLocal[13];
319 a32 = -pFilterCoeffLocal[14];
331 coeff0 = pFilterCoeffLocal[10];
332 b30 = (vec) (coeff0);
333 r = (vec) fast_recip<dataType>(coeff0);
334 b31 = pFilterCoeffLocal[11] * r;
335 b32 = pFilterCoeffLocal[12] * r;
336 a31 = -pFilterCoeffLocal[13];
337 a32 = -pFilterCoeffLocal[14];
343 vec outGain = b10 * b20 * b30;
345 vec b11_a11 = b11 + a11;
346 vec b12_a12 = b12 + a12;
347 vec b21_a21 = b21 + a21;
348 vec b22_a22 = b22 + a22;
349 vec b31_a31 = b31 + a31;
350 vec b32_a32 = b32 + a32;
352 #if DSPLIB_DEBUGPRINT
353 DSPLIB_debugPrintVector(outGain);
365 for (uint32_t chCount = 0; chCount < numChannels; chCount += eleCount) {
367 vec filtVars_d0_1 = c7x::strm_eng<0, vec>::get_adv();
368 vec filtVars_d1_1 = c7x::strm_eng<0, vec>::get_adv();
369 vec filtVars_d0_2 = c7x::strm_eng<0, vec>::get_adv();
370 vec filtVars_d1_2 = c7x::strm_eng<0, vec>::get_adv();
371 vec filtVars_d0_3 = c7x::strm_eng<0, vec>::get_adv();
372 vec filtVars_d1_3 = c7x::strm_eng<0, vec>::get_adv();
374 #if DSPLIB_DEBUGPRINT
382 for (uint32_t samp = 0; samp < dataSize; samp++) {
384 input = c7x::strm_eng<1, vec>::get();
385 #if DSPLIB_DEBUGPRINT
388 output1 = input + filtVars_d0_1;
389 temp1_mul_1 = input * b11_a11;
390 temp1_add_1 = temp1_mul_1 + filtVars_d1_1;
391 temp0_mul_1 = a12 * filtVars_d0_1;
392 d0_temp_1 = a11 * filtVars_d0_1;
393 filtVars_d0_1 = d0_temp_1 + temp1_add_1;
394 input = c7x::strm_eng<1, vec>::get_adv();
395 d1_mul_1 = b12_a12 * input;
396 filtVars_d1_1 = d1_mul_1 + temp0_mul_1;
399 output2 = output1 + filtVars_d0_2;
400 temp1_mul_2 = b21_a21 * output1;
401 temp1_add_2 = temp1_mul_2 + filtVars_d1_2;
402 temp0_mul_2 = a22 * filtVars_d0_2;
403 d0_temp_2 = a21 * filtVars_d0_2;
404 filtVars_d0_2 = d0_temp_2 + temp1_add_2;
405 d1_mul_2 = b22_a22 * output1;
406 filtVars_d1_2 = d1_mul_2 + temp0_mul_2;
409 output3 = output2 + filtVars_d0_3;
410 temp1_mul_3 = b31_a31 * output2;
411 temp1_add_3 = temp1_mul_3 + filtVars_d1_3;
412 temp0_mul_3 = a32 * filtVars_d0_3;
413 d0_temp_3 = a31 * filtVars_d0_3;
414 filtVars_d0_3 = d0_temp_3 + temp1_add_3;
415 d1_mul_3 = b32_a32 * output2;
416 filtVars_d1_3 = d1_mul_3 + temp0_mul_3;
418 __vpred tmp = c7x::strm_agen<0, vec>::get_vpred();
419 vec *VB1 = c7x::strm_agen<0, vec>::get_adv(pOutLocal);
420 #if DSPLIB_DEBUGPRINT
428 vec output = output3 * outGain;
429 #if DSPLIB_DEBUGPRINT
431 DSPLIB_debugPrintVector(output);
434 __vstore_pred(tmp, VB1, output);
437 __vpred tmp1 = c7x::strm_agen<1, vec>::get_vpred();
438 vec *VB2 = c7x::strm_agen<1, vec>::get_adv(pFilterVarLocal);
439 __vstore_pred(tmp1, VB2, filtVars_d0_1);
441 tmp1 = c7x::strm_agen<1, vec>::get_vpred();
442 VB2 = c7x::strm_agen<1, vec>::get_adv(pFilterVarLocal);
443 __vstore_pred(tmp1, VB2, filtVars_d1_1);
445 tmp1 = c7x::strm_agen<1, vec>::get_vpred();
446 VB2 = c7x::strm_agen<1, vec>::get_adv(pFilterVarLocal);
447 __vstore_pred(tmp1, VB2, filtVars_d0_2);
449 tmp1 = c7x::strm_agen<1, vec>::get_vpred();
450 VB2 = c7x::strm_agen<1, vec>::get_adv(pFilterVarLocal);
451 __vstore_pred(tmp1, VB2, filtVars_d1_2);
453 tmp1 = c7x::strm_agen<1, vec>::get_vpred();
454 VB2 = c7x::strm_agen<1, vec>::get_adv(pFilterVarLocal);
455 __vstore_pred(tmp1, VB2, filtVars_d0_3);
457 tmp1 = c7x::strm_agen<1, vec>::get_vpred();
458 VB2 = c7x::strm_agen<1, vec>::get_adv(pFilterVarLocal);
459 __vstore_pred(tmp1, VB2, filtVars_d1_3);
471 void *restrict pFilterCoeff,
472 void *restrict pFilterVar,
473 void *restrict pOut);
#define SE_SE0_PARAM_OFFSET
#define SE_SA0_PARAM_OFFSET
#define SE_SE1_PARAM_OFFSET
static dataType fast_recip(dataType x)
DSPLIB_STATUS DSPLIB_cascadeBiquad_init_ci(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsFilterCoeff, const DSPLIB_bufParams2D_t *bufParamsFilterVar, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_cascadeBiquad_InitArgs *pKerInitArgs)
This function is the initialization function for the C7x implementation of the kernel....
template DSPLIB_STATUS DSPLIB_cascadeBiquad_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsFilterCoeff, const DSPLIB_bufParams2D_t *bufParamsFilterVar, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_cascadeBiquad_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_cascadeBiquad_exec_ci(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilterCoeff, void *restrict pFilterVar, void *restrict pOut)
This function is the main execution function for the C7x implementation of the kernel....
template DSPLIB_STATUS DSPLIB_cascadeBiquad_exec_ci< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilterCoeff, void *restrict pFilterVar, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_cascadeBiquad.
#define SE_SA1_PARAM_OFFSET
DSPLIB_STATUS_NAME
The enumeration of all status codes.
void * DSPLIB_kernelHandle
Handle type for DSPLIB operations.
A structure for a 1 dimensional buffer descriptor.
A structure for a 2 dimensional buffer descriptor.
Structure containing the parameters to initialize the kernel.
uint32_t dataSize
Size of input data
uint32_t numChannels
number of channels
uint32_t numStages
Size of batch in terms of number of channels of input data
Structure that is reserved for internal use by the kernel.
uint8_t bufPblock[DSPLIB_CASCADEBIQUAD_PBLOCK_SIZE]
uint32_t filterVarPitch
Pitch of filter Variable buffer for different channels DSPLIB_cascadeBiquad_init that will be retriev...
uint32_t dataBufferOutPitch
Pitch of output buffer for different batches DSPLIB_cascadeBiquad_init that will be retrieved and use...
DSPLIB_cascadeBiquad_InitArgs initArgs
Structure holding initialization parameters
uint32_t dataBufferInPitch
Pitch of input buffer for different batches DSPLIB_cascadeBiquad_init that will be retrieved and used...