| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- #include "ref_conv.h"
- void ref_conv_f32(float32_t* pSrcA, uint32_t srcALen, float32_t* pSrcB,
- uint32_t srcBLen, float32_t* pDst)
- {
- float32_t sum; /* Accumulator */
- uint32_t i, j; /* loop counters */
- /* Loop to calculate convolution for output length number of times */
- for (i = 0; i < srcALen + srcBLen - 1; i++) {
- /* Initialize sum with zero to carry out MAC operations */
- sum = 0.0f;
- /* Loop to perform MAC operations according to convolution equation */
- for (j = 0; j <= i; j++) {
- /* Check the array limitations */
- if ((i - j < srcBLen) && (j < srcALen)) {
- /* z[i] += x[i-j] * y[j] */
- sum += pSrcB[i - j] * pSrcA[j];
- }
- }
- /* Store the output in the destination buffer */
- pDst[i] = sum;
- }
- }
- riscv_status ref_conv_partial_f32(float32_t* pSrcA, uint32_t srcALen,
- float32_t* pSrcB, uint32_t srcBLen,
- float32_t* pDst, uint32_t firstIndex,
- uint32_t numPoints)
- {
- ref_conv_f32(pSrcA, srcALen, pSrcB, srcBLen, pDst);
- return RISCV_MATH_SUCCESS;
- }
- void ref_conv_q31(q31_t* pSrcA, uint32_t srcALen, q31_t* pSrcB,
- uint32_t srcBLen, q31_t* pDst)
- {
- q63_t sum; /* Accumulator */
- uint32_t i, j; /* loop counter */
- /* Loop to calculate output of convolution for output length number of times
- */
- for (i = 0; i < srcALen + srcBLen - 1; i++) {
- /* Initialize sum with zero to carry on MAC operations */
- sum = 0;
- /* Loop to perform MAC operations according to convolution equation */
- for (j = 0; j <= i; j++) {
- /* Check the array limitations */
- if ((i - j < srcBLen) && (j < srcALen)) {
- /* z[i] += x[i-j] * y[j] */
- sum += (q63_t)pSrcA[j] * (pSrcB[i - j]);
- }
- }
- /* Store the output in the destination buffer */
- pDst[i] = (q31_t)(sum >> 31U);
- }
- }
- void ref_conv_fast_q31(q31_t* pSrcA, uint32_t srcALen, q31_t* pSrcB,
- uint32_t srcBLen, q31_t* pDst)
- {
- q31_t sum; /* Accumulator */
- uint32_t i, j; /* loop counter */
- /* Loop to calculate output of convolution for output length number of times
- */
- for (i = 0; i < srcALen + srcBLen - 1; i++) {
- /* Initialize sum with zero to carry on MAC operations */
- sum = 0;
- /* Loop to perform MAC operations according to convolution equation */
- for (j = 0; j <= i; j++) {
- /* Check the array limitations */
- if ((i - j < srcBLen) && (j < srcALen)) {
- /* z[i] += x[i-j] * y[j] */
- sum = (q31_t)(
- (((q63_t)sum << 32) + ((q63_t)pSrcA[j] * pSrcB[i - j])) >>
- 32);
- }
- }
- /* Store the output in the destination buffer */
- pDst[i] = (q31_t)(sum << 1U);
- }
- }
- riscv_status ref_conv_partial_q31(q31_t* pSrcA, uint32_t srcALen, q31_t* pSrcB,
- uint32_t srcBLen, q31_t* pDst,
- uint32_t firstIndex, uint32_t numPoints)
- {
- ref_conv_q31(pSrcA, srcALen, pSrcB, srcBLen, pDst);
- return RISCV_MATH_SUCCESS;
- }
- riscv_status ref_conv_partial_fast_q31(q31_t* pSrcA, uint32_t srcALen,
- q31_t* pSrcB, uint32_t srcBLen,
- q31_t* pDst, uint32_t firstIndex,
- uint32_t numPoints)
- {
- ref_conv_fast_q31(pSrcA, srcALen, pSrcB, srcBLen, pDst);
- return RISCV_MATH_SUCCESS;
- }
- void ref_conv_q15(q15_t* pSrcA, uint32_t srcALen, q15_t* pSrcB,
- uint32_t srcBLen, q15_t* pDst)
- {
- q63_t sum; /* Accumulator */
- uint32_t i, j; /* loop counter */
- /* Loop to calculate output of convolution for output length number of times
- */
- for (i = 0; i < srcALen + srcBLen - 1; i++) {
- /* Initialize sum with zero to carry on MAC operations */
- sum = 0;
- /* Loop to perform MAC operations according to convolution equation */
- for (j = 0; j <= i; j++) {
- /* Check the array limitations */
- if ((i - j < srcBLen) && (j < srcALen)) {
- /* z[i] += x[i-j] * y[j] */
- sum += (q31_t)pSrcA[j] * pSrcB[i - j];
- }
- }
- /* Store the output in the destination buffer */
- pDst[i] = ref_sat_q15(sum >> 15U);
- }
- }
- riscv_status ref_conv_partial_fast_opt_q15(q15_t* pSrcA, uint32_t srcALen,
- q15_t* pSrcB, uint32_t srcBLen,
- q15_t* pDst, uint32_t firstIndex,
- uint32_t numPoints, q15_t* pScratch1,
- q15_t* pScratch2)
- {
- q31_t sum; /* Accumulator */
- uint32_t i, j; /* loop counter */
- /* Loop to calculate output of convolution for output length number of times
- */
- for (i = 0; i < srcALen + srcBLen - 1; i++) {
- /* Initialize sum with zero to carry on MAC operations */
- sum = 0;
- /* Loop to perform MAC operations according to convolution equation */
- for (j = 0; j <= i; j++) {
- /* Check the array limitations */
- if ((i - j < srcBLen) && (j < srcALen)) {
- /* z[i] += x[i-j] * y[j] */
- sum += (q31_t)pSrcA[j] * pSrcB[i - j];
- }
- }
- /* Store the output in the destination buffer */
- pDst[i] = ref_sat_q15(sum >> 15U);
- }
- return RISCV_MATH_SUCCESS;
- }
- void ref_conv_fast_q15(q15_t* pSrcA, uint32_t srcALen, q15_t* pSrcB,
- uint32_t srcBLen, q15_t* pDst)
- {
- q31_t sum; /* Accumulator */
- uint32_t i, j; /* loop counter */
- /* Loop to calculate output of convolution for output length number of times
- */
- for (i = 0; i < srcALen + srcBLen - 1; i++) {
- /* Initialize sum with zero to carry on MAC operations */
- sum = 0;
- /* Loop to perform MAC operations according to convolution equation */
- for (j = 0; j <= i; j++) {
- /* Check the array limitations */
- if ((i - j < srcBLen) && (j < srcALen)) {
- /* z[i] += x[i-j] * y[j] */
- sum += (q31_t)pSrcA[j] * pSrcB[i - j];
- }
- }
- /* Store the output in the destination buffer */
- pDst[i] = sum >> 15U;
- }
- }
- void ref_conv_fast_opt_q15(q15_t* pSrcA, uint32_t srcALen, q15_t* pSrcB,
- uint32_t srcBLen, q15_t* pDst, q15_t* pScratch1,
- q15_t* pScratch2)
- {
- q31_t sum; /* Accumulator */
- uint32_t i, j; /* loop counter */
- /* Loop to calculate output of convolution for output length number of times
- */
- for (i = 0; i < srcALen + srcBLen - 1; i++) {
- /* Initialize sum with zero to carry on MAC operations */
- sum = 0;
- /* Loop to perform MAC operations according to convolution equation */
- for (j = 0; j <= i; j++) {
- /* Check the array limitations */
- if ((i - j < srcBLen) && (j < srcALen)) {
- /* z[i] += x[i-j] * y[j] */
- sum += (q31_t)pSrcA[j] * pSrcB[i - j];
- }
- }
- /* Store the output in the destination buffer */
- pDst[i] = ref_sat_q15(sum >> 15U);
- }
- }
- riscv_status ref_conv_partial_q15(q15_t* pSrcA, uint32_t srcALen, q15_t* pSrcB,
- uint32_t srcBLen, q15_t* pDst,
- uint32_t firstIndex, uint32_t numPoints)
- {
- ref_conv_q15(pSrcA, srcALen, pSrcB, srcBLen, pDst);
- return RISCV_MATH_SUCCESS;
- }
- riscv_status ref_conv_partial_fast_q15(q15_t* pSrcA, uint32_t srcALen,
- q15_t* pSrcB, uint32_t srcBLen,
- q15_t* pDst, uint32_t firstIndex,
- uint32_t numPoints)
- {
- ref_conv_fast_q15(pSrcA, srcALen, pSrcB, srcBLen, pDst);
- return RISCV_MATH_SUCCESS;
- }
- void ref_conv_q7(q7_t* pSrcA, uint32_t srcALen, q7_t* pSrcB, uint32_t srcBLen,
- q7_t* pDst)
- {
- q31_t sum; /* Accumulator */
- uint32_t i, j; /* loop counter */
- /* Loop to calculate output of convolution for output length number of times
- */
- for (i = 0; i < srcALen + srcBLen - 1; i++) {
- /* Initialize sum with zero to carry on MAC operations */
- sum = 0;
- /* Loop to perform MAC operations according to convolution equation */
- for (j = 0; j <= i; j++) {
- /* Check the array limitations */
- if ((i - j < srcBLen) && (j < srcALen)) {
- /* z[i] += x[i-j] * y[j] */
- sum += (q15_t)pSrcA[j] * pSrcB[i - j];
- }
- }
- /* Store the output in the destination buffer */
- pDst[i] = (q7_t)ref_sat_q7(sum >> 7);
- }
- }
- riscv_status ref_conv_partial_q7(q7_t* pSrcA, uint32_t srcALen, q7_t* pSrcB,
- uint32_t srcBLen, q7_t* pDst,
- uint32_t firstIndex, uint32_t numPoints)
- {
- ref_conv_q7(pSrcA, srcALen, pSrcB, srcBLen, pDst);
- return RISCV_MATH_SUCCESS;
- }
|