Skip to content

Commit b475e1f

Browse files
Siyuan Chengcarlescufi
authored andcommitted
zdsp: add ARC DSPLIB backend for zdsp
Introduce ARC DSPLIB backend zdsp library for ARC target. Add agu and restrict attributes to map with ARC DSPLIB Signed-off-by: Siyuan Cheng <[email protected]>
1 parent a0db069 commit b475e1f

File tree

10 files changed

+354
-3
lines changed

10 files changed

+354
-3
lines changed

doc/services/dsp/index.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ optimized. The status of the various architectures can be found below:
1414
============ =============
1515
Architecture Status
1616
============ =============
17-
ARC Unoptimized
17+
ARC Optimized
1818
ARM Optimized
1919
ARM64 Optimized
2020
MIPS Unoptimized
@@ -46,11 +46,13 @@ Optimizing for your architecture
4646

4747
If your architecture is showing as ``Unoptimized``, it's possible to add a new
4848
zDSP backend to better support it. To do that, a new Kconfig option should be
49-
added to `subsys/dsp/Kconfig`_ along with the required dependencies and the
49+
added to :file:`subsys/dsp/Kconfig` along with the required dependencies and the
5050
``default`` set for ``DSP_BACKEND`` Kconfig choice.
5151

5252
Next, the implementation should be added at ``subsys/dsp/<backend>/`` and
53-
linked in at `subsys/dsp/CMakeLists.txt`_.
53+
linked in at :file:`subsys/dsp/CMakeLists.txt`. To add architecture-specific attributes,
54+
its corresponding Kconfig option should be added to :file:`subsys/dsp/Kconfig` and use
55+
them to update ``DSP_DATA`` and ``DSP_STATIC_DATA`` in :file:`include/zephyr/dsp/dsp.h`.
5456

5557
API Reference
5658
*************
@@ -59,3 +61,4 @@ API Reference
5961

6062
.. _subsys/dsp/Kconfig: https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/dsp/Kconfig
6163
.. _subsys/dsp/CMakeLists.txt: https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/dsp/CMakeLists.txt
64+
.. _include/zephyr/dsp/dsp.h: https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/dsp/dsp.h

include/zephyr/dsp/dsp.h

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

20+
#ifdef CONFIG_DSP_BACKEND_HAS_AGU
21+
#define DSP_DATA __agu
22+
#else
2023
#define DSP_DATA
24+
#endif
2125

26+
#ifdef CONFIG_DSP_BACKEND_HAS_XDATA_SECTION
27+
#define DSP_STATIC_DATA DSP_DATA __attribute__((section(".Xdata")))
28+
#else
2229
#define DSP_STATIC_DATA DSP_DATA
30+
#endif
2331

