[feat][nmsis] add nmsis component and nn,dsp demo

This commit is contained in:
jzlv 2021-09-26 13:38:51 +08:00
parent b2aada479b
commit 5d1126d0f0
989 changed files with 286224 additions and 0 deletions

View file

@ -0,0 +1,5 @@
set(TARGET_REQUIRED_PRIVATE_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(TARGET_REQUIRED_SRCS cmplx_conj.c cmplx_dot_prod.c cmplx_mag_squared.c cmplx_mag.c cmplx_mult_cmplx.c cmplx_mult_real.c)
set(TARGET_REQUIRED_LIBS nmsis)
set(mains main.c)
generate_bin()

View file

@ -0,0 +1,16 @@
// Array for ComplxMathFunctions part1
#define ARRAY_SIZE 30
float32_t f32_pSrcA[ARRAY_SIZE*2] = {704.5279167f,506.6857712f,793.2871035f,305.5315929f,109.5305238f,309.7076447f,122.7004618f,840.5692246f,950.9584574f,934.8239665f,588.5509918f,833.7191077f,611.3631242f,924.9100665f,361.4867205f,41.83539833f,183.2083257f,556.116886f,265.9937173f,496.8472173f,928.5481753f,253.0324213f,586.8337343f,581.7978718f,456.0253183f,326.0406882f,884.6902438f,541.1501332f,417.6316005f,152.5320118f,213.5065429f,433.9458192f,187.0847954f,140.5114248f,962.0518991f,412.6578408f,812.6642868f,946.1971639f,471.3243121f,711.1154755f,392.1989654f,473.4947265f,833.0514348f,354.3220799f,715.6117383f,942.1381415f,847.6186892f,589.3667904f,87.57625204f,727.8179529f,342.4746073f,801.1042843f,162.8443f,435.5455276f,734.1532633f,521.3174816f,334.1935264f,553.207996f,881.1368172f,74.2205834f};
float32_t f32_pSrcB[ARRAY_SIZE*2] = {360.2278893f,587.1974853f,62.40814712f,792.7066399f,965.8345962f,293.2086075f,426.1140755f,724.4893256f,843.4007777f,287.2378938f,260.9545077f,637.231996f,453.1068466f,207.8070205f,549.0365559f,737.3326029f,744.005019f,758.8798312f,588.1083464f,506.6380206f,622.7278774f,657.3896717f,726.0084871f,734.7774978f,585.0305975f,105.440685f,453.6799981f,336.2371604f,825.2010211f,702.9909706f,726.9576162f,965.70017f,361.2763939f,104.5421251f,739.3361226f,409.1556159f,821.2729964f,870.0662011f,453.6375324f,710.5607406f,545.6878012f,67.20579844f,80.87042566f,563.4148473f,64.18989416f,331.7376586f,848.6764813f,521.1060922f,388.3993025f,755.049026f,987.0420605f,168.8053496f,938.6704548f,851.8401507f,87.24828032f,410.7651106f,775.8945631f,308.6824955f,455.6400612f,316.6203432f};
float32_t f32_pDst[ARRAY_SIZE*2];
float32_t f32_pDst_ref[ARRAY_SIZE*2];
q31_t q31_pSrcA[ARRAY_SIZE*2] = {796887251,1030167264,189571953,733841244,256011990,463585171,1005360044,362003295,508134324,169736787,818983756,70214708,947598976,346046906,944296507,759550386,930551632,388800383,927900109,8980540,978221952,200614415,152879041,103577868,54318340,451673229,127874782,394496616,890345881,1065328751,626449475,587012454,174638999,985645921,808136208,230002610,946615979,687525423,153757560,780541539,537451927,631067255,955381912,24953691,780465704,533188779,120232986,800550679,307319376,98143676,384722563,820027168,237431489,605365063,455827685,422148486,226475963,91640355,102399531,658465192};
q31_t q31_pSrcB[ARRAY_SIZE*2] = {47534611,673506795,381523311,438499188,617707419,908754814,217138888,82127467,378297066,884969202,714080958,625366034,575766908,264545177,600676435,1058705955,908407625,774297443,198108301,230675120,626746145,816692908,19309240,1023223843,753263914,487072794,894750046,1047668430,802061507,409452595,670309876,448547624,818122630,793097220,578317164,334950039,34576675,753110623,995698597,632807993,509216146,437199428,688498556,912693142,567255998,298230889,91427720,260343483,505818717,339538160,526192993,692543562,328013357,404518690,96459129,371523187,1034363659,35649598,195456424,874204657};
q31_t q31_pDst[ARRAY_SIZE*2];
q31_t q31_pDst_ref[ARRAY_SIZE*2];
q15_t q15_pSrcA[ARRAY_SIZE*2] = {11228,5879,5625,5673,8452,14898,14261,6351,156,9493,4178,5333,14104,8360,5176,16106,7558,13492,9620,6464,4130,9997,11322,1636,14766,12847,885,13513,4029,15574,8132,4305,2173,4809,11187,7340,9823,15332,2282,5647,13839,6988,9147,15621,11716,11090,5981,345,649,9737,11334,12335,4548,11786,10397,14048,14572,6375,7552,15932};
q15_t q15_pSrcB[ARRAY_SIZE*2] = {879,2908,15598,14649,10350,5701,11753,14826,10474,9211,13443,9030,10187,14348,4934,15523,1612,13706,10775,4233,4661,5253,2123,11275,278,6970,5150,7762,6165,10643,1430,13426,9020,2872,15269,11916,1503,16274,12731,5935,663,7371,6641,4741,3521,12056,9989,951,11743,3680,2299,13004,5343,8490,11289,14925,9459,6489,5566,13296};
q15_t q15_pDst[ARRAY_SIZE*2];
q15_t q15_pDst_ref[ARRAY_SIZE*2];

View file

@ -0,0 +1,28 @@
#include "ref.h"
void ref_cmplx_conj_f32(float32_t *pSrc, float32_t *pDst, uint32_t numSamples)
{
uint32_t i;
for (i = 0; i < numSamples * 2; i += 2) {
pDst[i] = pSrc[i];
pDst[i + 1] = -pSrc[i + 1];
}
}
void ref_cmplx_conj_q31(q31_t *pSrc, q31_t *pDst, uint32_t numSamples)
{
uint32_t i;
for (i = 0; i < numSamples * 2; i += 2) {
pDst[i] = pSrc[i];
pDst[i + 1] = -pSrc[i + 1];
}
}
void ref_cmplx_conj_q15(q15_t *pSrc, q15_t *pDst, uint32_t numSamples)
{
uint32_t i;
for (i = 0; i < numSamples * 2; i += 2) {
pDst[i] = pSrc[i];
pDst[i + 1] = -pSrc[i + 1];
}
}

View file

@ -0,0 +1,61 @@
#include "ref.h"
void ref_cmplx_dot_prod_f32(float32_t *pSrcA, float32_t *pSrcB,
uint32_t numSamples, float32_t *realResult,
float32_t *imagResult)
{
float32_t sumr, sumi;
uint32_t i;
sumr = 0;
sumi = 0;
for (i = 0; i < numSamples * 2; i += 2) {
sumr += pSrcA[i] * pSrcB[i] - pSrcA[i + 1] * pSrcB[i + 1];
sumi += pSrcA[i] * pSrcB[i + 1] + pSrcA[i + 1] * pSrcB[i];
}
*realResult = sumr;
*imagResult = sumi;
}
void ref_cmplx_dot_prod_q31(q31_t *pSrcA, q31_t *pSrcB, uint32_t numSamples,
q63_t *realResult, q63_t *imagResult)
{
q63_t sumr, sumi;
uint32_t i;
sumr = 0;
sumi = 0;
for (i = 0; i < numSamples * 2; i += 2) {
// shifting down 14 here to provide guard bits
sumr += (((q63_t)pSrcA[i] * pSrcB[i]) >> 14) -
(((q63_t)pSrcA[i + 1] * pSrcB[i + 1]) >> 14);
sumi += (((q63_t)pSrcA[i] * pSrcB[i + 1]) >> 14) +
(((q63_t)pSrcA[i + 1] * pSrcB[i]) >> 14);
}
*realResult = sumr;
*imagResult = sumi;
}
void ref_cmplx_dot_prod_q15(q15_t *pSrcA, q15_t *pSrcB, uint32_t numSamples,
q31_t *realResult, q31_t *imagResult)
{
q63_t sumr, sumi;
uint32_t i;
sumr = 0;
sumi = 0;
for (i = 0; i < numSamples * 2; i += 2) {
sumr += (q31_t)pSrcA[i] * pSrcB[i] - (q31_t)pSrcA[i + 1] * pSrcB[i + 1];
sumi += (q31_t)pSrcA[i] * pSrcB[i + 1] + (q31_t)pSrcA[i + 1] * pSrcB[i];
}
// shifting down 6 at the end here because there are already 32 guard bits
// available, this method is more accurate
*realResult = (q31_t)(sumr >> 6);
*imagResult = (q31_t)(sumi >> 6);
}

View file

@ -0,0 +1,37 @@
#include "ref.h"
void ref_cmplx_mag_f32(float32_t *pSrc, float32_t *pDst, uint32_t numSamples)
{
uint32_t i;
for (i = 0; i < numSamples * 2; i += 2) {
*pDst++ = sqrtf(pSrc[i] * pSrc[i] + pSrc[i + 1] * pSrc[i + 1]);
}
}
void ref_cmplx_mag_q31(q31_t *pSrc, q31_t *pDst, uint32_t numSamples)
{
uint32_t i;
q31_t acc0, acc1, out;
for (i = 0; i < numSamples * 2; i += 2) {
acc0 = (q31_t)(((q63_t)pSrc[i] * pSrc[i]) >> 33);
acc1 = (q31_t)(((q63_t)pSrc[i + 1] * pSrc[i + 1]) >> 33);
out = acc0 + acc1;
*pDst++ = (q31_t)(sqrtf((float)out / 2147483648.0f) * 2147483648.0f);
}
}
void ref_cmplx_mag_q15(q15_t *pSrc, q15_t *pDst, uint32_t numSamples)
{
uint32_t i;
q31_t acc0, acc1;
q15_t out;
for (i = 0; i < numSamples * 2; i += 2) {
acc0 = pSrc[i] * pSrc[i];
acc1 = pSrc[i + 1] * pSrc[i + 1];
out = (q15_t)(((q63_t)acc0 + acc1) >> 17);
*pDst++ = (q15_t)(sqrtf((float)out / 32768.0f) * 32768.0f);
}
}

View file

@ -0,0 +1,35 @@
#include "ref.h"
void ref_cmplx_mag_squared_f32(float32_t *pSrc, float32_t *pDst,
uint32_t numSamples)
{
uint32_t i;
for (i = 0; i < numSamples * 2; i += 2) {
*pDst++ = pSrc[i] * pSrc[i] + pSrc[i + 1] * pSrc[i + 1];
}
}
void ref_cmplx_mag_squared_q31(q31_t *pSrc, q31_t *pDst, uint32_t numSamples)
{
uint32_t i;
q31_t acc0, acc1;
for (i = 0; i < numSamples * 2; i += 2) {
acc0 = (q31_t)(((q63_t)pSrc[i] * pSrc[i]) >> 33);
acc1 = (q31_t)(((q63_t)pSrc[i + 1] * pSrc[i + 1]) >> 33);
*pDst++ = acc0 + acc1;
}
}
void ref_cmplx_mag_squared_q15(q15_t *pSrc, q15_t *pDst, uint32_t numSamples)
{
uint32_t i;
q31_t acc0, acc1;
for (i = 0; i < numSamples * 2; i += 2) {
acc0 = pSrc[i] * pSrc[i];
acc1 = pSrc[i + 1] * pSrc[i + 1];
*pDst++ = (q15_t)(((q63_t)acc0 + acc1) >> 17);
}
}

View file

@ -0,0 +1,44 @@
#include "ref.h"
void ref_cmplx_mult_cmplx_f32(float32_t *pSrcA, float32_t *pSrcB,
float32_t *pDst, uint32_t numSamples)
{
uint32_t i;
for (i = 0; i < numSamples * 2; i += 2) {
pDst[i] = pSrcA[i] * pSrcB[i] - pSrcA[i + 1] * pSrcB[i + 1];
pDst[i + 1] = pSrcA[i] * pSrcB[i + 1] + pSrcA[i + 1] * pSrcB[i];
}
}
void ref_cmplx_mult_cmplx_q31(q31_t *pSrcA, q31_t *pSrcB, q31_t *pDst,
uint32_t numSamples)
{
uint32_t i;
q31_t mul1, mul2, mul3, mul4;
for (i = 0; i < numSamples * 2; i += 2) {
mul1 = ((q63_t)pSrcA[i] * pSrcB[i]) >> 33;
mul2 = ((q63_t)pSrcA[i + 1] * pSrcB[i + 1]) >> 33;
mul3 = ((q63_t)pSrcA[i] * pSrcB[i + 1]) >> 33;
mul4 = ((q63_t)pSrcA[i + 1] * pSrcB[i]) >> 33;
pDst[i] = mul1 - mul2;
pDst[i + 1] = mul3 + mul4;
}
}
void ref_cmplx_mult_cmplx_q15(q15_t *pSrcA, q15_t *pSrcB, q15_t *pDst,
uint32_t numSamples)
{
uint32_t i;
q31_t mul1, mul2, mul3, mul4;
for (i = 0; i < numSamples * 2; i += 2) {
mul1 = ((q31_t)pSrcA[i] * pSrcB[i]) >> 17;
mul2 = ((q31_t)pSrcA[i + 1] * pSrcB[i + 1]) >> 17;
mul3 = ((q31_t)pSrcA[i] * pSrcB[i + 1]) >> 17;
mul4 = ((q31_t)pSrcA[i + 1] * pSrcB[i]) >> 17;
pDst[i] = mul1 - mul2;
pDst[i + 1] = mul3 + mul4;
}
}

View file

@ -0,0 +1,40 @@
#include "ref.h"
void ref_cmplx_mult_real_f32(float32_t *pSrcCmplx, float32_t *pSrcReal,
float32_t *pCmplxDst, uint32_t numSamples)
{
uint32_t i;
for (i = 0; i < numSamples; i++) {
pCmplxDst[2 * i + 0] = pSrcCmplx[2 * i + 0] * pSrcReal[i];
pCmplxDst[2 * i + 1] = pSrcCmplx[2 * i + 1] * pSrcReal[i];
}
}
void ref_cmplx_mult_real_q31(q31_t *pSrcCmplx, q31_t *pSrcReal,
q31_t *pCmplxDst, uint32_t numSamples)
{
uint32_t i;
q31_t tempR, tempI;
for (i = 0; i < numSamples; i++) {
tempR = ((q63_t)pSrcCmplx[2 * i + 0] * pSrcReal[i]) >> 32;
tempI = ((q63_t)pSrcCmplx[2 * i + 1] * pSrcReal[i]) >> 32;
pCmplxDst[2 * i + 0] = ref_sat_n(tempR, 31) << 1;
pCmplxDst[2 * i + 1] = ref_sat_n(tempI, 31) << 1;
}
}
void ref_cmplx_mult_real_q15(q15_t *pSrcCmplx, q15_t *pSrcReal,
q15_t *pCmplxDst, uint32_t numSamples)
{
uint32_t i;
q31_t tempR, tempI;
for (i = 0; i < numSamples; i++) {
tempR = ((q31_t)pSrcCmplx[2 * i + 0] * pSrcReal[i]) >> 15;
tempI = ((q31_t)pSrcCmplx[2 * i + 1] * pSrcReal[i]) >> 15;
pCmplxDst[2 * i + 0] = ref_sat_q15(tempR);
pCmplxDst[2 * i + 1] = ref_sat_q15(tempI);
}
}

View file

@ -0,0 +1,399 @@
//
// Created by lujun on 19-6-28.
//
// This contains complx calculate in Conjugate, Dot Product, Magnitude,
// Magnitude Squared, by-Complex Multiplication, by-Real Multiplication each one
// has it's own function. All function can be found in main function. If you
// don't want to use it, then comment it. contains following functions,eachone
// includes q15,q31 and f32 versions
#include "riscv_math.h"
#include <stdint.h>
#include "array.h"
#include "../common.h"
#include "../HelperFunctions/math_helper.c"
#include "../HelperFunctions/ref_helper.c"
#include <stdio.h>
#include <stdlib.h>
#define DELTAF32 (2.0f)
#define DELTAQ31 (63)
#define DELTAQ15 (1)
#define DELTAQ7 (1)
#define ENABLE_ALL
#define CmplxMag
#define CmplxDotProduct
#define CONJ
#define MagSquared
#define CmplxMult
#define CmplxMultReal
int test_flag_error = 0;
/*
*********************************************************************************************************
* DSP_MagSquared
*********************************************************************************************************
*/
static int DSP_MagSquared(void)
{
uint8_t i;
/**********************************************************************************/
BENCH_START(riscv_cmplx_mag_squared_f32);
riscv_cmplx_mag_squared_f32(f32_pSrcA, f32_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_mag_squared_f32);
ref_cmplx_mag_squared_f32(f32_pSrcA, f32_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (fabs(f32_pDst[i] - f32_pDst_ref[i]) > DELTAF32) {
BENCH_ERROR(riscv_cmplx_mag_squared_f32);
printf("index: %d, expect: %f, actual: %f\n", i, f32_pDst_ref[i],
f32_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mag_squared_f32);
/***Q31*******************************************************************************/
BENCH_START(riscv_cmplx_mag_squared_q31);
riscv_cmplx_mag_squared_q31(q31_pSrcA, q31_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_mag_squared_q31);
ref_cmplx_mag_squared_q31(q31_pSrcA, q31_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (labs(q31_pDst[i] - q31_pDst_ref[i]) > DELTAQ31) {
BENCH_ERROR(riscv_cmplx_mag_squared_q31);
printf("index: %d, expect: %x, actual: %x\n", i, q31_pDst_ref[i],
q31_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mag_squared_q31);
/***Q15*******************************************************************************/
BENCH_START(riscv_cmplx_mag_squared_q15);
riscv_cmplx_mag_squared_q15(q15_pSrcA, q15_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_mag_squared_q15);
ref_cmplx_mag_squared_q15(q15_pSrcA, q15_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (abs(q15_pDst[i] - q15_pDst_ref[i]) > DELTAQ15) {
BENCH_ERROR(riscv_cmplx_mag_squared_q15);
printf("index: %d, expect: %x, actual: %x\n", i, q15_pDst_ref[i],
q15_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mag_squared_q15);
}
/*
*********************************************************************************************************
* DSP_CmplxMult
*********************************************************************************************************
*/
static int DSP_CmplxMult(void)
{
uint8_t i;
/**********************************************************************************/
BENCH_START(riscv_cmplx_mult_cmplx_f32);
riscv_cmplx_mult_cmplx_f32(f32_pSrcA, f32_pSrcB, f32_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_mult_cmplx_f32);
ref_cmplx_mult_cmplx_f32(f32_pSrcA, f32_pSrcB, f32_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (fabs(f32_pDst[i] - f32_pDst_ref[i]) > DELTAF32) {
BENCH_ERROR(riscv_cmplx_mult_cmplx_f32);
printf("index: %d, expect: %f, actual: %f\n", i, f32_pDst_ref[i],
f32_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mult_cmplx_f32);
/***Q31*******************************************************************************/
BENCH_START(riscv_cmplx_mult_cmplx_q31);
riscv_cmplx_mult_cmplx_q31(q31_pSrcA, q31_pSrcB, q31_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_mult_cmplx_q31);
ref_cmplx_mult_cmplx_q31(q31_pSrcA, q31_pSrcB, q31_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (labs(q31_pDst[i] - q31_pDst_ref[i]) > DELTAQ31) {
BENCH_ERROR(riscv_cmplx_mult_cmplx_q31);
printf("index: %d, expect: %x, actual: %x\n", i, q31_pDst_ref[i],
q31_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mult_cmplx_q31);
/***Q15*******************************************************************************/
BENCH_START(riscv_cmplx_mult_cmplx_q15);
riscv_cmplx_mult_cmplx_q15(q15_pSrcA, q15_pSrcB, q15_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_mult_cmplx_q15);
ref_cmplx_mult_cmplx_q15(q15_pSrcA, q15_pSrcB, q15_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (abs(q15_pDst[i] - q15_pDst_ref[i]) > DELTAQ15) {
BENCH_ERROR(riscv_cmplx_mult_cmplx_q15);
printf("index: %d, expect: %x, actual: %x\n", i, q15_pDst_ref[i],
q15_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mult_cmplx_q15);
}
/*
*********************************************************************************************************
* DSP_CmplxMultReal
*********************************************************************************************************
*/
static int DSP_CmplxMultReal(void)
{
uint8_t i;
/**********************************************************************************/
BENCH_START(riscv_cmplx_mult_real_f32);
riscv_cmplx_mult_real_f32(f32_pSrcA, f32_pSrcB, f32_pDst,
ARRAY_SIZE);
BENCH_END(riscv_cmplx_mult_real_f32);
ref_cmplx_mult_real_f32(f32_pSrcA, f32_pSrcB, f32_pDst_ref,
ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE * 2; i++) {
if (fabs(f32_pDst[i] - f32_pDst_ref[i]) > DELTAF32) {
BENCH_ERROR(riscv_cmplx_mult_real_f32);
printf("index: %d, expect: %f, actual: %f\n", i,
f32_pDst_ref[i], f32_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mult_real_f32);
/***Q31*******************************************************************************/
BENCH_START(riscv_cmplx_mult_real_q31);
riscv_cmplx_mult_real_q31(q31_pSrcA, q31_pSrcB, q31_pDst,
ARRAY_SIZE);
BENCH_END(riscv_cmplx_mult_real_q31);
ref_cmplx_mult_real_q31(q31_pSrcA, q31_pSrcB, q31_pDst_ref,
ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE * 2; i++) {
if (labs(q31_pDst[i] - q31_pDst_ref[i]) > DELTAQ31) {
BENCH_ERROR(riscv_cmplx_mult_real_q31);
printf("index: %d, expect: %x, actual: %x\n", i,
q31_pDst_ref[i], q31_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mult_real_q31);
/***Q15*******************************************************************************/
BENCH_START(riscv_cmplx_mult_real_q15);
riscv_cmplx_mult_real_q15(q15_pSrcA, q15_pSrcB, q15_pDst,
ARRAY_SIZE);
BENCH_END(riscv_cmplx_mult_real_q15);
ref_cmplx_mult_real_q15(q15_pSrcA, q15_pSrcB, q15_pDst_ref,
ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE * 2; i++) {
if (abs(q15_pDst[i] - q15_pDst_ref[i]) > DELTAQ15) {
BENCH_ERROR(riscv_cmplx_mult_real_q15);
printf("index: %d, expect: %x, actual: %x\n", i,
q15_pDst_ref[i], q15_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mult_real_q15);
}
/*
*********************************************************************************************************
* DSP_CONJ
*********************************************************************************************************
*/
static int DSP_CONJ(void)
{
uint8_t i;
/**********************************************************************************/
BENCH_START(riscv_cmplx_conj_f32);
riscv_cmplx_conj_f32(f32_pSrcA, f32_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_conj_f32);
ref_cmplx_conj_f32(f32_pSrcA, f32_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (fabs(f32_pDst[i] - f32_pDst_ref[i]) > DELTAF32) {
BENCH_ERROR(riscv_cmplx_conj_f32);
printf("index: %d, expect: %f, actual: %f\n", i, f32_pDst_ref[i],
f32_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_conj_f32);
/***Q31*******************************************************************************/
BENCH_START(riscv_cmplx_conj_q31);
riscv_cmplx_conj_q31(q31_pSrcA, q31_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_conj_q31);
ref_cmplx_conj_q31(q31_pSrcA, q31_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (labs(q31_pDst[i] - q31_pDst_ref[i]) > DELTAQ31) {
BENCH_ERROR(riscv_cmplx_conj_q31);
printf("index: %d, expect: %x, actual: %x\n", i, q31_pDst_ref[i],
q31_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_conj_q31);
/***Q15*******************************************************************************/
BENCH_START(riscv_cmplx_conj_q15);
riscv_cmplx_conj_q15(q15_pSrcA, q15_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_conj_q15);
ref_cmplx_conj_q15(q15_pSrcA, q15_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (abs(q15_pDst[i] - q15_pDst_ref[i]) > DELTAQ15) {
BENCH_ERROR(riscv_cmplx_conj_q15);
printf("index: %d, expect: %x, actual: %x\n", i, q15_pDst_ref[i],
q15_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_conj_q15);
}
/*
*********************************************************************************************************
* DSP_CmplxDotProduct
*********************************************************************************************************
*/
static int DSP_CmplxDotProduct(void)
{
float32_t f32_realResult;
float32_t f32_imagResult;
float32_t f32_realResult_ref;
float32_t f32_imagResult_ref;
q63_t q31_realResult;
q63_t q31_imagResult;
q63_t q31_realResult_ref;
q63_t q31_imagResult_ref;
q31_t q15_realResult;
q31_t q15_imagResult;
q31_t q15_realResult_ref;
q31_t q15_imagResult_ref;
/* clang-format on */
/**********************************************************************************/
BENCH_START(riscv_cmplx_dot_prod_f32);
riscv_cmplx_dot_prod_f32(f32_pSrcA, f32_pSrcB, ARRAY_SIZE, &f32_realResult,
&f32_imagResult);
BENCH_END(riscv_cmplx_dot_prod_f32);
ref_cmplx_dot_prod_f32(f32_pSrcA, f32_pSrcB, ARRAY_SIZE,
&f32_realResult_ref, &f32_imagResult_ref);
if ((fabs(f32_realResult - f32_realResult_ref) > DELTAF32) ||
(fabs(f32_imagResult - f32_imagResult_ref) > DELTAF32)) {
BENCH_ERROR(riscv_cmplx_dot_prod_f32);
printf("real expect: %f, actual: %f\nimag expect: %f, actual: %f\n",
f32_realResult_ref, f32_realResult, f32_imagResult_ref,
f32_imagResult);
test_flag_error = 1;
}
BENCH_STATUS(riscv_cmplx_dot_prod_f32);
/***Q31*******************************************************************************/
BENCH_START(riscv_cmplx_dot_prod_q31);
riscv_cmplx_dot_prod_q31(q31_pSrcA, q31_pSrcB, ARRAY_SIZE, &q31_realResult,
&q31_imagResult);
BENCH_END(riscv_cmplx_dot_prod_q31);
ref_cmplx_dot_prod_q31(q31_pSrcA, q31_pSrcB, ARRAY_SIZE,
&q31_realResult_ref, &q31_imagResult_ref);
if ((labs(q31_realResult - q31_realResult_ref) > DELTAQ31) ||
(labs(q31_imagResult - q31_imagResult_ref) > DELTAQ31)) {
BENCH_ERROR(riscv_cmplx_dot_prod_q31);
printf("real expect: %x, actual: %x\nimag expect: %x, actual: %x\n",
q31_realResult_ref, q31_realResult, q31_imagResult_ref,
q31_imagResult);
test_flag_error = 1;
}
BENCH_STATUS(riscv_cmplx_dot_prod_q31);
/***Q15*******************************************************************************/
BENCH_START(riscv_cmplx_dot_prod_q15);
riscv_cmplx_dot_prod_q15(q15_pSrcA, q15_pSrcB, ARRAY_SIZE, &q15_realResult,
&q15_imagResult);
BENCH_END(riscv_cmplx_dot_prod_q15);
ref_cmplx_dot_prod_q15(q15_pSrcA, q15_pSrcB, ARRAY_SIZE,
&q15_realResult_ref, &q15_imagResult_ref);
if ((abs(q15_realResult - q15_realResult_ref) > DELTAQ15) ||
(abs(q15_imagResult - q15_imagResult_ref) > DELTAQ15)) {
BENCH_ERROR(riscv_cmplx_dot_prod_q15);
printf("real expect: %x, actual: %x\nimag expect: %x, actual: %x\n",
q15_realResult_ref, q15_realResult, q15_imagResult_ref,
q15_imagResult);
test_flag_error = 1;
}
BENCH_STATUS(riscv_cmplx_dot_prod_q15);
}
/*
*********************************************************************************************************
* DSP_CmplxMag
*********************************************************************************************************
*/
static int DSP_CmplxMag(void)
{
uint8_t i;
/**********************************************************************************/
BENCH_START(riscv_cmplx_mag_f32);
riscv_cmplx_mag_f32(f32_pSrcA, f32_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_mag_f32);
ref_cmplx_mag_f32(f32_pSrcA, f32_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (fabs(f32_pDst[i] - f32_pDst_ref[i]) > DELTAF32) {
BENCH_ERROR(riscv_cmplx_mag_f32);
printf("index: %d, expect: %f, actual: %f\n", i, f32_pDst_ref[i],
f32_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mag_f32);
/***Q31*******************************************************************************/
BENCH_START(riscv_cmplx_mag_q31);
riscv_cmplx_mag_q31(q31_pSrcA, q31_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_mag_q31);
ref_cmplx_mag_q31(q31_pSrcA, q31_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (labs(q31_pDst[i] - q31_pDst_ref[i]) > DELTAQ31) {
BENCH_ERROR(riscv_cmplx_mag_q31);
printf("index: %d, expect: %x, actual: %x\n", i, q31_pDst_ref[i],
q31_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mag_q31);
/***Q15*******************************************************************************/
BENCH_START(riscv_cmplx_mag_q15);
riscv_cmplx_mag_q15(q15_pSrcA, q15_pDst, ARRAY_SIZE);
BENCH_END(riscv_cmplx_mag_q15);
ref_cmplx_mag_q15(q15_pSrcA, q15_pDst_ref, ARRAY_SIZE);
for (i = 0; i < ARRAY_SIZE; i++) {
if (abs(q15_pDst[i] - q15_pDst_ref[i]) > DELTAQ15) {
BENCH_ERROR(riscv_cmplx_mag_q15);
printf("index: %d, expect: %x, actual: %x\n", i, q15_pDst_ref[i],
q15_pDst[i]);
test_flag_error = 1;
}
}
BENCH_STATUS(riscv_cmplx_mag_q15);
}
int main()
{
BENCH_INIT;
#if defined CmplxMag || defined ENABLE_ALL
DSP_CmplxMag();
#endif
#if defined CmplxDotProduct || defined ENABLE_ALL
DSP_CmplxDotProduct();
#endif
#if defined CONJ || defined ENABLE_ALL
DSP_CONJ();
#endif
#if defined MagSquared || defined ENABLE_ALL
DSP_MagSquared();
#endif
#if defined CmplxMult || defined ENABLE_ALL
DSP_CmplxMult();
#endif
#if defined CmplxMultReal || defined ENABLE_ALL
DSP_CmplxMultReal();
#endif
BENCH_FINISH;
if (test_flag_error) {
printf("test error apprears, please recheck.\n");
return 1;
} else {
printf("all test are passed. Well done!\n");
}
return 0;
}