Skip to content

Commit 8c160e0

Browse files
committed
tests: lib: cmsis_dsp: filtering: Test vector FIR functions
This commit adds support for testing the vector implementation of the FIR filter functions when the MVE is enabled. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 4e379f9 commit 8c160e0

File tree

5 files changed

+110
-10
lines changed

5 files changed

+110
-10
lines changed

tests/lib/cmsis_dsp/filtering/src/fir_f16.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#define SNR_ERROR_THRESH ((float32_t)60)
1717
#define REL_ERROR_THRESH (1.0e-2)
1818

19+
#define COEFF_PADDING (4)
20+
1921
static void test_arm_fir_f16(void)
2022
{
2123
size_t sample_index, block_index;
@@ -28,6 +30,10 @@ static void test_arm_fir_f16(void)
2830
const float16_t *ref = (const float16_t *)ref_val;
2931
float16_t *state, *output_buf, *output;
3032
arm_fir_instance_f16 inst;
33+
#if defined(CONFIG_ARMV8_1_M_MVEF) && defined(CONFIG_FPU)
34+
float16_t coeff_padded[32];
35+
int round;
36+
#endif
3137

3238
/* Allocate buffers */
3339
state = malloc(2 * 47 * sizeof(float16_t));
@@ -44,10 +50,24 @@ static void test_arm_fir_f16(void)
4450
block_size = config[0];
4551
tap_count = config[1];
4652

53+
#if defined(CONFIG_ARMV8_1_M_MVEF) && defined(CONFIG_FPU)
54+
/* Copy coefficients and pad to zero */
55+
memset(coeff_padded, 127, sizeof(coeff_padded));
56+
round = tap_count / COEFF_PADDING;
57+
if ((round * COEFF_PADDING) < tap_count) {
58+
round++;
59+
}
60+
round = round * COEFF_PADDING;
61+
memset(coeff_padded, 0, round * sizeof(float16_t));
62+
memcpy(coeff_padded, coeff, tap_count * sizeof(float16_t));
63+
#endif
64+
4765
/* Initialise instance */
66+
#if defined(CONFIG_ARMV8_1_M_MVEF) && defined(CONFIG_FPU)
67+
arm_fir_init_f16(&inst, tap_count, coeff_padded, state, block_size);
68+
#else
4869
arm_fir_init_f16(&inst, tap_count, coeff, state, block_size);
49-
50-
/* TODO: Add MEVF support */
70+
#endif
5171

5272
/* Reset input pointer */
5373
input = (const float16_t *)in_val;

tests/lib/cmsis_dsp/filtering/src/fir_f32.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#define SNR_ERROR_THRESH ((float32_t)120)
1717
#define REL_ERROR_THRESH (3.0e-5)
1818

19+
#define COEFF_PADDING (4)
20+
1921
static void test_arm_fir_f32(void)
2022
{
2123
size_t sample_index, block_index;
@@ -28,6 +30,10 @@ static void test_arm_fir_f32(void)
2830
const float32_t *ref = (const float32_t *)ref_val;
2931
float32_t *state, *output_buf, *output;
3032
arm_fir_instance_f32 inst;
33+
#if defined(CONFIG_ARMV8_1_M_MVEF) && defined(CONFIG_FPU)
34+
float32_t coeff_padded[32];
35+
int round;
36+
#endif
3137

3238
/* Allocate buffers */
3339
state = malloc(2 * 47 * sizeof(float32_t));
@@ -44,10 +50,24 @@ static void test_arm_fir_f32(void)
4450
block_size = config[0];
4551
tap_count = config[1];
4652

53+
#if defined(CONFIG_ARMV8_1_M_MVEF) && defined(CONFIG_FPU)
54+
/* Copy coefficients and pad to zero */
55+
memset(coeff_padded, 127, sizeof(coeff_padded));
56+
round = tap_count / COEFF_PADDING;
57+
if ((round * COEFF_PADDING) < tap_count) {
58+
round++;
59+
}
60+
round = round * COEFF_PADDING;
61+
memset(coeff_padded, 0, round * sizeof(float32_t));
62+
memcpy(coeff_padded, coeff, tap_count * sizeof(float32_t));
63+
#endif
64+
4765
/* Initialise instance */
66+
#if defined(CONFIG_ARMV8_1_M_MVEF) && defined(CONFIG_FPU)
67+
arm_fir_init_f32(&inst, tap_count, coeff_padded, state, block_size);
68+
#else
4869
arm_fir_init_f32(&inst, tap_count, coeff, state, block_size);
49-
50-
/* TODO: Add MEVF support */
70+
#endif
5171

5272
/* Reset input pointer */
5373
input = (const float32_t *)in_val;

tests/lib/cmsis_dsp/filtering/src/fir_q15.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#define SNR_ERROR_THRESH ((float32_t)59)
1717
#define ABS_ERROR_THRESH_Q15 ((q15_t)2)
1818

19+
#define COEFF_PADDING (8)
20+
1921
static void test_arm_fir_q15(void)
2022
{
2123
size_t sample_index, block_index;
@@ -28,6 +30,10 @@ static void test_arm_fir_q15(void)
2830
const q15_t *ref = (const q15_t *)ref_val;
2931
q15_t *state, *output_buf, *output;
3032
arm_fir_instance_q15 inst;
33+
#if defined(CONFIG_ARMV8_1_M_MVEI) && defined(CONFIG_FPU)
34+
q15_t coeff_padded[32];
35+
int round;
36+
#endif
3137

3238
/* Allocate buffers */
3339
state = malloc(3 * 41 * sizeof(q15_t));
@@ -44,10 +50,24 @@ static void test_arm_fir_q15(void)
4450
block_size = config[0];
4551
tap_count = config[1];
4652

53+
#if defined(CONFIG_ARMV8_1_M_MVEI) && defined(CONFIG_FPU)
54+
/* Copy coefficients and pad to zero */
55+
memset(coeff_padded, 127, sizeof(coeff_padded));
56+
round = tap_count / COEFF_PADDING;
57+
if ((round * COEFF_PADDING) < tap_count) {
58+
round++;
59+
}
60+
round = round * COEFF_PADDING;
61+
memset(coeff_padded, 0, round * sizeof(q15_t));
62+
memcpy(coeff_padded, coeff, tap_count * sizeof(q15_t));
63+
#endif
64+
4765
/* Initialise instance */
66+
#if defined(CONFIG_ARMV8_1_M_MVEI) && defined(CONFIG_FPU)
67+
arm_fir_init_q15(&inst, tap_count, coeff_padded, state, block_size);
68+
#else
4869
arm_fir_init_q15(&inst, tap_count, coeff, state, block_size);
49-
50-
/* TODO: Add MEVI support */
70+
#endif
5171

5272
/* Reset input pointer */
5373
input = (const q15_t *)in_val;

tests/lib/cmsis_dsp/filtering/src/fir_q31.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#define SNR_ERROR_THRESH ((float32_t)100)
1717
#define ABS_ERROR_THRESH_Q31 ((q31_t)2)
1818

19+
#define COEFF_PADDING (4)
20+
1921
static void test_arm_fir_q31(void)
2022
{
2123
size_t sample_index, block_index;
@@ -28,6 +30,10 @@ static void test_arm_fir_q31(void)
2830
const q31_t *ref = (const q31_t *)ref_val;
2931
q31_t *state, *output_buf, *output;
3032
arm_fir_instance_q31 inst;
33+
#if defined(CONFIG_ARMV8_1_M_MVEI) && defined(CONFIG_FPU)
34+
q31_t coeff_padded[32];
35+
int round;
36+
#endif
3137

3238
/* Allocate buffers */
3339
state = malloc(3 * 47 * sizeof(q31_t));
@@ -44,10 +50,24 @@ static void test_arm_fir_q31(void)
4450
block_size = config[0];
4551
tap_count = config[1];
4652

53+
#if defined(CONFIG_ARMV8_1_M_MVEI) && defined(CONFIG_FPU)
54+
/* Copy coefficients and pad to zero */
55+
memset(coeff_padded, 127, sizeof(coeff_padded));
56+
round = tap_count / COEFF_PADDING;
57+
if ((round * COEFF_PADDING) < tap_count) {
58+
round++;
59+
}
60+
round = round * COEFF_PADDING;
61+
memset(coeff_padded, 0, round * sizeof(q31_t));
62+
memcpy(coeff_padded, coeff, tap_count * sizeof(q31_t));
63+
#endif
64+
4765
/* Initialise instance */
66+
#if defined(CONFIG_ARMV8_1_M_MVEI) && defined(CONFIG_FPU)
67+
arm_fir_init_q31(&inst, tap_count, coeff_padded, state, block_size);
68+
#else
4869
arm_fir_init_q31(&inst, tap_count, coeff, state, block_size);
49-
50-
/* TODO: Add MEVI support */
70+
#endif
5171

5272
/* Reset input pointer */
5373
input = (const q31_t *)in_val;

tests/lib/cmsis_dsp/filtering/src/fir_q7.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#define SNR_ERROR_THRESH ((float32_t)10)
1717
#define ABS_ERROR_THRESH_Q7 ((q7_t)2)
1818

19+
#define COEFF_PADDING (16)
20+
1921
static void test_arm_fir_q7(void)
2022
{
2123
size_t sample_index, block_index;
@@ -28,6 +30,10 @@ static void test_arm_fir_q7(void)
2830
const q7_t *ref = (const q7_t *)ref_val;
2931
q7_t *state, *output_buf, *output;
3032
arm_fir_instance_q7 inst;
33+
#if defined(CONFIG_ARMV8_1_M_MVEI) && defined(CONFIG_FPU)
34+
q7_t coeff_padded[32];
35+
int round;
36+
#endif
3137

3238
/* Allocate buffers */
3339
state = malloc(47 * sizeof(q7_t));
@@ -44,10 +50,24 @@ static void test_arm_fir_q7(void)
4450
block_size = config[0];
4551
tap_count = config[1];
4652

53+
#if defined(CONFIG_ARMV8_1_M_MVEI) && defined(CONFIG_FPU)
54+
/* Copy coefficients and pad to zero */
55+
memset(coeff_padded, 127, sizeof(coeff_padded));
56+
round = tap_count / COEFF_PADDING;
57+
if ((round * COEFF_PADDING) < tap_count) {
58+
round++;
59+
}
60+
round = round * COEFF_PADDING;
61+
memset(coeff_padded, 0, round * sizeof(q7_t));
62+
memcpy(coeff_padded, coeff, tap_count * sizeof(q7_t));
63+
#endif
64+
4765
/* Initialise instance */
66+
#if defined(CONFIG_ARMV8_1_M_MVEI) && defined(CONFIG_FPU)
67+
arm_fir_init_q7(&inst, tap_count, coeff_padded, state, block_size);
68+
#else
4869
arm_fir_init_q7(&inst, tap_count, coeff, state, block_size);
49-
50-
/* TODO: Add MEVI support */
70+
#endif
5171

5272
/* Reset input pointer */
5373
input = (const q7_t *)in_val;

0 commit comments

Comments
 (0)