2432
/**
2533
* @brief DSP Interface

soc/arc/snps_nsim/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ else()
2828
-Xshift_assist -Xfpus_div -Xfpu_mac -Xfpuda -Xfpus_mpy_slow
2929
-Xfpus_div_slow -Xbitstream -Xtimer0 -Xtimer1)
3030

31+
zephyr_ld_option_ifdef(CONFIG_SOC_NSIM_EM11D -Hlib=em9d_nrg_fpusp -Hdsplib)
32+
3133
if(CONFIG_SOC_NSIM_EM11D)
3234
set_property(GLOBAL PROPERTY z_arc_dsp_options -Xxy -Xagu_large -Hfxapi -Xdsp2
3335
-Xdsp_accshift=full -Xdsp_divsqrt=radix2 -Xdsp_complex -Xdsp_itu

subsys/dsp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
add_subdirectory_ifdef(CONFIG_DSP_BACKEND_CMSIS cmsis)
5+
add_subdirectory_ifdef(CONFIG_DSP_BACKEND_ARCMWDT arcmwdt)

subsys/dsp/Kconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ if DSP
1313
config DSP_BACKEND_HAS_STATIC
1414
bool
1515

16+
config DSP_BACKEND_HAS_AGU
17+
bool
18+
19+
config DSP_BACKEND_HAS_XDATA_SECTION
20+
bool
21+
1622
choice DSP_BACKEND
1723
prompt "DSP library backend selection"
1824
default DSP_BACKEND_CMSIS if CMSIS_DSP
25+
default DSP_BACKEND_ARCMWDT if ARC && "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "arcmwdt"
1926
default DSP_BACKEND_CUSTOM
2027

2128
config DSP_BACKEND_CMSIS
@@ -32,6 +39,17 @@ config DSP_BACKEND_CUSTOM
3239
Rely on the application to provide a custom DSP backend. The implementation should be
3340
added to the 'zdsp' build target by the application or one of its modules.
3441

42+
config DSP_BACKEND_ARCMWDT
43+
bool "Use the mwdt library as the math backend"
44+
depends on ARCMWDT_LIBC
45+
depends on CMSIS_DSP
46+
select DSP_BACKEND_HAS_STATIC
47+
select DSP_BACKEND_HAS_AGU
48+
select DSP_BACKEND_HAS_XDATA_SECTION
49+
help
50+
Implement the various zephyr DSP functions using the MWDT-DSP library. This feature
51+
requires the MetaWare toolchain and CMSIS module to be selected.
52+
3553
endchoice
3654

3755
endif # DSP

subsys/dsp/arcmwdt/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2022 Synopsys
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_include_directories(public)
5+
6+
zephyr_include_directories_ifdef(CONFIG_DSP_BACKEND_ARCMWDT
7+
${ARCMWDT_TOOLCHAIN_PATH}/MetaWare/arc/lib/src/dsp/include/
8+
)
Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
/*
2+
* Copyright (c) 2022 Synopsys
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef SUBSYS_MATH_ARC_BACKEND_PUBLIC_ZDSP_BACKEND_DSP_H_
8+
#define SUBSYS_MATH_ARC_BACKEND_PUBLIC_ZDSP_BACKEND_DSP_H_
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
/* This include MUST be done before arm_math.h so we can let the arch specific
15+
* logic set up the right #define values for arm_math.h
16+
*/
17+
#include <zephyr/kernel.h>
18+
19+
#include <arm_math.h>
20+
#include "dsplib.h"
21+
22+
static inline void zdsp_mult_q7(const DSP_DATA q7_t *src_a, const DSP_DATA q7_t *src_b,
23+
DSP_DATA q7_t *dst, uint32_t block_size)
24+
{
25+
dsp_mult_q7(src_a, src_b, dst, block_size);
26+
}
27+
static inline void zdsp_mult_q15(const DSP_DATA q15_t *src_a, const DSP_DATA q15_t *src_b,
28+
DSP_DATA q15_t *dst, uint32_t block_size)
29+
{
30+
dsp_mult_q15(src_a, src_b, dst, block_size);
31+
}
32+
static inline void zdsp_mult_q31(const DSP_DATA q31_t *src_a, const DSP_DATA q31_t *src_b,
33+
DSP_DATA q31_t *dst, uint32_t block_size)
34+
{
35+
dsp_mult_q31(src_a, src_b, dst, block_size);
36+
}
37+
static inline void zdsp_mult_f32(const DSP_DATA float32_t *src_a, const DSP_DATA float32_t *src_b,
38+
DSP_DATA float32_t *dst, uint32_t block_size)
39+
{
40+
dsp_mult_f32(src_a, src_b, dst, block_size);
41+
}
42+
43+
static inline void zdsp_add_q7(const DSP_DATA q7_t *src_a, const DSP_DATA q7_t *src_b,
44+
DSP_DATA q7_t *dst, uint32_t block_size)
45+
{
46+
dsp_add_q7(src_a, src_b, dst, block_size);
47+
}
48+
static inline void zdsp_add_q15(const DSP_DATA q15_t *src_a, const DSP_DATA q15_t *src_b,
49+
DSP_DATA q15_t *dst, uint32_t block_size)
50+
{
51+
dsp_add_q15(src_a, src_b, dst, block_size);
52+
}
53+
static inline void zdsp_add_q31(const DSP_DATA q31_t *src_a, const DSP_DATA q31_t *src_b,
54+
DSP_DATA q31_t *dst, uint32_t block_size)
55+
{
56+
dsp_add_q31(src_a, src_b, dst, block_size);
57+
}
58+
static inline void zdsp_add_f32(const DSP_DATA float32_t *src_a, const DSP_DATA float32_t *src_b,
59+
DSP_DATA float32_t *dst, uint32_t block_size)
60+
{
61+
dsp_add_f32(src_a, src_b, dst, block_size);
62+
}
63+
64+
static inline void zdsp_sub_q7(const DSP_DATA q7_t *src_a, const DSP_DATA q7_t *src_b,
65+
DSP_DATA q7_t *dst, uint32_t block_size)
66+
{
67+
dsp_sub_q7(src_a, src_b, dst, block_size);
68+
}
69+
static inline void zdsp_sub_q15(const DSP_DATA q15_t *src_a, const DSP_DATA q15_t *src_b,
70+
DSP_DATA q15_t *dst, uint32_t block_size)
71+
{
72+
dsp_sub_q15(src_a, src_b, dst, block_size);
73+
}
74+
static inline void zdsp_sub_q31(const DSP_DATA q31_t *src_a, const DSP_DATA q31_t *src_b,
75+
DSP_DATA q31_t *dst, uint32_t block_size)
76+
{
77+
dsp_sub_q31(src_a, src_b, dst, block_size);
78+
}
79+
static inline void zdsp_sub_f32(const DSP_DATA float32_t *src_a, const DSP_DATA float32_t *src_b,
80+
DSP_DATA float32_t *dst, uint32_t block_size)
81+
{
82+
dsp_sub_f32(src_a, src_b, dst, block_size);
83+
}
84+
85+
static inline void zdsp_scale_q7(const DSP_DATA q7_t *src, q7_t scale_fract, int8_t shift,
86+
DSP_DATA q7_t *dst, uint32_t block_size)
87+
{
88+
dsp_scale_q7(src, scale_fract, shift, dst, block_size);
89+
}
90+
static inline void zdsp_scale_q15(const DSP_DATA q15_t *src, q15_t scale_fract, int8_t shift,
91+
DSP_DATA q15_t *dst, uint32_t block_size)
92+
{
93+
dsp_scale_q15(src, scale_fract, shift, dst, block_size);
94+
}
95+
static inline void zdsp_scale_q31(const DSP_DATA q31_t *src, q31_t scale_fract, int8_t shift,
96+
DSP_DATA q31_t *dst, uint32_t block_size)
97+
{
98+
dsp_scale_q31(src, scale_fract, shift, dst, block_size);
99+
}
100+
101+
static inline void zdsp_scale_f32(const DSP_DATA float32_t *src, float32_t scale,
102+
DSP_DATA float32_t *dst, uint32_t block_size)
103+
{
104+
dsp_scale_f32(src, scale, dst, block_size);
105+
}
106+
107+
static inline void zdsp_abs_q7(const DSP_DATA q7_t *src, DSP_DATA q7_t *dst, uint32_t block_size)
108+
{
109+
dsp_abs_q7(src, dst, block_size);
110+
}
111+
static inline void zdsp_abs_q15(const DSP_DATA q15_t *src, DSP_DATA q15_t *dst, uint32_t block_size)
112+
{
113+
dsp_abs_q15(src, dst, block_size);
114+
}
115+
static inline void zdsp_abs_q31(const DSP_DATA q31_t *src, DSP_DATA q31_t *dst, uint32_t block_size)
116+
{
117+
dsp_abs_q31(src, dst, block_size);
118+
}
119+
static inline void zdsp_abs_f32(const DSP_DATA float32_t *src, DSP_DATA float32_t *dst,
120+
uint32_t block_size)
121+
{
122+
dsp_abs_f32(src, dst, block_size);
123+
}
124+
125+
static inline void zdsp_negate_q7(const DSP_DATA q7_t *src, DSP_DATA q7_t *dst, uint32_t block_size)
126+
{
127+
dsp_negate_q7(src, dst, block_size);
128+
}
129+
static inline void zdsp_negate_q15(const DSP_DATA q15_t *src, DSP_DATA q15_t *dst,
130+
uint32_t block_size)
131+
{
132+
dsp_negate_q15(src, dst, block_size);
133+
}
134+
static inline void zdsp_negate_q31(const DSP_DATA q31_t *src, DSP_DATA q31_t *dst,
135+
uint32_t block_size)
136+
{
137+
dsp_negate_q31(src, dst, block_size);
138+
}
139+
static inline void zdsp_negate_f32(const DSP_DATA float32_t *src, DSP_DATA float32_t *dst,
140+
uint32_t block_size)
141+
{
142+
dsp_negate_f32(src, dst, block_size);
143+
}
144+
145+
static inline void zdsp_dot_prod_q7(const DSP_DATA q7_t *src_a, const DSP_DATA q7_t *src_b,
146+
uint32_t block_size, DSP_DATA q31_t *dst)
147+
{
148+
dsp_dot_prod_q7(src_a, src_b, block_size, dst);
149+
}
150+
static inline void zdsp_dot_prod_q15(const DSP_DATA q15_t *src_a, const DSP_DATA q15_t *src_b,
151+
uint32_t block_size, DSP_DATA q63_t *dst)
152+
{
153+
dsp_dot_prod_q15(src_a, src_b, block_size, dst);
154+
}
155+
static inline void zdsp_dot_prod_q31(const DSP_DATA q31_t *src_a, const DSP_DATA q31_t *src_b,
156+
uint32_t block_size, DSP_DATA q63_t *dst)
157+
{
158+
dsp_dot_prod_q31(src_a, src_b, block_size, dst);
159+
}
160+
static inline void zdsp_dot_prod_f32(const DSP_DATA float32_t *src_a,
161+
const DSP_DATA float32_t *src_b, uint32_t block_size,
162+
DSP_DATA float32_t *dst)
163+
{
164+
dsp_dot_prod_f32(src_a, src_b, block_size, dst);
165+
}
166+
167+
static inline void zdsp_shift_q7(const DSP_DATA q7_t *src, int8_t shift_bits, DSP_DATA q7_t *dst,
168+
uint32_t block_size)
169+
{
170+
dsp_shift_q7(src, shift_bits, dst, block_size);
171+
}
172+
static inline void zdsp_shift_q15(const DSP_DATA q15_t *src, int8_t shift_bits, DSP_DATA q15_t *dst,
173+
uint32_t block_size)
174+
{
175+
dsp_shift_q15(src, shift_bits, dst, block_size);
176+
}
177+
static inline void zdsp_shift_q31(const DSP_DATA q31_t *src, int8_t shift_bits, DSP_DATA q31_t *dst,
178+
uint32_t block_size)
179+
{
180+
dsp_shift_q31(src, shift_bits, dst, block_size);
181+
}
182+
183+
static inline void zdsp_offset_q7(const DSP_DATA q7_t *src, q7_t offset, DSP_DATA q7_t *dst,
184+
uint32_t block_size)
185+
{
186+
dsp_offset_q7(src, offset, dst, block_size);
187+
}
188+
static inline void zdsp_offset_q15(const DSP_DATA q15_t *src, q15_t offset, DSP_DATA q15_t *dst,
189+
uint32_t block_size)
190+
{
191+
dsp_offset_q15(src, offset, dst, block_size);
192+
}
193+
static inline void zdsp_offset_q31(const DSP_DATA q31_t *src, q31_t offset, DSP_DATA q31_t *dst,
194+
uint32_t block_size)
195+
{
196+
dsp_offset_q31(src, offset, dst, block_size);
197+
}
198+
static inline void zdsp_offset_f32(const DSP_DATA float32_t *src, float32_t offset,
199+
DSP_DATA float32_t *dst, uint32_t block_size)
200+
{
201+
dsp_offset_f32(src, offset, dst, block_size);
202+
}
203+
204+
static inline void zdsp_clip_q7(const DSP_DATA q7_t *src, DSP_DATA q7_t *dst, q7_t low, q7_t high,
205+
uint32_t num_samples)
206+
{
207+
arm_clip_q7(src, dst, low, high, num_samples);
208+
}
209+
static inline void zdsp_clip_q15(const DSP_DATA q15_t *src, DSP_DATA q15_t *dst, q15_t low,
210+
q15_t high, uint32_t num_samples)
211+
{
212+
arm_clip_q15(src, dst, low, high, num_samples);
213+
}
214+
static inline void zdsp_clip_q31(const DSP_DATA q31_t *src, DSP_DATA q31_t *dst, q31_t low,
215+
q31_t high, uint32_t num_samples)
216+
{
217+
arm_clip_q31(src, dst, low, high, num_samples);
218+
}
219+
static inline void zdsp_clip_f32(const DSP_DATA float32_t *src, DSP_DATA float32_t *dst,
220+
float32_t low, float32_t high, uint32_t num_samples)
221+
{
222+
arm_clip_f32(src, dst, low, high, num_samples);
223+
}
224+
225+
static inline void zdsp_and_u8(const DSP_DATA uint8_t *src_a, const DSP_DATA uint8_t *src_b,
226+
DSP_DATA uint8_t *dst, uint32_t block_size)
227+
{
228+
arm_and_u8(src_a, src_b, dst, block_size);
229+
}
230+
static inline void zdsp_and_u16(const DSP_DATA uint16_t *src_a, const DSP_DATA uint16_t *src_b,
231+
DSP_DATA uint16_t *dst, uint32_t block_size)
232+
{
233+
arm_and_u16(src_a, src_b, dst, block_size);
234+
}
235+
static inline void zdsp_and_u32(const DSP_DATA uint32_t *src_a, const DSP_DATA uint32_t *src_b,
236+
DSP_DATA uint32_t *dst, uint32_t block_size)
237+
{
238+
arm_and_u32(src_a, src_b, dst, block_size);
239+
}
240+
241+
static inline void zdsp_or_u8(const DSP_DATA uint8_t *src_a, const DSP_DATA uint8_t *src_b,
242+
DSP_DATA uint8_t *dst, uint32_t block_size)
243+
{
244+
arm_or_u8(src_a, src_b, dst, block_size);
245+
}
246+
static inline void zdsp_or_u16(const DSP_DATA uint16_t *src_a, const DSP_DATA uint16_t *src_b,
247+
DSP_DATA uint16_t *dst, uint32_t block_size)
248+
{
249+
arm_or_u16(src_a, src_b, dst, block_size);
250+
}
251+
static inline void zdsp_or_u32(const DSP_DATA uint32_t *src_a, const DSP_DATA uint32_t *src_b,
252+
DSP_DATA uint32_t *dst, uint32_t block_size)
253+
{
254+
arm_or_u32(src_a, src_b, dst, block_size);
255+
}
256+
257+
static inline void zdsp_xor_u8(const DSP_DATA uint8_t *src_a, const DSP_DATA uint8_t *src_b,
258+
DSP_DATA uint8_t *dst, uint32_t block_size)
259+
{
260+
arm_xor_u8(src_a, src_b, dst, block_size);
261+
}
262+
static inline void zdsp_xor_u16(const DSP_DATA uint16_t *src_a, const DSP_DATA uint16_t *src_b,
263+
DSP_DATA uint16_t *dst, uint32_t block_size)
264+
{
265+
arm_xor_u16(src_a, src_b, dst, block_size);
266+
}
267+
static inline void zdsp_xor_u32(const DSP_DATA uint32_t *src_a, const DSP_DATA uint32_t *src_b,
268+
DSP_DATA uint32_t *dst, uint32_t block_size)
269+
{
270+
arm_xor_u32(src_a, src_b, dst, block_size);
271+
}
272+
273+
static inline void zdsp_not_u8(const DSP_DATA uint8_t *src, DSP_DATA uint8_t *dst,
274+
uint32_t block_size)
275+
{
276+
arm_not_u8(src, dst, block_size);
277+
}
278+
static inline void zdsp_not_u16(const DSP_DATA uint16_t *src, DSP_DATA uint16_t *dst,
279+
uint32_t block_size)
280+
{
281+
arm_not_u16(src, dst, block_size);
282+
}
283+
static inline void zdsp_not_u32(const DSP_DATA uint32_t *src, DSP_DATA uint32_t *dst,
284+
uint32_t block_size)
285+
{
286+
arm_not_u32(src, dst, block_size);
287+
}
288+
289+
#ifdef __cplusplus
290+
}
291+
#endif
292+
293+
#endif /* SUBSYS_MATH_ARC_BACKEND_PUBLIC_ZDSP_BACKEND_DSP_H_ */

0 commit comments

Comments
 (0)