Skip to content

Commit a0db069

Browse files
Siyuan Chengcarlescufi
authored andcommitted
zdsp: Introduce attribute marco for third-party backend
Introduce DSP_DATA and DSP_STATIC_DATA attribute marco to support third-party backend Signed-off-by: Siyuan Cheng <[email protected]>
1 parent 1462751 commit a0db069

File tree

10 files changed

+329
-330
lines changed

10 files changed

+329
-330
lines changed

include/zephyr/dsp/basicmath.h

Lines changed: 102 additions & 90 deletions
Large diffs are not rendered by default.

include/zephyr/dsp/dsp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#define DSP_FUNC_SCOPE
1818
#endif
1919

20+
#define DSP_DATA
21+
22+
#define DSP_STATIC_DATA DSP_DATA
23+
2024
/**
2125
* @brief DSP Interface
2226
* @defgroup math_dsp DSP Interface

tests/subsys/dsp/basicmath/src/f32.c

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
#define SNR_ERROR_THRESH ((float32_t)120)
1717
#define REL_ERROR_THRESH (5.0e-5)
1818

19-
static void test_zdsp_add_f32(
20-
const uint32_t *input1, const uint32_t *input2, const uint32_t *ref,
21-
size_t length)
19+
static void test_zdsp_add_f32(const DSP_DATA uint32_t *input1, const DSP_DATA uint32_t *input2,
20+
const uint32_t *ref, size_t length)
2221
{
23-
float32_t *output;
22+
DSP_DATA float32_t *output;
2423

2524
/* Allocate output buffer */
26-
output = malloc(length * sizeof(float32_t));
25+
output = (DSP_DATA float32_t *)malloc(length * sizeof(float32_t));
2726
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
2827

2928
/* Run test function */
30-
zdsp_add_f32((float32_t *)input1, (float32_t *)input2, output, length);
29+
zdsp_add_f32((DSP_DATA float32_t *)input1, (DSP_DATA float32_t *)input2, output, length);
3130

3231
/* Validate output */
3332
zassert_true(
@@ -50,18 +49,17 @@ DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_add_f32, 11, in_com1, in_com2, ref_add
5049
DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_add_f32, long, in_com1, in_com2, ref_add,
5150
ARRAY_SIZE(in_com1));
5251

