Skip to content

Commit

Permalink
DSP: Update DSP support source code
Browse files Browse the repository at this point in the history
Signed-off-by: Huaqi Fang <578567190@qq.com>
  • Loading branch information
fanghuaqi committed Jul 24, 2020
1 parent 72f443d commit 9ba880a
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void riscv_conv_fast_opt_q15(
}
#if __RISCV_XLEN == 64
/* Pointer to take end of scratch2 buffer */
pScr2 = pScratch2 + srcBLen - 4;
pScr2 = pScratch2 + srcBLen - 3;
#else
/* Pointer to take end of scratch2 buffer */
pScr2 = pScratch2 + srcBLen - 1;
Expand Down
4 changes: 3 additions & 1 deletion NMSIS/DSP/Source/FilteringFunctions/riscv_conv_fast_q15.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ void riscv_conv_fast_q15(
/* Decrement loop counter */
k--;
}

#if defined RISCV_MATH_DSP && __RISCV_XLEN == 64
py += 2;
#endif /* defined RISCV_MATH_DSP && __RISCV_XLEN == 64 */
/* For the next MAC operations, the pointer py is used without SIMD
* So, py is incremented by 1 */
py = py + 1U;
Expand Down
6 changes: 4 additions & 2 deletions NMSIS/DSP/Source/FilteringFunctions/riscv_conv_opt_q15.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void riscv_conv_opt_q15(
/* Loop unrolling: Compute 4 outputs at a time */
k = srcBLen >> 2U;
#if __RISCV_XLEN == 64
pScr2 -= 4;
pScr2 -= 3;
#endif /* __RISCV_XLEN == 64 */
/* Copy smaller length input sequence in reverse order into second scratch buffer */
while (k > 0U)
Expand All @@ -140,7 +140,9 @@ void riscv_conv_opt_q15(
/* Decrement loop counter */
k--;
}

#if __RISCV_XLEN == 64
pScr2 += 3;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute remaining outputs */
k = srcBLen % 0x4U;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ riscv_status riscv_conv_partial_fast_opt_q15(

#if __RISCV_XLEN == 64
/* Pointer to take end of scratch2 buffer */
pScr2 = pScratch2 + srcBLen - 5;
pScr2 = pScratch2 + srcBLen - 4;
#else
/* Pointer to take end of scratch2 buffer */
pScr2 = pScratch2 + srcBLen - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ riscv_status riscv_conv_partial_fast_q15(
/* Decrement loop counter */
k--;
}

#if defined RISCV_MATH_DSP && __RISCV_XLEN == 64
py += 2;
#endif /* RISCV_MATH_DSP && __RISCV_XLEN == 64 */
/* For the next MAC operations, the pointer py is used without SIMD
So, py is incremented by 1 */
py = py + 1U;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ riscv_status riscv_conv_partial_opt_q15(

#if defined (RISCV_MATH_LOOPUNROLL)
#if __RISCV_XLEN == 64
pScr2 -= 4;
pScr2 -= 3;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute 4 outputs at a time */
k = srcBLen >> 2U;
Expand All @@ -153,7 +153,9 @@ riscv_status riscv_conv_partial_opt_q15(
/* Decrement loop counter */
k--;
}

#if __RISCV_XLEN == 64
pScr2 += 3;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute remaining outputs */
k = srcBLen % 0x4U;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ riscv_status riscv_conv_partial_opt_q7(
** a second loop below copies for the remaining 1 to 3 samples. */
while (k > 0U)
{
#if __RISCV_XLEN == 64
write_q15x4_ia(&pScr2,read_q15x4_da((q15_t **)&px));
#else
/* copy second buffer in reversal manner */
x4 = (q15_t) *pIn1++;
*pScr1++ = x4;
Expand All @@ -180,7 +177,6 @@ riscv_status riscv_conv_partial_opt_q7(
*pScr1++ = x4;
x4 = (q15_t) *pIn1++;
*pScr1++ = x4;
#endif /* __RISCV_XLEN == 64 */
/* Decrement loop counter */
k--;
}
Expand Down
6 changes: 3 additions & 3 deletions NMSIS/DSP/Source/FilteringFunctions/riscv_conv_partial_q15.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ riscv_status riscv_conv_partial_q15(
/* Update the inputA and inputB pointers for next MAC calculation */
py = ++pSrc2 - 1U;
px = pIn1;
#if __RISCV_XLEN == 64
py = py - 2;
#endif /* __RISCV_XLEN == 64 */
// #if __RISCV_XLEN == 64
// py = py - 2;
// #endif /* __RISCV_XLEN == 64 */
/* Increment MAC count */
count++;

Expand Down
16 changes: 12 additions & 4 deletions NMSIS/DSP/Source/FilteringFunctions/riscv_conv_partial_q31.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ riscv_status riscv_conv_partial_q31(
/* Decrement loop counter */
k--;
}

#if __RISCV_XLEN == 64
py++;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute remaining outputs */
k = count % 0x4U;

Expand Down Expand Up @@ -414,7 +416,9 @@ riscv_status riscv_conv_partial_q31(

/* Loop unrolling: Compute 4 outputs at a time */
k = srcBLen >> 2U;

#if __RISCV_XLEN == 64
py--;
#endif /* __RISCV_XLEN == 64 */
while (k > 0U)
{
#if __RISCV_XLEN == 64
Expand All @@ -435,7 +439,9 @@ riscv_status riscv_conv_partial_q31(
/* Decrement loop counter */
k--;
}

#if __RISCV_XLEN == 64
py++;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute remaining outputs */
k = srcBLen % 0x4U;

Expand Down Expand Up @@ -572,7 +578,9 @@ riscv_status riscv_conv_partial_q31(
/* Decrement loop counter */
k--;
}

#if __RISCV_XLEN == 64
py++;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute remaining outputs */
k = count % 0x4U;

Expand Down
4 changes: 3 additions & 1 deletion NMSIS/DSP/Source/FilteringFunctions/riscv_conv_partial_q7.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ riscv_status riscv_conv_partial_q7(
/* Decrement loop counter */
k--;
}

#if __RISCV_XLEN == 64
py += 7;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute remaining outputs */
k = count % 0x4U;

Expand Down
12 changes: 9 additions & 3 deletions NMSIS/DSP/Source/FilteringFunctions/riscv_conv_q31.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ void riscv_conv_q31(
/* Decrement loop counter */
k--;
}

#if __RISCV_XLEN == 64
py++;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute remaining outputs */
k = count % 0x4U;

Expand Down Expand Up @@ -410,7 +412,9 @@ void riscv_conv_q31(
/* Decrement loop counter */
k--;
}

#if __RISCV_XLEN == 64
py++;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute remaining outputs */
k = srcBLen % 0x4U;

Expand Down Expand Up @@ -548,7 +552,9 @@ void riscv_conv_q31(
/* Decrement loop counter */
k--;
}

#if __RISCV_XLEN == 64
py++;
#endif /* __RISCV_XLEN == 64 */
/* Loop unrolling: Compute remaining outputs */
k = blockSize3 % 0x4U;

Expand Down
17 changes: 14 additions & 3 deletions NMSIS/DSP/Source/FilteringFunctions/riscv_fir_decimate_fast_q15.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void riscv_fir_decimate_fast_q15(
#if defined (RISCV_MATH_LOOPUNROLL)
q31_t c1; /* Temporary variables to hold state and coefficient values */
#if __RISCV_XLEN == 64
q63_t x064, x164, c064;
q63_t x064, x164, c064, sum064 = 0;
#endif /* __RISCV_XLEN == 64 */
#endif

Expand Down Expand Up @@ -228,6 +228,15 @@ void riscv_fir_decimate_fast_q15(

while (tapCnt > 0U)
{
#if __RISCV_XLEN == 64
/* Read the b[numTaps-1] and b[numTaps-2] coefficients */
c064 = read_q15x4_ia ((q15_t **) &pb);

/* Read x[n-numTaps-1] and x[n-numTaps-2] sample */
x064 = read_q15x4_ia ((q15_t **) &px);

sum064 = __SMLAD(x064, c064, sum064);
#else
/* Read the b[numTaps-1] and b[numTaps-2] coefficients */
c0 = read_q15x2_ia ((q15_t **) &pb);

Expand All @@ -245,11 +254,13 @@ void riscv_fir_decimate_fast_q15(

/* Perform the multiply-accumulate */
sum0 = __SMLAD(x0, c1, sum0);

#endif
/* Decrement loop counter */
tapCnt--;
}

#if __RISCV_XLEN == 64
sum0 =(q31_t)((sum064 + (sum064<<32u))>>32u);
#endif
/* Loop unrolling: Compute remaining taps */
tapCnt = numTaps % 0x4U;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ static int DSP_SIN_COS_F32(void)
riscv_sin_cos_f32(0, &pSinVal, &pCosVal);
BENCH_END(riscv_sin_cos_f32);
ref_sin_cos_f32(0, &pSinVal_ref, &pCosVal_ref);
printf("%-20s : cycle: %d\n", "riscv_sin_cos_f32", cycle);
if ((fabs(pSinVal - pSinVal_ref) > DELTAF32) ||
(fabs(pCosVal - pCosVal_ref) > DELTAF32)) {
BENCH_ERROR(riscv_sin_cos_f32);
Expand All @@ -50,7 +49,6 @@ static int DSP_SIN_COS_Q31(void)
riscv_sin_cos_q31(0, &pSinVal, &pCosVal);
BENCH_END(riscv_sin_cos_q31);
ref_sin_cos_q31(0, &pSinVal_ref, &pCosVal_ref);
printf("%-20s : cycle: %d\n", "riscv_sin_cos_q31", cycle);
if ((labs(pSinVal - pSinVal_ref) > DELTAQ31) ||
(labs(pCosVal - pCosVal_ref) > DELTAQ31)) {
BENCH_ERROR(riscv_sin_cos_q31);
Expand Down

0 comments on commit 9ba880a

Please sign in to comment.