53-
static void test_zdsp_sub_f32(
54-
const uint32_t *input1, const uint32_t *input2, const uint32_t *ref,
55-
size_t length)
52+
static void test_zdsp_sub_f32(const DSP_DATA uint32_t *input1, const DSP_DATA uint32_t *input2,
53+
const uint32_t *ref, size_t length)
5654
{
57-
float32_t *output;
55+
DSP_DATA float32_t *output;
5856

5957
/* Allocate output buffer */
60-
output = malloc(length * sizeof(float32_t));
58+
output = (DSP_DATA float32_t *)malloc(length * sizeof(float32_t));
6159
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
6260

6361
/* Run test function */
64-
zdsp_sub_f32((float32_t *)input1, (float32_t *)input2, output, length);
62+
zdsp_sub_f32((DSP_DATA float32_t *)input1, (DSP_DATA float32_t *)input2, output, length);
6563

6664
/* Validate output */
6765
zassert_true(
@@ -84,18 +82,17 @@ DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_sub_f32, 11, in_com1, in_com2, ref_sub
8482
DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_sub_f32, long, in_com1, in_com2, ref_sub,
8583
ARRAY_SIZE(in_com1));
8684

87-
static void test_zdsp_mult_f32(
88-
const uint32_t *input1, const uint32_t *input2, const uint32_t *ref,
89-
size_t length)
85+
static void test_zdsp_mult_f32(const DSP_DATA uint32_t *input1, const DSP_DATA uint32_t *input2,
86+
const uint32_t *ref, size_t length)
9087
{
91-
float32_t *output;
88+
DSP_DATA float32_t *output;
9289

9390
/* Allocate output buffer */
94-
output = malloc(length * sizeof(float32_t));
91+
output = (DSP_DATA float32_t *)malloc(length * sizeof(float32_t));
9592
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
9693

9794
/* Run test function */
98-
zdsp_mult_f32((float32_t *)input1, (float32_t *)input2, output, length);
95+
zdsp_mult_f32((DSP_DATA float32_t *)input1, (DSP_DATA float32_t *)input2, output, length);
9996

10097
/* Validate output */
10198
zassert_true(
@@ -118,17 +115,17 @@ DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_mult_f32, 11, in_com1, in_com2, ref_mu
118115
DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_mult_f32, long, in_com1, in_com2, ref_mult,
119116
ARRAY_SIZE(in_com1));
120117

121-
static void test_zdsp_negate_f32(
122-
const uint32_t *input1, const uint32_t *ref, size_t length)
118+
static void test_zdsp_negate_f32(const DSP_DATA uint32_t *input1, const uint32_t *ref,
119+
size_t length)
123120
{
124-
float32_t *output;
121+
DSP_DATA float32_t *output;
125122

126123
/* Allocate output buffer */
127-
output = malloc(length * sizeof(float32_t));
124+
output = (DSP_DATA float32_t *)malloc(length * sizeof(float32_t));
128125
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
129126

130127
/* Run test function */
131-
zdsp_negate_f32((float32_t *)input1, output, length);
128+
zdsp_negate_f32((DSP_DATA float32_t *)input1, output, length);
132129

133130
/* Validate output */
134131
zassert_true(
@@ -151,18 +148,17 @@ DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_negate_f32, 11, in_com1, ref_negate, 1
151148
DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_negate_f32, long, in_com1, ref_negate,
152149
ARRAY_SIZE(in_com1));
153150

154-
static void test_zdsp_offset_f32(
155-
const uint32_t *input1, float32_t scalar, const uint32_t *ref,
156-
size_t length)
151+
static void test_zdsp_offset_f32(const DSP_DATA uint32_t *input1, float32_t scalar,
152+
const uint32_t *ref, size_t length)
157153
{
158-
float32_t *output;
154+
DSP_DATA float32_t *output;
159155

160156
/* Allocate output buffer */
161-
output = malloc(length * sizeof(float32_t));
157+
output = (DSP_DATA float32_t *)malloc(length * sizeof(float32_t));
162158
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
163159

164160
/* Run test function */
165-
zdsp_offset_f32((float32_t *)input1, scalar, output, length);
161+
zdsp_offset_f32((DSP_DATA float32_t *)input1, scalar, output, length);
166162

167163
/* Validate output */
168164
zassert_true(
@@ -185,18 +181,17 @@ DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_offset_f32, 0p5_11, in_com1, 0.5f, ref
185181
DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_offset_f32, long, in_com1, 0.5f, ref_offset,
186182
ARRAY_SIZE(in_com1));
187183

188-
static void test_zdsp_scale_f32(
189-
const uint32_t *input1, float32_t scalar, const uint32_t *ref,
190-
size_t length)
184+
static void test_zdsp_scale_f32(const DSP_DATA uint32_t *input1, float32_t scalar,
185+
const uint32_t *ref, size_t length)
191186
{
192-
float32_t *output;
187+
DSP_DATA float32_t *output;
193188

194189
/* Allocate output buffer */
195-
output = malloc(length * sizeof(float32_t));
190+
output = (DSP_DATA float32_t *)malloc(length * sizeof(float32_t));
196191
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
197192

198193
/* Run test function */
199-
zdsp_scale_f32((float32_t *)input1, scalar, output, length);
194+
zdsp_scale_f32((DSP_DATA float32_t *)input1, scalar, output, length);
200195

201196
/* Validate output */
202197
zassert_true(
@@ -219,19 +214,18 @@ DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_scale_f32, 0p5_11, in_com1, 0.5f, ref_
219214
DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_scale_f32, long, in_com1, 0.5f, ref_scale,
220215
ARRAY_SIZE(in_com1));
221216

222-
static void test_zdsp_dot_prod_f32(
223-
const uint32_t *input1, const uint32_t *input2, const uint32_t *ref,
224-
size_t length)
217+
static void test_zdsp_dot_prod_f32(const DSP_DATA uint32_t *input1, const DSP_DATA uint32_t *input2,
218+
const uint32_t *ref, size_t length)
225219
{
226-
float32_t *output;
220+
DSP_DATA float32_t *output;
227221

228222
/* Allocate output buffer */
229-
output = malloc(1 * sizeof(float32_t));
223+
output = (DSP_DATA float32_t *)malloc(1 * sizeof(float32_t));
230224
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
231225

232226
/* Run test function */
233-
zdsp_dot_prod_f32(
234-
(float32_t *)input1, (float32_t *)input2, length, &output[0]);
227+
zdsp_dot_prod_f32((DSP_DATA float32_t *)input1, (DSP_DATA float32_t *)input2, length,
228+
&output[0]);
235229

236230
/* Validate output */
237231
zassert_true(
@@ -254,17 +248,16 @@ DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_dot_prod_f32, 11, in_com1, in_com2, re
254248
DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_dot_prod_f32, long, in_com1, in_com2, ref_dot_prod_long,
255249
ARRAY_SIZE(in_com1));
256250

257-
static void test_zdsp_abs_f32(
258-
const uint32_t *input1, const uint32_t *ref, size_t length)
251+
static void test_zdsp_abs_f32(const DSP_DATA uint32_t *input1, const uint32_t *ref, size_t length)
259252
{
260-
float32_t *output;
253+
DSP_DATA float32_t *output;
261254

262255
/* Allocate output buffer */
263-
output = malloc(length * sizeof(float32_t));
256+
output = (DSP_DATA float32_t *)malloc(length * sizeof(float32_t));
264257
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
265258

266259
/* Run test function */
267-
zdsp_abs_f32((float32_t *)input1, output, length);
260+
zdsp_abs_f32((DSP_DATA float32_t *)input1, output, length);
268261

269262
/* Validate output */
270263
zassert_true(
@@ -286,17 +279,17 @@ DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_abs_f32, 8, in_com1, ref_abs, 8);
286279
DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_abs_f32, 11, in_com1, ref_abs, 11);
287280
DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_abs_f32, long, in_com1, ref_abs, ARRAY_SIZE(in_com1));
288281

289-
static void test_zdsp_clip_f32(
290-
const uint32_t *input, const uint32_t *ref, float32_t min, float32_t max, size_t length)
282+
static void test_zdsp_clip_f32(const DSP_DATA uint32_t *input, const uint32_t *ref, float32_t min,
283+
float32_t max, size_t length)
291284
{
292-
float32_t *output;
285+
DSP_DATA float32_t *output;
293286

294287
/* Allocate output buffer */
295-
output = malloc(length * sizeof(float32_t));
288+
output = (DSP_DATA float32_t *)malloc(length * sizeof(float32_t));
296289
zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
297290

298291
/* Run test function */
299-
zdsp_clip_f32((float32_t *)input, output, min, max, length);
292+
zdsp_clip_f32((DSP_DATA float32_t *)input, output, min, max, length);
300293

301294
/* Validate output */
302295
zassert_true(

tests/subsys/dsp/basicmath/src/f32.pat

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)