From 5d33e022e374ac5270bacc78fc8a7ef6cdf2a43f Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Tue, 11 Oct 2022 21:58:36 -0600 Subject: [PATCH 1/3] dsp: move cmsis_dsp basicmath tests Move the tests to tests/subsys/dsp/ as they'll be a part of the Zephyr dsp subsystem. Signed-off-by: Yuval Peress --- MAINTAINERS.yml | 1 + tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/CMakeLists.txt | 2 ++ tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/prj.conf | 0 tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/f16.c | 2 +- tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/f16.pat | 0 tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/f32.c | 2 +- tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/f32.pat | 0 tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q15.c | 2 +- tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q15.pat | 0 tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q31.c | 2 +- tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q31.pat | 0 tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q7.c | 2 +- tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q7.pat | 0 tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/testcase.yaml | 0 14 files changed, 8 insertions(+), 5 deletions(-) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/CMakeLists.txt (80%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/prj.conf (100%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/f16.c (99%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/f16.pat (100%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/f32.c (99%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/f32.pat (100%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q15.c (99%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q15.pat (100%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q31.c (99%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q31.pat (100%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q7.c (99%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/src/q7.pat (100%) rename tests/{lib/cmsis_dsp => subsys/dsp}/basicmath/testcase.yaml (100%) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index d3594feaef340..bec395b67593d 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -334,6 +334,7 @@ CMSIS-DSP integration: - modules/Kconfig.cmsis_dsp - tests/benchmarks/cmsis_dsp/ - tests/lib/cmsis_dsp/ + - tests/subsys/dsp/ labels: - "area: CMSIS-DSP" diff --git a/tests/lib/cmsis_dsp/basicmath/CMakeLists.txt b/tests/subsys/dsp/basicmath/CMakeLists.txt similarity index 80% rename from tests/lib/cmsis_dsp/basicmath/CMakeLists.txt rename to tests/subsys/dsp/basicmath/CMakeLists.txt index 48754f7a8ead6..6c972fc0441c9 100644 --- a/tests/lib/cmsis_dsp/basicmath/CMakeLists.txt +++ b/tests/subsys/dsp/basicmath/CMakeLists.txt @@ -12,3 +12,5 @@ target_sources(app PRIVATE ) target_sources_ifdef(CONFIG_CMSIS_DSP_FLOAT16 app PRIVATE src/f16.c) + +target_include_directories(app PRIVATE ${ZEPHYR_BASE}/tests/lib/cmsis_dsp) diff --git a/tests/lib/cmsis_dsp/basicmath/prj.conf b/tests/subsys/dsp/basicmath/prj.conf similarity index 100% rename from tests/lib/cmsis_dsp/basicmath/prj.conf rename to tests/subsys/dsp/basicmath/prj.conf diff --git a/tests/lib/cmsis_dsp/basicmath/src/f16.c b/tests/subsys/dsp/basicmath/src/f16.c similarity index 99% rename from tests/lib/cmsis_dsp/basicmath/src/f16.c rename to tests/subsys/dsp/basicmath/src/f16.c index bfd79cb3f0dcf..fd10697e89d69 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/f16.c +++ b/tests/subsys/dsp/basicmath/src/f16.c @@ -9,7 +9,7 @@ #include #include #include -#include "../../common/test_common.h" +#include "common/test_common.h" #include "f16.pat" diff --git a/tests/lib/cmsis_dsp/basicmath/src/f16.pat b/tests/subsys/dsp/basicmath/src/f16.pat similarity index 100% rename from tests/lib/cmsis_dsp/basicmath/src/f16.pat rename to tests/subsys/dsp/basicmath/src/f16.pat diff --git a/tests/lib/cmsis_dsp/basicmath/src/f32.c b/tests/subsys/dsp/basicmath/src/f32.c similarity index 99% rename from tests/lib/cmsis_dsp/basicmath/src/f32.c rename to tests/subsys/dsp/basicmath/src/f32.c index b8f27223f3efb..c92b4703662cb 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/f32.c +++ b/tests/subsys/dsp/basicmath/src/f32.c @@ -9,7 +9,7 @@ #include #include #include -#include "../../common/test_common.h" +#include "common/test_common.h" #include "f32.pat" diff --git a/tests/lib/cmsis_dsp/basicmath/src/f32.pat b/tests/subsys/dsp/basicmath/src/f32.pat similarity index 100% rename from tests/lib/cmsis_dsp/basicmath/src/f32.pat rename to tests/subsys/dsp/basicmath/src/f32.pat diff --git a/tests/lib/cmsis_dsp/basicmath/src/q15.c b/tests/subsys/dsp/basicmath/src/q15.c similarity index 99% rename from tests/lib/cmsis_dsp/basicmath/src/q15.c rename to tests/subsys/dsp/basicmath/src/q15.c index 9c7938152ae7c..c69120cf424d1 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/q15.c +++ b/tests/subsys/dsp/basicmath/src/q15.c @@ -9,7 +9,7 @@ #include #include #include -#include "../../common/test_common.h" +#include "common/test_common.h" #include "q15.pat" diff --git a/tests/lib/cmsis_dsp/basicmath/src/q15.pat b/tests/subsys/dsp/basicmath/src/q15.pat similarity index 100% rename from tests/lib/cmsis_dsp/basicmath/src/q15.pat rename to tests/subsys/dsp/basicmath/src/q15.pat diff --git a/tests/lib/cmsis_dsp/basicmath/src/q31.c b/tests/subsys/dsp/basicmath/src/q31.c similarity index 99% rename from tests/lib/cmsis_dsp/basicmath/src/q31.c rename to tests/subsys/dsp/basicmath/src/q31.c index dd0ff26c5c04f..87b8048c27dc6 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/q31.c +++ b/tests/subsys/dsp/basicmath/src/q31.c @@ -9,7 +9,7 @@ #include #include #include -#include "../../common/test_common.h" +#include "common/test_common.h" #include "q31.pat" diff --git a/tests/lib/cmsis_dsp/basicmath/src/q31.pat b/tests/subsys/dsp/basicmath/src/q31.pat similarity index 100% rename from tests/lib/cmsis_dsp/basicmath/src/q31.pat rename to tests/subsys/dsp/basicmath/src/q31.pat diff --git a/tests/lib/cmsis_dsp/basicmath/src/q7.c b/tests/subsys/dsp/basicmath/src/q7.c similarity index 99% rename from tests/lib/cmsis_dsp/basicmath/src/q7.c rename to tests/subsys/dsp/basicmath/src/q7.c index cb9628fc3b358..dc9f3979bba6c 100644 --- a/tests/lib/cmsis_dsp/basicmath/src/q7.c +++ b/tests/subsys/dsp/basicmath/src/q7.c @@ -9,7 +9,7 @@ #include #include #include -#include "../../common/test_common.h" +#include "common/test_common.h" #include "q7.pat" diff --git a/tests/lib/cmsis_dsp/basicmath/src/q7.pat b/tests/subsys/dsp/basicmath/src/q7.pat similarity index 100% rename from tests/lib/cmsis_dsp/basicmath/src/q7.pat rename to tests/subsys/dsp/basicmath/src/q7.pat diff --git a/tests/lib/cmsis_dsp/basicmath/testcase.yaml b/tests/subsys/dsp/basicmath/testcase.yaml similarity index 100% rename from tests/lib/cmsis_dsp/basicmath/testcase.yaml rename to tests/subsys/dsp/basicmath/testcase.yaml From 8f2b7cfcb27fee3224f10acfcda7f5ce9e1792dc Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Thu, 6 Oct 2022 23:54:46 -0600 Subject: [PATCH 2/3] math: Introduce a DSP basicmath subsystem with a cmsis backend Introduce an API mirroring the CMSIS-DSP's basicmath. If CMSIS_DSP is enabled, then it will by default be used as a backend. Developers may opt into a custom backend by setting CONFIG_DSP_BACKEND_CMSIS=n. If done, the application must provide `zdsp_backend/dsp.h` and optionally implement the functions in its own .c files. Signed-off-by: Yuval Peress --- CODEOWNERS | 1 + MAINTAINERS.yml | 12 +- doc/develop/api/overview.rst | 4 + doc/services/dsp/index.rst | 61 ++ doc/services/index.rst | 1 + doc/zephyr.doxyfile.in | 1 + include/zephyr/dsp/basicmath.h | 920 +++++++++++++++++++++ include/zephyr/dsp/basicmath_f16.h | 124 +++ include/zephyr/dsp/dsp.h | 31 + include/zephyr/dsp/types.h | 71 ++ modules/Kconfig.cmsis | 2 +- modules/Kconfig.cmsis_dsp | 14 + subsys/CMakeLists.txt | 1 + subsys/Kconfig | 2 + subsys/dsp/CMakeLists.txt | 8 + subsys/dsp/Kconfig | 26 + subsys/dsp/cmsis/CMakeLists.txt | 4 + subsys/dsp/cmsis/public/zdsp_backend.h | 280 +++++++ subsys/dsp/cmsis/public/zdsp_backend_f16.h | 75 ++ west.yml | 2 +- 20 files changed, 1637 insertions(+), 3 deletions(-) create mode 100644 doc/services/dsp/index.rst create mode 100644 include/zephyr/dsp/basicmath.h create mode 100644 include/zephyr/dsp/basicmath_f16.h create mode 100644 include/zephyr/dsp/dsp.h create mode 100644 include/zephyr/dsp/types.h create mode 100644 subsys/dsp/CMakeLists.txt create mode 100644 subsys/dsp/Kconfig create mode 100644 subsys/dsp/cmsis/CMakeLists.txt create mode 100644 subsys/dsp/cmsis/public/zdsp_backend.h create mode 100644 subsys/dsp/cmsis/public/zdsp_backend_f16.h diff --git a/CODEOWNERS b/CODEOWNERS index 203fe1fa15e1c..08a4999027213 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -755,6 +755,7 @@ scripts/build/gen_image_info.py @tejlmand /subsys/debug/gdbstub.c @ceolin /subsys/dfu/ @de-nordic @nordicjm /subsys/disk/ @jfischer-no +/subsys/dsp/ @yperess /subsys/tracing/ @nashif /subsys/debug/asan_hacks.c @aescolar @daor-oti /subsys/demand_paging/ @dcpleung @nashif diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index bec395b67593d..484f6728ce01e 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -324,6 +324,17 @@ CMSIS API layer: - "area: CMSIS API Layer" - "area: Portability" +DSP subsystem: + status: maintained + maintainers: + - stephanosio + - yperess + files: + - subsys/dsp/ + - tests/subsys/dsp/ + labels: + - "area: DSP" + CMSIS-DSP integration: status: maintained maintainers: @@ -334,7 +345,6 @@ CMSIS-DSP integration: - modules/Kconfig.cmsis_dsp - tests/benchmarks/cmsis_dsp/ - tests/lib/cmsis_dsp/ - - tests/subsys/dsp/ labels: - "area: CMSIS-DSP" diff --git a/doc/develop/api/overview.rst b/doc/develop/api/overview.rst index a7836c388a466..b6f686ee6c5ce 100644 --- a/doc/develop/api/overview.rst +++ b/doc/develop/api/overview.rst @@ -316,3 +316,7 @@ between major releases are available in the :ref:`zephyr_release_notes`. * - :ref:`watchdog_api` - Stable - 1.0 + + * - :ref:`zdsp_api` + - Experimental + - 3.3 diff --git a/doc/services/dsp/index.rst b/doc/services/dsp/index.rst new file mode 100644 index 0000000000000..6ce6acf384da7 --- /dev/null +++ b/doc/services/dsp/index.rst @@ -0,0 +1,61 @@ +.. _zdsp_api: + +Digital Signal Processing (DSP) +############################### + +.. contents:: + :local: + :depth: 2 + +The DSP API provides an architecture agnostic way for signal processing. +Currently, the API will work on any architecture but will likely not be +optimized. The status of the various architectures can be found below: + ++--------------+-------------+ +| Architecture | Status | ++--------------+-------------+ +| ARC | Unoptimized | +| ARM | Optimized | +| ARM64 | Optimized | +| MIPS | Unoptimized | +| NIOS2 | Unoptimized | +| POSIX | Unoptimized | +| RISCV | Unoptimized | +| RISCV64 | Unoptimized | +| SPARC | Unoptimized | +| X86 | Unoptimized | +| XTENSA | Unoptimized | ++--------------+-------------+ + +Using zDSP +********** + +zDSP provides various backend options which are selected automatically for the +application. By default, including the CMSIS module will enable all +architectures to use the zDSP APIs. This can be done by setting:: + + CONFIG_CMSIS_DSP=y + +If your application requires some additional customization, it's possible to +enable :kconfig:option:`CONFIG_DSP_BACKEND_CUSTOM` which means that the +application is responsible for providing the implementation of the zDSP +library. + +Optimizing for your architecture +******************************** + +If your architecture is showing as ``Unoptimized``, it's possible to add a new +zDSP backend to better support it. To do that, a new Kconfig option should be +added to `subsys/dsp/Kconfig`_ along with the required dependencies and the +``default`` set for ``DSP_BACKEND`` Kconfig choice. + +Next, the implementation should be added at ``subsys/dsp//`` and +linked in at `subsys/dsp/CMakeLists.txt`_. + +API Reference +************* + +.. doxygengroup:: math_dsp + +.. _subsys/dsp/Kconfig: https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/dsp/Kconfig +.. _subsys/dsp/CMakeLists.txt: https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/dsp/CMakeLists.txt diff --git a/doc/services/index.rst b/doc/services/index.rst index 61c1695ac47c6..675edf935d590 100644 --- a/doc/services/index.rst +++ b/doc/services/index.rst @@ -10,6 +10,7 @@ OS Services crypto/index debugging/index.rst device_mgmt/index + dsp/index.rst file_system/index.rst formatted_output.rst ipc/index.rst diff --git a/doc/zephyr.doxyfile.in b/doc/zephyr.doxyfile.in index 79e3c2bf91175..600d8ac81b91e 100644 --- a/doc/zephyr.doxyfile.in +++ b/doc/zephyr.doxyfile.in @@ -2316,6 +2316,7 @@ PREDEFINED = __DOXYGEN__ \ CONFIG_ERRNO \ CONFIG_FLASH_JESD216_API \ CONFIG_FLASH_PAGE_LAYOUT \ + CONFIG_FP16 \ CONFIG_FPU \ CONFIG_FPU_SHARING \ CONFIG_GDBSTUB \ diff --git a/include/zephyr/dsp/basicmath.h b/include/zephyr/dsp/basicmath.h new file mode 100644 index 0000000000000..0128b3c727d12 --- /dev/null +++ b/include/zephyr/dsp/basicmath.h @@ -0,0 +1,920 @@ +/* Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file zephyr/dsp/basicmath.h + * + * @brief Public APIs for DSP basicmath + */ + +#ifndef INCLUDE_ZEPHYR_DSP_BASICMATH_H_ +#define INCLUDE_ZEPHYR_DSP_BASICMATH_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup math_dsp + * @defgroup math_dsp_basic Basic Math Functions + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_mult Vector Multiplication + * + * Element-by-element multiplication of two vectors. + *
+ *     dst[n] = src_a[n] * src_b[n],   0 <= n < block_size.
+ * 
+ * There are separate functions for floating-point, Q7, Q15, and Q31 data types. + * @{ + */ + +/** + * @brief Q7 vector multiplication. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q7 range [0x80 0x7F] are saturated. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_mult_q7(const q7_t *src_a, const q7_t *src_b, q7_t *dst, + uint32_t block_size); + +/** + * @brief Q15 vector multiplication. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_mult_q15(const q15_t *src_a, const q15_t *src_b, q15_t *dst, + uint32_t block_size); + +/** + * @brief Q31 vector multiplication. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] are saturated. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_mult_q31(const q31_t *src_a, const q31_t *src_b, q31_t *dst, + uint32_t block_size); + +/** + * @brief Floating-point vector multiplication. + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_mult_f32(const float32_t *src_a, const float32_t *src_b, float32_t *dst, + uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_add Vector Addition + * + * Element-by-element addition of two vectors. + *
+ *     dst[n] = src_a[n] + src_b[n],   0 <= n < block_size.
+ * 
+ * There are separate functions for floating-point, Q7, Q15, and Q31 data types. + * @{ + */ + +/** + * @brief Floating-point vector addition. + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_add_f32(const float32_t *src_a, const float32_t *src_b, float32_t *dst, + uint32_t block_size); + +/** + * @brief Q7 vector addition. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q7 range [0x80 0x7F] are saturated. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_add_q7(const q7_t *src_a, const q7_t *src_b, q7_t *dst, + uint32_t block_size); + +/** + * @brief Q15 vector addition. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_add_q15(const q15_t *src_a, const q15_t *src_b, q15_t *dst, + uint32_t block_size); + +/** + * @brief Q31 vector addition. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_add_q31(const q31_t *src_a, const q31_t *src_b, q31_t *dst, + uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_sub Vector Subtraction + * + * Element-by-element subtraction of two vectors. + *
+ *     dst[n] = src_a[n] - src_b[n],   0 <= n < block_size.
+ * 
+ * There are separate functions for floating-point, Q7, Q15, and Q31 data types. + * @{ + */ + +/** + * @brief Floating-point vector subtraction. + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_sub_f32(const float32_t *src_a, const float32_t *src_b, float32_t *dst, + uint32_t block_size); + +/** + * @brief Q7 vector subtraction. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q7 range [0x80 0x7F] will be saturated. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_sub_q7(const q7_t *src_a, const q7_t *src_b, q7_t *dst, + uint32_t block_size); + +/** + * @brief Q15 vector subtraction. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_sub_q15(const q15_t *src_a, const q15_t *src_b, q15_t *dst, + uint32_t block_size); + +/** + * @brief Q31 vector subtraction. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_sub_q31(const q31_t *src_a, const q31_t *src_b, q31_t *dst, + uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_scale Vector Scale + * + * Multiply a vector by a scalar value. For floating-point data, the algorithm used is: + *
+ *     dst[n] = src[n] * scale,   0 <= n < block_size.
+ * 
+ * + * In the fixed-point Q7, Q15, and Q31 functions, scale is represented by a fractional + * multiplication scale_fract and an arithmetic shift shift. The shift + * allows the gain of the scaling operation to exceed 1.0. The algorithm used with fixed-point data + * is: + *
+ *     dst[n] = (src[n] * scale_fract) << shift,   0 <= n < block_size.
+ * 
+ * + * The overall scale factor applied to the fixed-point data is + *
+ *     scale = scale_fract * 2^shift.
+ * 
+ * The functions support in-place computation allowing the source and destination pointers to + * reference the same memory buffer. + * @{ + */ + +/** + * @brief Multiplies a floating-point vector by a scalar. + * @param[in] src points to the input vector + * @param[in] scale scale factor to be applied + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_scale_f32(const float32_t *src, float32_t scale, float32_t *dst, + uint32_t block_size); + +/** + * @brief Multiplies a Q7 vector by a scalar. + * + * @par Scaling and Overflow Behavior + * The input data *src and scale_fract are in 1.7 format. + * These are multiplied to yield a 2.14 intermediate result and this is shifted with saturation to + * 1.7 format. + * + * @param[in] src points to the input vector + * @param[in] scale_fract fractional portion of the scale value + * @param[in] shift number of bits to shift the result by + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_scale_q7(const q7_t *src, q7_t scale_fract, int8_t shift, q7_t *dst, + uint32_t block_size); + +/** + * @brief Multiplies a Q15 vector by a scalar. + * + * @par Scaling and Overflow Behavior + * The input data *src and scale_fract are in 1.15 format. + * These are multiplied to yield a 2.30 intermediate result and this is shifted with saturation to + * 1.15 format. + * + * @param[in] src points to the input vector + * @param[in] scale_fract fractional portion of the scale value + * @param[in] shift number of bits to shift the result by + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_scale_q15(const q15_t *src, q15_t scale_fract, int8_t shift, q15_t *dst, + uint32_t block_size); + +/** + * @brief Multiplies a Q31 vector by a scalar. + * + * @par Scaling and Overflow Behavior + * The input data *src and scale_fract are in 1.31 format. + * These are multiplied to yield a 2.62 intermediate result and this is shifted with saturation to + * 1.31 format. + * + * @param[in] src points to the input vector + * @param[in] scale_fract fractional portion of the scale value + * @param[in] shift number of bits to shift the result by + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_scale_q31(const q31_t *src, q31_t scale_fract, int8_t shift, q31_t *dst, + uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_abs Vector Absolute Value + * + * Computes the absolute value of a vector on an element-by-element basis. + *
+ *     dst[n] = abs(src[n]),   0 <= n < block_size.
+ * 
+ * The functions support in-place computation allowing the source and destination pointers to + * reference the same memory buffer. There are separate functions for floating-point, Q7, Q15, and + * Q31 data types. + * @{ + */ + +/** + * @brief Floating-point vector absolute value. + * @param[in] src points to the input buffer + * @param[out] dst points to the output buffer + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_abs_f32(const float32_t *src, float32_t *dst, uint32_t block_size); + +/** + * @brief Q7 vector absolute value. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * The Q7 value -1 (0x80) will be saturated to the maximum allowable positive value 0x7F. + * + * @param[in] src points to the input buffer + * @param[out] dst points to the output buffer + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_abs_q7(const q7_t *src, q7_t *dst, uint32_t block_size); + +/** + * @brief Q15 vector absolute value. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * The Q15 value -1 (0x8000) will be saturated to the maximum allowable positive value 0x7FFF. + * + * @param[in] src points to the input buffer + * @param[out] dst points to the output buffer + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_abs_q15(const q15_t *src, q15_t *dst, uint32_t block_size); + +/** + * @brief Q31 vector absolute value. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * The Q31 value -1 (0x80000000) will be saturated to the maximum allowable positive value + * 0x7FFFFFFF. + * + * @param[in] src points to the input buffer + * @param[out] dst points to the output buffer + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_abs_q31(const q31_t *src, q31_t *dst, uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_dot Vector Dot Product + * + * Computes the dot product of two vectors. The vectors are multiplied element-by-element and then + * summed. + *
+ *     sum = src_a[0]*src_b[0] + src_a[1]*src_b[1] + ... + src_a[block_size-1]*src_b[block_size-1]
+ * 
+ * There are separate functions for floating-point, Q7, Q15, and Q31 data types. + * @{ + */ + +/** + * @brief Dot product of floating-point vectors. + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[in] block_size number of samples in each vector + * @param[out] result output result returned here + */ +DSP_FUNC_SCOPE void zdsp_dot_prod_f32(const float32_t *src_a, const float32_t *src_b, + uint32_t block_size, float32_t *result); + +/** + * @brief Dot product of Q7 vectors. + * + * @par Scaling and Overflow Behavior + * The intermediate multiplications are in 1.7 x 1.7 = 2.14 format and these results are added to + * an accumulator in 18.14 format. Nonsaturating additions are used and there is no danger of wrap + * around as long as the vectors are less than 2^18 elements long. The return result is in 18.14 + * format. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[in] block_size number of samples in each vector + * @param[out] result output result returned here + */ +DSP_FUNC_SCOPE void zdsp_dot_prod_q7(const q7_t *src_a, const q7_t *src_b, uint32_t block_size, + q31_t *result); + +/** + * @brief Dot product of Q15 vectors. + * + * @par Scaling and Overflow Behavior + * The intermediate multiplications are in 1.15 x 1.15 = 2.30 format and these results are added + * to a 64-bit accumulator in 34.30 format. Nonsaturating additions are used and given that there + * are 33 guard bits in the accumulator there is no risk of overflow. The return result is in + * 34.30 format. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[in] block_size number of samples in each vector + * @param[out] result output result returned here + */ +DSP_FUNC_SCOPE void zdsp_dot_prod_q15(const q15_t *src_a, const q15_t *src_b, uint32_t block_size, + q63_t *result); + +/** + * @brief Dot product of Q31 vectors. + * + * @par Scaling and Overflow Behavior + * The intermediate multiplications are in 1.31 x 1.31 = 2.62 format and these are truncated to + * 2.48 format by discarding the lower 14 bits. The 2.48 result is then added without saturation + * to a 64-bit accumulator in 16.48 format. There are 15 guard bits in the accumulator and there + * is no risk of overflow as long as the length of the vectors is less than 2^16 elements. The + * return result is in 16.48 format. + * + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[in] block_size number of samples in each vector + * @param[out] result output result returned here + */ +DSP_FUNC_SCOPE void zdsp_dot_prod_q31(const q31_t *src_a, const q31_t *src_b, uint32_t block_size, + q63_t *result); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_shift Vector Shift + * + * Shifts the elements of a fixed-point vector by a specified number of bits. + * There are separate functions for Q7, Q15, and Q31 data types. The underlying algorithm used is: + *
+ *     dst[n] = src[n] << shift,   0 <= n < block_size.
+ * 
+ * If shift is positive then the elements of the vector are shifted to the left. + * If shift is negative then the elements of the vector are shifted to the right. + * + * The functions support in-place computation allowing the source and destination pointers to + * reference the same memory buffer. + * @{ + */ + +/** + * @brief Shifts the elements of a Q7 vector a specified number of bits. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q7 range [0x80 0x7F] are saturated. + * + * @param[in] src points to the input vector + * @param[in] shift_bits number of bits to shift. A positive value shifts left; a negative value + * shifts right. + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_shift_q7(const q7_t *src, int8_t shift_bits, q7_t *dst, + uint32_t block_size); + +/** + * @brief Shifts the elements of a Q15 vector a specified number of bits. + * + * @pre Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated. + * + * @param[in] src points to the input vector + * @param[in] shift_bits number of bits to shift. A positive value shifts left; a negative value + * shifts right. + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_shift_q15(const q15_t *src, int8_t shift_bits, q15_t *dst, + uint32_t block_size); + +/** + * @brief Shifts the elements of a Q31 vector a specified number of bits. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated. + * + * @param[in] src points to the input vector + * @param[in] shift_bits number of bits to shift. A positive value shifts left; a negative value + * shifts right. + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_shift_q31(const q31_t *src, int8_t shift_bits, q31_t *dst, + uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_offset Vector Offset + * + * Adds a constant offset to each element of a vector. + *
+ *     dst[n] = src[n] + offset,   0 <= n < block_size.
+ * 
+ * The functions support in-place computation allowing the source and destination pointers to + * reference the same memory buffer. There are separate functions for floating-point, Q7, Q15, and + * Q31 data types. + * + * @{ + */ + +/** + * @brief Adds a constant offset to a floating-point vector. + * @param[in] src points to the input vector + * @param[in] offset is the offset to be added + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_offset_f32(const float32_t *src, float32_t offset, float32_t *dst, + uint32_t block_size); + +/** + * @brief Adds a constant offset to a Q7 vector. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q7 range [0x80 0x7F] are saturated. + * + * @param[in] src points to the input vector + * @param[in] offset is the offset to be added + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_offset_q7(const q7_t *src, q7_t offset, q7_t *dst, uint32_t block_size); + +/** + * @brief Adds a constant offset to a Q15 vector. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated. + * + * @param[in] src points to the input vector + * @param[in] offset is the offset to be added + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_offset_q15(const q15_t *src, q15_t offset, q15_t *dst, + uint32_t block_size); + +/** + * @brief Adds a constant offset to a Q31 vector. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated. + * + * @param[in] src points to the input vector + * @param[in] offset is the offset to be added + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_offset_q31(const q31_t *src, q31_t offset, q31_t *dst, + uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_negate Vector Negate + * + * Negates the elements of a vector. + *
+ *     dst[n] = -src[n],   0 <= n < block_size.
+ * 
+ * The functions support in-place computation allowing the source and destination pointers to + * reference the same memory buffer. There are separate functions for floating-point, Q7, Q15, and + * Q31 data types. + * + * @{ + */ + +/** + * @brief Negates the elements of a floating-point vector. + * @param[in] src points to the input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_negate_f32(const float32_t *src, float32_t *dst, uint32_t block_size); + +/** + * @brief Negates the elements of a Q7 vector. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * The Q7 value -1 (0x80) is saturated to the maximum allowable positive value 0x7F. + * + * @param[in] src points to the input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_negate_q7(const q7_t *src, q7_t *dst, uint32_t block_size); + +/** + * @brief Negates the elements of a Q15 vector. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * The Q15 value -1 (0x8000) is saturated to the maximum allowable positive value 0x7FFF. + * + * @param[in] src points to the input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_negate_q15(const q15_t *src, q15_t *dst, uint32_t block_size); + +/** + * @brief Negates the elements of a Q31 vector. + * + * @par Scaling and Overflow Behavior + * The function uses saturating arithmetic. + * The Q31 value -1 (0x80000000) is saturated to the maximum allowable positive value 0x7FFFFFFF. + * + * @param[in] src points to the input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_negate_q31(const q31_t *src, q31_t *dst, uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_and Vector bitwise AND + * + * Compute the logical bitwise AND. + * + * There are separate functions for uint32_t, uint16_t, and uint7_t data types. + * @{ + */ + +/** + * @brief Compute the logical bitwise AND of two fixed-point vectors. + * @param[in] src_a points to input vector A + * @param[in] src_b points to input vector B + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_and_u8(const uint8_t *src_a, const uint8_t *src_b, uint8_t *dst, + uint32_t block_size); + +/** + * @brief Compute the logical bitwise AND of two fixed-point vectors. + * @param[in] src_a points to input vector A + * @param[in] src_b points to input vector B + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_and_u16(const uint16_t *src_a, const uint16_t *src_b, uint16_t *dst, + uint32_t block_size); + +/** + * @brief Compute the logical bitwise AND of two fixed-point vectors. + * @param[in] src_a points to input vector A + * @param[in] src_b points to input vector B + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_and_u32(const uint32_t *src_a, const uint32_t *src_b, uint32_t *dst, + uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_or Vector bitwise OR + * + * Compute the logical bitwise OR. + * + * There are separate functions for uint32_t, uint16_t, and uint7_t data types. + * @{ + */ + +/** + * @brief Compute the logical bitwise OR of two fixed-point vectors. + * @param[in] src_a points to input vector A + * @param[in] src_b points to input vector B + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_or_u8(const uint8_t *src_a, const uint8_t *src_b, uint8_t *dst, + uint32_t block_size); + +/** + * @brief Compute the logical bitwise OR of two fixed-point vectors. + * @param[in] src_a points to input vector A + * @param[in] src_b points to input vector B + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_or_u16(const uint16_t *src_a, const uint16_t *src_b, uint16_t *dst, + uint32_t block_size); + +/** + * @brief Compute the logical bitwise OR of two fixed-point vectors. + * @param[in] src_a points to input vector A + * @param[in] src_b points to input vector B + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_or_u32(const uint32_t *src_a, const uint32_t *src_b, uint32_t *dst, + uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_not Vector bitwise NOT + * + * Compute the logical bitwise NOT. + * + * There are separate functions for uint32_t, uint16_t, and uint7_t data types. + * @{ + */ + +/** + * @brief Compute the logical bitwise NOT of a fixed-point vector. + * @param[in] src points to input vector + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_not_u8(const uint8_t *src, uint8_t *dst, uint32_t block_size); + +/** + * @brief Compute the logical bitwise NOT of a fixed-point vector. + * @param[in] src points to input vector + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_not_u16(const uint16_t *src, uint16_t *dst, uint32_t block_size); + +/** + * @brief Compute the logical bitwise NOT of a fixed-point vector. + * @param[in] src points to input vector + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_not_u32(const uint32_t *src, uint32_t *dst, uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_xor Vector bitwise XOR + * + * Compute the logical bitwise XOR. + * + * There are separate functions for uint32_t, uint16_t, and uint7_t data types. + * @{ + */ + +/** + * @brief Compute the logical bitwise XOR of two fixed-point vectors. + * @param[in] src_a points to input vector A + * @param[in] src_b points to input vector B + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_xor_u8(const uint8_t *src_a, const uint8_t *src_b, uint8_t *dst, + uint32_t block_size); + +/** + * @brief Compute the logical bitwise XOR of two fixed-point vectors. + * @param[in] src_a points to input vector A + * @param[in] src_b points to input vector B + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_xor_u16(const uint16_t *src_a, const uint16_t *src_b, uint16_t *dst, + uint32_t block_size); + +/** + * @brief Compute the logical bitwise XOR of two fixed-point vectors. + * @param[in] src_a points to input vector A + * @param[in] src_b points to input vector B + * @param[out] dst points to output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_xor_u32(const uint32_t *src_a, const uint32_t *src_b, uint32_t *dst, + uint32_t block_size); + +/** + * @} + */ + +/** + * @ingroup math_dsp_basic + * @addtogroup math_dsp_basic_clip Vector Clipping + * + * Element-by-element clipping of a value. + * + * The value is constrained between 2 bounds. + * + * There are separate functions for floating-point, Q7, Q15, and Q31 data types. + * @{ + */ + +/** + * @brief Elementwise floating-point clipping + * @param[in] src points to input values + * @param[out] dst points to output clipped values + * @param[in] low lower bound + * @param[in] high higher bound + * @param[in] num_samples number of samples to clip + */ +DSP_FUNC_SCOPE void zdsp_clip_f32(const float32_t *src, float32_t *dst, float32_t low, + float32_t high, uint32_t num_samples); + +/** + * @brief Elementwise fixed-point clipping + * @param[in] src points to input values + * @param[out] dst points to output clipped values + * @param[in] low lower bound + * @param[in] high higher bound + * @param[in] num_samples number of samples to clip + */ +DSP_FUNC_SCOPE void zdsp_clip_q31(const q31_t *src, q31_t *dst, q31_t low, q31_t high, + uint32_t num_samples); + +/** + * @brief Elementwise fixed-point clipping + * @param[in] src points to input values + * @param[out] dst points to output clipped values + * @param[in] low lower bound + * @param[in] high higher bound + * @param[in] num_samples number of samples to clip + */ +DSP_FUNC_SCOPE void zdsp_clip_q15(const q15_t *src, q15_t *dst, q15_t low, q15_t high, + uint32_t num_samples); + +/** + * @brief Elementwise fixed-point clipping + * @param[in] src points to input values + * @param[out] dst points to output clipped values + * @param[in] low lower bound + * @param[in] high higher bound + * @param[in] num_samples number of samples to clip + */ +DSP_FUNC_SCOPE void zdsp_clip_q7(const q7_t *src, q7_t *dst, q7_t low, q7_t high, + uint32_t num_samples); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#ifdef CONFIG_FP16 +#include +#endif /* CONFIG_FP16 */ + +#endif /* INCLUDE_ZEPHYR_DSP_BASICMATH_H_ */ diff --git a/include/zephyr/dsp/basicmath_f16.h b/include/zephyr/dsp/basicmath_f16.h new file mode 100644 index 0000000000000..23239e9a65980 --- /dev/null +++ b/include/zephyr/dsp/basicmath_f16.h @@ -0,0 +1,124 @@ +/* Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file zephyr/dsp/basicmath_f16.h + * + * @brief Public APIs for DSP basicmath for 16 bit floating point + */ + +#ifndef INCLUDE_ZEPHYR_DSP_BASICMATH_F16_H_ +#define INCLUDE_ZEPHYR_DSP_BASICMATH_F16_H_ + +#ifndef CONFIG_FP16 +#error "Cannot use float16 DSP functionality without CONFIG_FP16 enabled" +#endif /* CONFIG_FP16 */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup math_dsp_basic_mult + * @brief Floating-point vector multiplication. + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_mult_f16(const float16_t *src_a, const float16_t *src_b, float16_t *dst, + uint32_t block_size); + +/** + * @ingroup math_dsp_basic_add + * @brief Floating-point vector addition. + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_add_f16(const float16_t *src_a, const float16_t *src_b, float16_t *dst, + uint32_t block_size); + +/** + * @ingroup math_dsp_basic_sub + * @brief Floating-point vector subtraction. + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_sub_f16(const float16_t *src_a, const float16_t *src_b, float16_t *dst, + uint32_t block_size); + +/** + * @ingroup math_dsp_basic_scale + * @brief Multiplies a floating-point vector by a scalar. + * @param[in] src points to the input vector + * @param[in] scale scale factor to be applied + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_scale_f16(const float16_t *src, float16_t scale, float16_t *dst, + uint32_t block_size); + +/** + * @ingroup math_dsp_basic_abs + * @brief Floating-point vector absolute value. + * @param[in] src points to the input buffer + * @param[out] dst points to the output buffer + * @param[in] block_size number of samples in each vector + */ +DSP_FUNC_SCOPE void zdsp_abs_f16(const float16_t *src, float16_t *dst, uint32_t block_size); + +/** + * @ingroup math_dsp_basic_dot + * @brief Dot product of floating-point vectors. + * @param[in] src_a points to the first input vector + * @param[in] src_b points to the second input vector + * @param[in] block_size number of samples in each vector + * @param[out] result output result returned here + */ +DSP_FUNC_SCOPE void zdsp_dot_prod_f16(const float16_t *src_a, const float16_t *src_b, + uint32_t block_size, float16_t *result); + +/** + * @ingroup math_dsp_basic_offset + * @brief Adds a constant offset to a floating-point vector. + * @param[in] src points to the input vector + * @param[in] offset is the offset to be added + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_offset_f16(const float16_t *src, float16_t offset, float16_t *dst, + uint32_t block_size); + +/** + * @ingroup math_dsp_basic_negate + * @brief Negates the elements of a floating-point vector. + * @param[in] src points to the input vector + * @param[out] dst points to the output vector + * @param[in] block_size number of samples in the vector + */ +DSP_FUNC_SCOPE void zdsp_negate_f16(const float16_t *src, float16_t *dst, uint32_t block_size); + +/** + * @ingroup math_dsp_basic_clip + * @brief Elementwise floating-point clipping + * @param[in] src points to input values + * @param[out] dst points to output clipped values + * @param[in] low lower bound + * @param[in] high higher bound + * @param[in] num_samples number of samples to clip + */ +DSP_FUNC_SCOPE void zdsp_clip_f16(const float16_t *src, float16_t *dst, float16_t low, + float16_t high, uint32_t num_samples); + +#ifdef __cplusplus +} +#endif + +#endif /* INCLUDE_ZEPHYR_DSP_BASICMATH_F16_H_ */ diff --git a/include/zephyr/dsp/dsp.h b/include/zephyr/dsp/dsp.h new file mode 100644 index 0000000000000..09c757216b13a --- /dev/null +++ b/include/zephyr/dsp/dsp.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2022 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file zephyr/dsp/dsp.h + * + * @brief Public APIs for Digital Signal Processing (DSP) math. + */ + +#ifndef INCLUDE_ZEPHYR_DSP_DSP_H_ +#define INCLUDE_ZEPHYR_DSP_DSP_H_ + +#ifdef CONFIG_DSP_BACKEND_HAS_STATIC +#define DSP_FUNC_SCOPE static +#else +#define DSP_FUNC_SCOPE +#endif + +/** + * @brief DSP Interface + * @defgroup math_dsp DSP Interface + */ + +#include + +#include + +#include "zdsp_backend.h" + +#endif /* INCLUDE_ZEPHYR_DSP_DSP_H_ */ diff --git a/include/zephyr/dsp/types.h b/include/zephyr/dsp/types.h new file mode 100644 index 0000000000000..52ce2ab20372c --- /dev/null +++ b/include/zephyr/dsp/types.h @@ -0,0 +1,71 @@ +/* Copyright (c) 2022 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef INCLUDE_ZEPHYR_DSP_TYPES_H_ +#define INCLUDE_ZEPHYR_DSP_TYPES_H_ + +#include + +/** + * @addtogroup math_dsp + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @typedef q7_t + * @brief 8-bit fractional data type in 1.7 format. + */ +typedef int8_t q7_t; + +/** + * @typedef q15_t + * @brief 16-bit fractional data type in 1.15 format. + */ +typedef int16_t q15_t; + +/** + * @typedef q31_t + * @brief 32-bit fractional data type in 1.31 format. + */ +typedef int32_t q31_t; + +/** + * @typedef q63_t + * @brief 64-bit fractional data type in 1.63 format. + */ +typedef int64_t q63_t; + +/** + * @typedef float16_t + * @brief 16-bit floating point type definition. + */ +#if defined(CONFIG_FP16) +typedef __fp16 float16_t; +#endif /* CONFIG_FP16 */ + +/** + * @typedef float32_t + * @brief 32-bit floating-point type definition. + */ +typedef float float32_t; + +/** + * @typedef float64_t + * @brief 64-bit floating-point type definition. + */ +typedef double float64_t; + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* INCLUDE_ZEPHYR_DSP_TYPES_H_ */ diff --git a/modules/Kconfig.cmsis b/modules/Kconfig.cmsis index 19ab657e668f5..c14870c1429a2 100644 --- a/modules/Kconfig.cmsis +++ b/modules/Kconfig.cmsis @@ -22,7 +22,7 @@ endif menuconfig CMSIS_DSP bool "CMSIS-DSP Library Support" - depends on (CPU_CORTEX && NEWLIB_LIBC) || ARCH_POSIX + depends on NEWLIB_LIBC || ARCH_POSIX if CMSIS_DSP source "modules/Kconfig.cmsis_dsp" diff --git a/modules/Kconfig.cmsis_dsp b/modules/Kconfig.cmsis_dsp index 86704b392abbf..6b5f936ccc3e0 100644 --- a/modules/Kconfig.cmsis_dsp +++ b/modules/Kconfig.cmsis_dsp @@ -29,6 +29,7 @@ config CMSIS_DSP_BASICMATH config CMSIS_DSP_COMPLEXMATH bool "Complex Math Functions" imply CMSIS_DSP_FASTMATH + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Complex Math Functions, which support the following operations: @@ -42,6 +43,7 @@ config CMSIS_DSP_COMPLEXMATH config CMSIS_DSP_CONTROLLER bool "Controller Functions" + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Controller Functions, which support the following operations: @@ -61,6 +63,7 @@ config CMSIS_DSP_FASTMATH bool "Fast Math Functions" select CMSIS_DSP_TABLES imply CMSIS_DSP_TABLES_ALL_FAST + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Fast Math Functions, which support the following operations: @@ -74,6 +77,7 @@ config CMSIS_DSP_FILTERING bool "Filtering Functions" imply CMSIS_DSP_FASTMATH imply CMSIS_DSP_SUPPORT + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Filtering Functions, which support the following operations: @@ -99,6 +103,7 @@ config CMSIS_DSP_FILTERING config CMSIS_DSP_INTERPOLATION bool "Interpolation Functions" + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Interpolation Functions, which support the following operations: @@ -109,6 +114,7 @@ config CMSIS_DSP_INTERPOLATION config CMSIS_DSP_MATRIX bool "Matrix Functions" + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Matrix Functions, which support the following operations: @@ -127,6 +133,7 @@ config CMSIS_DSP_MATRIX config CMSIS_DSP_QUATERNIONMATH bool "Quaternion Math Functions" + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Quaternion Math Functions, which support the following operations: @@ -142,6 +149,7 @@ config CMSIS_DSP_STATISTICS bool "Statistics Functions" imply CMSIS_DSP_BASICMATH imply CMSIS_DSP_FASTMATH + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Statistics Functions, which support the following operations: @@ -161,6 +169,7 @@ config CMSIS_DSP_STATISTICS config CMSIS_DSP_SUPPORT bool "Support Functions" + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Support Functions, which support the following operations: @@ -180,6 +189,7 @@ config CMSIS_DSP_TRANSFORM bool "Transform Functions" select CMSIS_DSP_TABLES imply CMSIS_DSP_TABLES_ALL_FFT + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Transform Functions, which support the following transformations: @@ -191,6 +201,7 @@ config CMSIS_DSP_TRANSFORM config CMSIS_DSP_SVM bool "Support Vector Machine Functions" select CMSIS_DSP_TABLES + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Support Vector Machine Functions, which support the following algorithms: @@ -203,6 +214,7 @@ config CMSIS_DSP_SVM config CMSIS_DSP_BAYES bool "Bayesian Estimators" imply CMSIS_DSP_STATISTICS + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Bayesian Estimator Functions, which implements the naive gaussian Bayes estimator. @@ -210,6 +222,7 @@ config CMSIS_DSP_BAYES config CMSIS_DSP_DISTANCE bool "Distance Functions" imply CMSIS_DSP_STATISTICS + depends on CPU_CORTEX || ARCH_POSIX help This option enables the Distance Functions, which support the following distance computation algorithms: @@ -238,6 +251,7 @@ config CMSIS_DSP_DISTANCE menuconfig CMSIS_DSP_TABLES bool "Look-up Tables" + depends on CPU_CORTEX || ARCH_POSIX help This option enables the static look-up tables used by the DSP functions to compute results. diff --git a/subsys/CMakeLists.txt b/subsys/CMakeLists.txt index a7f385cc545f7..44d1f82eab887 100644 --- a/subsys/CMakeLists.txt +++ b/subsys/CMakeLists.txt @@ -19,6 +19,7 @@ add_subdirectory(random) add_subdirectory(storage) add_subdirectory_ifdef(CONFIG_SETTINGS settings) add_subdirectory(fb) +add_subdirectory(dsp) add_subdirectory(portability) add_subdirectory(pm) add_subdirectory(stats) diff --git a/subsys/Kconfig b/subsys/Kconfig index a37bd623d58bb..d34b5acee449e 100644 --- a/subsys/Kconfig +++ b/subsys/Kconfig @@ -32,6 +32,8 @@ source "subsys/logging/Kconfig" source "subsys/lorawan/Kconfig" +source "subsys/dsp/Kconfig" + source "subsys/mgmt/Kconfig" source "subsys/modbus/Kconfig" diff --git a/subsys/dsp/CMakeLists.txt b/subsys/dsp/CMakeLists.txt new file mode 100644 index 0000000000000..a8ebd0ca92162 --- /dev/null +++ b/subsys/dsp/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (c) 2022 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library_named(zdsp) + +add_subdirectory_ifdef(CONFIG_DSP_BACKEND_CMSIS cmsis) + +zephyr_link_libraries(zdsp) diff --git a/subsys/dsp/Kconfig b/subsys/dsp/Kconfig new file mode 100644 index 0000000000000..e053d9f6a38db --- /dev/null +++ b/subsys/dsp/Kconfig @@ -0,0 +1,26 @@ +# Copyright (c) 2022 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +config DSP_BACKEND_HAS_STATIC + bool + +choice DSP_BACKEND + prompt "DSP library backend selection" + default DSP_BACKEND_CMSIS if CMSIS_DSP + default DSP_BACKEND_CUSTOM + +config DSP_BACKEND_CMSIS + bool "Use the CMSIS-DSP library as the math backend" + depends on CMSIS_DSP + select DSP_BACKEND_HAS_STATIC + help + Implement the various zephyr DSP functions using the CMSIS-DSP library. This feature + requires the CMSIS module to be selected. + +config DSP_BACKEND_CUSTOM + bool "Do not use any Zephyr backends for DSP" + help + Rely on the application to provide a custom DSP backend. The implementation should be + added to the 'zdsp' build target by the application or one of its modules. + +endchoice diff --git a/subsys/dsp/cmsis/CMakeLists.txt b/subsys/dsp/cmsis/CMakeLists.txt new file mode 100644 index 0000000000000..c2b1bc0e6f278 --- /dev/null +++ b/subsys/dsp/cmsis/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2022 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +target_include_directories(zdsp PUBLIC public) diff --git a/subsys/dsp/cmsis/public/zdsp_backend.h b/subsys/dsp/cmsis/public/zdsp_backend.h new file mode 100644 index 0000000000000..39a9d6d4abefd --- /dev/null +++ b/subsys/dsp/cmsis/public/zdsp_backend.h @@ -0,0 +1,280 @@ +/* Copyright (c) 2022 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef SUBSYS_MATH_CMSIS_BACKEND_PUBLIC_ZDSP_BACKEND_DSP_H_ +#define SUBSYS_MATH_CMSIS_BACKEND_PUBLIC_ZDSP_BACKEND_DSP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* This include MUST be done before arm_math.h so we can let the arch specific + * logic set up the right #define values for arm_math.h + */ +#include + +#include + +static inline void zdsp_mult_q7(const q7_t *src_a, const q7_t *src_b, q7_t *dst, + uint32_t block_size) +{ + arm_mult_q7(src_a, src_b, dst, block_size); +} +static inline void zdsp_mult_q15(const q15_t *src_a, const q15_t *src_b, q15_t *dst, + uint32_t block_size) +{ + arm_mult_q15(src_a, src_b, dst, block_size); +} +static inline void zdsp_mult_q31(const q31_t *src_a, const q31_t *src_b, q31_t *dst, + uint32_t block_size) +{ + arm_mult_q31(src_a, src_b, dst, block_size); +} +static inline void zdsp_mult_f32(const float32_t *src_a, const float32_t *src_b, float32_t *dst, + uint32_t block_size) +{ + arm_mult_f32(src_a, src_b, dst, block_size); +} + +static inline void zdsp_add_q7(const q7_t *src_a, const q7_t *src_b, q7_t *dst, uint32_t block_size) +{ + arm_add_q7(src_a, src_b, dst, block_size); +} +static inline void zdsp_add_q15(const q15_t *src_a, const q15_t *src_b, q15_t *dst, + uint32_t block_size) +{ + arm_add_q15(src_a, src_b, dst, block_size); +} +static inline void zdsp_add_q31(const q31_t *src_a, const q31_t *src_b, q31_t *dst, + uint32_t block_size) +{ + arm_add_q31(src_a, src_b, dst, block_size); +} +static inline void zdsp_add_f32(const float32_t *src_a, const float32_t *src_b, float32_t *dst, + uint32_t block_size) +{ + arm_add_f32(src_a, src_b, dst, block_size); +} + +static inline void zdsp_sub_q7(const q7_t *src_a, const q7_t *src_b, q7_t *dst, uint32_t block_size) +{ + arm_sub_q7(src_a, src_b, dst, block_size); +} +static inline void zdsp_sub_q15(const q15_t *src_a, const q15_t *src_b, q15_t *dst, + uint32_t block_size) +{ + arm_sub_q15(src_a, src_b, dst, block_size); +} +static inline void zdsp_sub_q31(const q31_t *src_a, const q31_t *src_b, q31_t *dst, + uint32_t block_size) +{ + arm_sub_q31(src_a, src_b, dst, block_size); +} +static inline void zdsp_sub_f32(const float32_t *src_a, const float32_t *src_b, float32_t *dst, + uint32_t block_size) +{ + arm_sub_f32(src_a, src_b, dst, block_size); +} + +static inline void zdsp_scale_q7(const q7_t *src, q7_t scale_fract, int8_t shift, q7_t *dst, + uint32_t block_size) +{ + arm_scale_q7(src, scale_fract, shift, dst, block_size); +} +static inline void zdsp_scale_q15(const q15_t *src, q15_t scale_fract, int8_t shift, q15_t *dst, + uint32_t block_size) +{ + arm_scale_q15(src, scale_fract, shift, dst, block_size); +} +static inline void zdsp_scale_q31(const q31_t *src, q31_t scale_fract, int8_t shift, q31_t *dst, + uint32_t block_size) +{ + arm_scale_q31(src, scale_fract, shift, dst, block_size); +} + +static inline void zdsp_scale_f32(const float32_t *src, float32_t scale, float32_t *dst, + uint32_t block_size) +{ + arm_scale_f32(src, scale, dst, block_size); +} + +static inline void zdsp_abs_q7(const q7_t *src, q7_t *dst, uint32_t block_size) +{ + arm_abs_q7(src, dst, block_size); +} +static inline void zdsp_abs_q15(const q15_t *src, q15_t *dst, uint32_t block_size) +{ + arm_abs_q15(src, dst, block_size); +} +static inline void zdsp_abs_q31(const q31_t *src, q31_t *dst, uint32_t block_size) +{ + arm_abs_q31(src, dst, block_size); +} +static inline void zdsp_abs_f32(const float32_t *src, float32_t *dst, uint32_t block_size) +{ + arm_abs_f32(src, dst, block_size); +} + +static inline void zdsp_negate_q7(const q7_t *src, q7_t *dst, uint32_t block_size) +{ + arm_negate_q7(src, dst, block_size); +} +static inline void zdsp_negate_q15(const q15_t *src, q15_t *dst, uint32_t block_size) +{ + arm_negate_q15(src, dst, block_size); +} +static inline void zdsp_negate_q31(const q31_t *src, q31_t *dst, uint32_t block_size) +{ + arm_negate_q31(src, dst, block_size); +} +static inline void zdsp_negate_f32(const float32_t *src, float32_t *dst, uint32_t block_size) +{ + arm_negate_f32(src, dst, block_size); +} + +static inline void zdsp_dot_prod_q7(const q7_t *src_a, const q7_t *src_b, uint32_t block_size, + q31_t *dst) +{ + arm_dot_prod_q7(src_a, src_b, block_size, dst); +} +static inline void zdsp_dot_prod_q15(const q15_t *src_a, const q15_t *src_b, uint32_t block_size, + q63_t *dst) +{ + arm_dot_prod_q15(src_a, src_b, block_size, dst); +} +static inline void zdsp_dot_prod_q31(const q31_t *src_a, const q31_t *src_b, uint32_t block_size, + q63_t *dst) +{ + arm_dot_prod_q31(src_a, src_b, block_size, dst); +} +static inline void zdsp_dot_prod_f32(const float32_t *src_a, const float32_t *src_b, + uint32_t block_size, float32_t *dst) +{ + arm_dot_prod_f32(src_a, src_b, block_size, dst); +} + +static inline void zdsp_shift_q7(const q7_t *src, int8_t shift_bits, q7_t *dst, uint32_t block_size) +{ + arm_shift_q7(src, shift_bits, dst, block_size); +} +static inline void zdsp_shift_q15(const q15_t *src, int8_t shift_bits, q15_t *dst, + uint32_t block_size) +{ + arm_shift_q15(src, shift_bits, dst, block_size); +} +static inline void zdsp_shift_q31(const q31_t *src, int8_t shift_bits, q31_t *dst, + uint32_t block_size) +{ + arm_shift_q31(src, shift_bits, dst, block_size); +} + +static inline void zdsp_offset_q7(const q7_t *src, q7_t offset, q7_t *dst, uint32_t block_size) +{ + arm_offset_q7(src, offset, dst, block_size); +} +static inline void zdsp_offset_q15(const q15_t *src, q15_t offset, q15_t *dst, uint32_t block_size) +{ + arm_offset_q15(src, offset, dst, block_size); +} +static inline void zdsp_offset_q31(const q31_t *src, q31_t offset, q31_t *dst, uint32_t block_size) +{ + arm_offset_q31(src, offset, dst, block_size); +} +static inline void zdsp_offset_f32(const float32_t *src, float32_t offset, float32_t *dst, + uint32_t block_size) +{ + arm_offset_f32(src, offset, dst, block_size); +} + +static inline void zdsp_clip_q7(const q7_t *src, q7_t *dst, q7_t low, q7_t high, + uint32_t num_samples) +{ + arm_clip_q7(src, dst, low, high, num_samples); +} +static inline void zdsp_clip_q15(const q15_t *src, q15_t *dst, q15_t low, q15_t high, + uint32_t num_samples) +{ + arm_clip_q15(src, dst, low, high, num_samples); +} +static inline void zdsp_clip_q31(const q31_t *src, q31_t *dst, q31_t low, q31_t high, + uint32_t num_samples) +{ + arm_clip_q31(src, dst, low, high, num_samples); +} +static inline void zdsp_clip_f32(const float32_t *src, float32_t *dst, float32_t low, + float32_t high, uint32_t num_samples) +{ + arm_clip_f32(src, dst, low, high, num_samples); +} + +static inline void zdsp_and_u8(const uint8_t *src_a, const uint8_t *src_b, uint8_t *dst, + uint32_t block_size) +{ + arm_and_u8(src_a, src_b, dst, block_size); +} +static inline void zdsp_and_u16(const uint16_t *src_a, const uint16_t *src_b, uint16_t *dst, + uint32_t block_size) +{ + arm_and_u16(src_a, src_b, dst, block_size); +} +static inline void zdsp_and_u32(const uint32_t *src_a, const uint32_t *src_b, uint32_t *dst, + uint32_t block_size) +{ + arm_and_u32(src_a, src_b, dst, block_size); +} + +static inline void zdsp_or_u8(const uint8_t *src_a, const uint8_t *src_b, uint8_t *dst, + uint32_t block_size) +{ + arm_or_u8(src_a, src_b, dst, block_size); +} +static inline void zdsp_or_u16(const uint16_t *src_a, const uint16_t *src_b, uint16_t *dst, + uint32_t block_size) +{ + arm_or_u16(src_a, src_b, dst, block_size); +} +static inline void zdsp_or_u32(const uint32_t *src_a, const uint32_t *src_b, uint32_t *dst, + uint32_t block_size) +{ + arm_or_u32(src_a, src_b, dst, block_size); +} + +static inline void zdsp_xor_u8(const uint8_t *src_a, const uint8_t *src_b, uint8_t *dst, + uint32_t block_size) +{ + arm_xor_u8(src_a, src_b, dst, block_size); +} +static inline void zdsp_xor_u16(const uint16_t *src_a, const uint16_t *src_b, uint16_t *dst, + uint32_t block_size) +{ + arm_xor_u16(src_a, src_b, dst, block_size); +} +static inline void zdsp_xor_u32(const uint32_t *src_a, const uint32_t *src_b, uint32_t *dst, + uint32_t block_size) +{ + arm_xor_u32(src_a, src_b, dst, block_size); +} + +static inline void zdsp_not_u8(const uint8_t *src, uint8_t *dst, uint32_t block_size) +{ + arm_not_u8(src, dst, block_size); +} +static inline void zdsp_not_u16(const uint16_t *src, uint16_t *dst, uint32_t block_size) +{ + arm_not_u16(src, dst, block_size); +} +static inline void zdsp_not_u32(const uint32_t *src, uint32_t *dst, uint32_t block_size) +{ + arm_not_u32(src, dst, block_size); +} + +#ifdef __cplusplus +} +#endif + +#ifdef CONFIG_FP16 +#include "zdsp_backend_f16.h" +#endif /* COIFNG_FP16 */ + +#endif /* SUBSYS_MATH_CMSIS_BACKEND_PUBLIC_ZDSP_BACKEND_DSP_H_ */ diff --git a/subsys/dsp/cmsis/public/zdsp_backend_f16.h b/subsys/dsp/cmsis/public/zdsp_backend_f16.h new file mode 100644 index 0000000000000..1bc6364edd092 --- /dev/null +++ b/subsys/dsp/cmsis/public/zdsp_backend_f16.h @@ -0,0 +1,75 @@ +/* Copyright (c) 2022 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef SUBSYS_DSP_CMSIS_PUBLIC_ZDSP_BACKEND_F16_H_ +#define SUBSYS_DSP_CMSIS_PUBLIC_ZDSP_BACKEND_F16_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* This include MUST be done before arm_math.h so we can let the arch specific + * logic set up the right #define values for arm_math.h + */ +#include + +#include + +static inline void zdsp_mult_f16(const float16_t *src_a, const float16_t *src_b, float16_t *dst, + uint32_t block_size) +{ + arm_mult_f16(src_a, src_b, dst, block_size); +} + +static inline void zdsp_add_f16(const float16_t *src_a, const float16_t *src_b, float16_t *dst, + uint32_t block_size) +{ + arm_add_f16(src_a, src_b, dst, block_size); +} + +static inline void zdsp_sub_f16(const float16_t *src_a, const float16_t *src_b, float16_t *dst, + uint32_t block_size) +{ + arm_sub_f16(src_a, src_b, dst, block_size); +} + +static inline void zdsp_scale_f16(const float16_t *src, float16_t scale, float16_t *dst, + uint32_t block_size) +{ + arm_scale_f16(src, scale, dst, block_size); +} + +static inline void zdsp_abs_f16(const float16_t *src, float16_t *dst, uint32_t block_size) +{ + arm_abs_f16(src, dst, block_size); +} + +static inline void zdsp_dot_prod_f16(const float16_t *src_a, const float16_t *src_b, + uint32_t block_size, float16_t *result) +{ + arm_dot_prod_f16(src_a, src_b, block_size, result); +} + +static inline void zdsp_offset_f16(const float16_t *src, float16_t offset, float16_t *dst, + uint32_t block_size) +{ + arm_offset_f16(src, offset, dst, block_size); +} + +static inline void zdsp_negate_f16(const float16_t *src, float16_t *dst, uint32_t block_size) +{ + arm_negate_f16(src, dst, block_size); +} + +static inline void zdsp_clip_f16(const float16_t *src, float16_t *dst, float16_t low, + float16_t high, uint32_t num_samples) +{ + arm_clip_f16(src, dst, low, high, num_samples); +} + +#ifdef __cplusplus +} +#endif + +#endif /* SUBSYS_DSP_CMSIS_PUBLIC_ZDSP_BACKEND_F16_H_ */ diff --git a/west.yml b/west.yml index 5771dfc089293..938ddd4238d43 100644 --- a/west.yml +++ b/west.yml @@ -32,7 +32,7 @@ manifest: revision: fe0ab36e0fa7453a4c9b97bedac89709f45cf965 path: modules/lib/chre - name: cmsis - revision: 093de61c2a7d12dc9253daf8692f61f793a9254a + revision: 74981bf893e8b10931464b9945e2143d99a3f0a3 path: modules/hal/cmsis groups: - hal From ca2a62e062f3bde6ef8f2a328d5528506aa5e1ab Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Tue, 11 Oct 2022 22:49:40 -0600 Subject: [PATCH 3/3] dsp: Update tests for basicmath to use dsp subsystem Update the relevant tests in basicmath to use the dsp subsystem. Note that f16 is not updated since it's much more architecture specific and did not become a part of zdsp. Signed-off-by: Yuval Peress --- tests/subsys/dsp/basicmath/CMakeLists.txt | 2 +- tests/subsys/dsp/basicmath/prj.conf | 1 + tests/subsys/dsp/basicmath/src/f16.c | 108 ++++++------- tests/subsys/dsp/basicmath/src/f32.c | 108 ++++++------- tests/subsys/dsp/basicmath/src/q15.c | 180 +++++++++++----------- tests/subsys/dsp/basicmath/src/q31.c | 176 ++++++++++----------- tests/subsys/dsp/basicmath/src/q7.c | 176 ++++++++++----------- tests/subsys/dsp/basicmath/testcase.yaml | 12 +- 8 files changed, 384 insertions(+), 379 deletions(-) diff --git a/tests/subsys/dsp/basicmath/CMakeLists.txt b/tests/subsys/dsp/basicmath/CMakeLists.txt index 6c972fc0441c9..22ec493cdfd83 100644 --- a/tests/subsys/dsp/basicmath/CMakeLists.txt +++ b/tests/subsys/dsp/basicmath/CMakeLists.txt @@ -11,6 +11,6 @@ target_sources(app PRIVATE src/f32.c ) -target_sources_ifdef(CONFIG_CMSIS_DSP_FLOAT16 app PRIVATE src/f16.c) +target_sources_ifdef(CONFIG_FP16 app PRIVATE src/f16.c) target_include_directories(app PRIVATE ${ZEPHYR_BASE}/tests/lib/cmsis_dsp) diff --git a/tests/subsys/dsp/basicmath/prj.conf b/tests/subsys/dsp/basicmath/prj.conf index ad76c3a269a2a..4511e31f3aa33 100644 --- a/tests/subsys/dsp/basicmath/prj.conf +++ b/tests/subsys/dsp/basicmath/prj.conf @@ -3,3 +3,4 @@ CONFIG_ZTEST_NEW_API=y CONFIG_NEWLIB_LIBC=y CONFIG_CMSIS_DSP=y CONFIG_CMSIS_DSP_BASICMATH=y +CONFIG_DSP_BACKEND_CMSIS=y diff --git a/tests/subsys/dsp/basicmath/src/f16.c b/tests/subsys/dsp/basicmath/src/f16.c index fd10697e89d69..891f57e018a68 100644 --- a/tests/subsys/dsp/basicmath/src/f16.c +++ b/tests/subsys/dsp/basicmath/src/f16.c @@ -5,10 +5,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include #include -#include #include "common/test_common.h" #include "f16.pat" @@ -17,7 +17,7 @@ #define SNR_DOTPROD_THRESH ((float32_t)40) #define REL_ERROR_THRESH (4.0e-2) -static void test_arm_add_f16( +static void test_zdsp_add_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, size_t length) { @@ -28,7 +28,7 @@ static void test_arm_add_f16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_add_f16((float16_t *)input1, (float16_t *)input2, output, length); + zdsp_add_f16((float16_t *)input1, (float16_t *)input2, output, length); /* Validate output */ zassert_true( @@ -45,13 +45,13 @@ static void test_arm_add_f16( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f16, arm_add_f16, 7, in_com1, in_com2, ref_add, 7); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_add_f16, 16, in_com1, in_com2, ref_add, 16); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_add_f16, 23, in_com1, in_com2, ref_add, 23); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_add_f16, long, in_com1, in_com2, ref_add, +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_add_f16, 7, in_com1, in_com2, ref_add, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_add_f16, 16, in_com1, in_com2, ref_add, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_add_f16, 23, in_com1, in_com2, ref_add, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_add_f16, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); -static void test_arm_sub_f16( +static void test_zdsp_sub_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, size_t length) { @@ -62,7 +62,7 @@ static void test_arm_sub_f16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_sub_f16((float16_t *)input1, (float16_t *)input2, output, length); + zdsp_sub_f16((float16_t *)input1, (float16_t *)input2, output, length); /* Validate output */ zassert_true( @@ -79,13 +79,13 @@ static void test_arm_sub_f16( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f16, arm_sub_f16, 7, in_com1, in_com2, ref_sub, 7); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_sub_f16, 16, in_com1, in_com2, ref_sub, 16); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_sub_f16, 23, in_com1, in_com2, ref_sub, 23); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_sub_f16, long, in_com1, in_com2, ref_sub, +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_sub_f16, 7, in_com1, in_com2, ref_sub, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_sub_f16, 16, in_com1, in_com2, ref_sub, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_sub_f16, 23, in_com1, in_com2, ref_sub, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_sub_f16, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); -static void test_arm_mult_f16( +static void test_zdsp_mult_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, size_t length) { @@ -96,7 +96,7 @@ static void test_arm_mult_f16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_mult_f16((float16_t *)input1, (float16_t *)input2, output, length); + zdsp_mult_f16((float16_t *)input1, (float16_t *)input2, output, length); /* Validate output */ zassert_true( @@ -113,13 +113,13 @@ static void test_arm_mult_f16( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f16, arm_mult_f16, 7, in_com1, in_com2, ref_mult, 7); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_mult_f16, 16, in_com1, in_com2, ref_mult, 16); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_mult_f16, 23, in_com1, in_com2, ref_mult, 23); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_mult_f16, long, in_com1, in_com2, ref_mult, +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_mult_f16, 7, in_com1, in_com2, ref_mult, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_mult_f16, 16, in_com1, in_com2, ref_mult, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_mult_f16, 23, in_com1, in_com2, ref_mult, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_mult_f16, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); -static void test_arm_negate_f16( +static void test_zdsp_negate_f16( const uint16_t *input1, const uint16_t *ref, size_t length) { float16_t *output; @@ -129,7 +129,7 @@ static void test_arm_negate_f16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_negate_f16((float16_t *)input1, output, length); + zdsp_negate_f16((float16_t *)input1, output, length); /* Validate output */ zassert_true( @@ -146,13 +146,13 @@ static void test_arm_negate_f16( free(output); } -DEFINE_TEST_VARIANT3(basic_math_f16, arm_negate_f16, 7, in_com1, ref_negate, 7); -DEFINE_TEST_VARIANT3(basic_math_f16, arm_negate_f16, 16, in_com1, ref_negate, 16); -DEFINE_TEST_VARIANT3(basic_math_f16, arm_negate_f16, 23, in_com1, ref_negate, 23); -DEFINE_TEST_VARIANT3(basic_math_f16, arm_negate_f16, long, in_com1, ref_negate, +DEFINE_TEST_VARIANT3(basic_math_f16, zdsp_negate_f16, 7, in_com1, ref_negate, 7); +DEFINE_TEST_VARIANT3(basic_math_f16, zdsp_negate_f16, 16, in_com1, ref_negate, 16); +DEFINE_TEST_VARIANT3(basic_math_f16, zdsp_negate_f16, 23, in_com1, ref_negate, 23); +DEFINE_TEST_VARIANT3(basic_math_f16, zdsp_negate_f16, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); -static void test_arm_offset_f16( +static void test_zdsp_offset_f16( const uint16_t *input1, float16_t scalar, const uint16_t *ref, size_t length) { @@ -163,7 +163,7 @@ static void test_arm_offset_f16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_offset_f16((float16_t *)input1, scalar, output, length); + zdsp_offset_f16((float16_t *)input1, scalar, output, length); /* Validate output */ zassert_true( @@ -180,13 +180,13 @@ static void test_arm_offset_f16( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f16, arm_offset_f16, 0p5_7, in_com1, 0.5f, ref_offset, 7); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_offset_f16, 0p5_16, in_com1, 0.5f, ref_offset, 16); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_offset_f16, 0p5_23, in_com1, 0.5f, ref_offset, 23); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_offset_f16, long, in_com1, 0.5f, ref_offset, +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_offset_f16, 0p5_7, in_com1, 0.5f, ref_offset, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_offset_f16, 0p5_16, in_com1, 0.5f, ref_offset, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_offset_f16, 0p5_23, in_com1, 0.5f, ref_offset, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_offset_f16, long, in_com1, 0.5f, ref_offset, ARRAY_SIZE(in_com1)); -static void test_arm_scale_f16( +static void test_zdsp_scale_f16( const uint16_t *input1, float16_t scalar, const uint16_t *ref, size_t length) { @@ -197,7 +197,7 @@ static void test_arm_scale_f16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_scale_f16((float16_t *)input1, scalar, output, length); + zdsp_scale_f16((float16_t *)input1, scalar, output, length); /* Validate output */ zassert_true( @@ -214,13 +214,13 @@ static void test_arm_scale_f16( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f16, arm_scale_f16, 0p5_7, in_com1, 0.5f, ref_scale, 7); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_scale_f16, 0p5_16, in_com1, 0.5f, ref_scale, 16); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_scale_f16, 0p5_23, in_com1, 0.5f, ref_scale, 23); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_scale_f16, long, in_com1, 0.5f, ref_scale, +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_scale_f16, 0p5_7, in_com1, 0.5f, ref_scale, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_scale_f16, 0p5_16, in_com1, 0.5f, ref_scale, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_scale_f16, 0p5_23, in_com1, 0.5f, ref_scale, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_scale_f16, long, in_com1, 0.5f, ref_scale, ARRAY_SIZE(in_com1)); -static void test_arm_dot_prod_f16( +static void test_zdsp_dot_prod_f16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, size_t length) { @@ -231,7 +231,7 @@ static void test_arm_dot_prod_f16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_dot_prod_f16( + zdsp_dot_prod_f16( (float16_t *)input1, (float16_t *)input2, length, &output[0]); /* Validate output */ @@ -249,13 +249,13 @@ static void test_arm_dot_prod_f16( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f16, arm_dot_prod_f16, 7, in_com1, in_com2, ref_dot_prod_3, 7); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_dot_prod_f16, 16, in_com1, in_com2, ref_dot_prod_4, 16); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_dot_prod_f16, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); -DEFINE_TEST_VARIANT4(basic_math_f16, arm_dot_prod_f16, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_dot_prod_f16, 7, in_com1, in_com2, ref_dot_prod_3, 7); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_dot_prod_f16, 16, in_com1, in_com2, ref_dot_prod_4, 16); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_dot_prod_f16, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); +DEFINE_TEST_VARIANT4(basic_math_f16, zdsp_dot_prod_f16, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); -static void test_arm_abs_f16( +static void test_zdsp_abs_f16( const uint16_t *input1, const uint16_t *ref, size_t length) { float16_t *output; @@ -265,7 +265,7 @@ static void test_arm_abs_f16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_abs_f16((float16_t *)input1, output, length); + zdsp_abs_f16((float16_t *)input1, output, length); /* Validate output */ zassert_true( @@ -282,12 +282,12 @@ static void test_arm_abs_f16( free(output); } -DEFINE_TEST_VARIANT3(basic_math_f16, arm_abs_f16, 7, in_com1, ref_abs, 7); -DEFINE_TEST_VARIANT3(basic_math_f16, arm_abs_f16, 16, in_com1, ref_abs, 16); -DEFINE_TEST_VARIANT3(basic_math_f16, arm_abs_f16, 23, in_com1, ref_abs, 23); -DEFINE_TEST_VARIANT3(basic_math_f16, arm_abs_f16, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_f16, zdsp_abs_f16, 7, in_com1, ref_abs, 7); +DEFINE_TEST_VARIANT3(basic_math_f16, zdsp_abs_f16, 16, in_com1, ref_abs, 16); +DEFINE_TEST_VARIANT3(basic_math_f16, zdsp_abs_f16, 23, in_com1, ref_abs, 23); +DEFINE_TEST_VARIANT3(basic_math_f16, zdsp_abs_f16, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); -static void test_arm_clip_f16( +static void test_zdsp_clip_f16( const uint16_t *input, const uint16_t *ref, float16_t min, float16_t max, size_t length) { float16_t *output; @@ -297,7 +297,7 @@ static void test_arm_clip_f16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_clip_f16((float16_t *)input, output, min, max, length); + zdsp_clip_f16((float16_t *)input, output, min, max, length); /* Validate output */ zassert_true( @@ -314,11 +314,11 @@ static void test_arm_clip_f16( free(output); } -DEFINE_TEST_VARIANT5(basic_math_f16, arm_clip_f16, m0p5_m0p1, in_clip, ref_clip1, +DEFINE_TEST_VARIANT5(basic_math_f16, zdsp_clip_f16, m0p5_m0p1, in_clip, ref_clip1, -0.5f, -0.1f, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(basic_math_f16, arm_clip_f16, m0p5_0p5, in_clip, ref_clip2, +DEFINE_TEST_VARIANT5(basic_math_f16, zdsp_clip_f16, m0p5_0p5, in_clip, ref_clip2, -0.5f, 0.5f, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(basic_math_f16, arm_clip_f16, 0p1_0p5, in_clip, ref_clip3, +DEFINE_TEST_VARIANT5(basic_math_f16, zdsp_clip_f16, 0p1_0p5, in_clip, ref_clip3, 0.1f, 0.5f, ARRAY_SIZE(ref_clip3)); ZTEST_SUITE(basic_math_f16, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/dsp/basicmath/src/f32.c b/tests/subsys/dsp/basicmath/src/f32.c index c92b4703662cb..05b3d22200b5d 100644 --- a/tests/subsys/dsp/basicmath/src/f32.c +++ b/tests/subsys/dsp/basicmath/src/f32.c @@ -5,10 +5,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include #include -#include #include "common/test_common.h" #include "f32.pat" @@ -16,7 +16,7 @@ #define SNR_ERROR_THRESH ((float32_t)120) #define REL_ERROR_THRESH (5.0e-5) -static void test_arm_add_f32( +static void test_zdsp_add_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) { @@ -27,7 +27,7 @@ static void test_arm_add_f32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_add_f32((float32_t *)input1, (float32_t *)input2, output, length); + zdsp_add_f32((float32_t *)input1, (float32_t *)input2, output, length); /* Validate output */ zassert_true( @@ -44,13 +44,13 @@ static void test_arm_add_f32( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f32, arm_add_f32, 3, in_com1, in_com2, ref_add, 3); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_add_f32, 8, in_com1, in_com2, ref_add, 8); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_add_f32, 11, in_com1, in_com2, ref_add, 11); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_add_f32, long, in_com1, in_com2, ref_add, +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_add_f32, 3, in_com1, in_com2, ref_add, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_add_f32, 8, in_com1, in_com2, ref_add, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_add_f32, 11, in_com1, in_com2, ref_add, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_add_f32, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); -static void test_arm_sub_f32( +static void test_zdsp_sub_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) { @@ -61,7 +61,7 @@ static void test_arm_sub_f32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_sub_f32((float32_t *)input1, (float32_t *)input2, output, length); + zdsp_sub_f32((float32_t *)input1, (float32_t *)input2, output, length); /* Validate output */ zassert_true( @@ -78,13 +78,13 @@ static void test_arm_sub_f32( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f32, arm_sub_f32, 3, in_com1, in_com2, ref_sub, 3); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_sub_f32, 8, in_com1, in_com2, ref_sub, 8); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_sub_f32, 11, in_com1, in_com2, ref_sub, 11); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_sub_f32, long, in_com1, in_com2, ref_sub, +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_sub_f32, 3, in_com1, in_com2, ref_sub, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_sub_f32, 8, in_com1, in_com2, ref_sub, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_sub_f32, 11, in_com1, in_com2, ref_sub, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_sub_f32, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); -static void test_arm_mult_f32( +static void test_zdsp_mult_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) { @@ -95,7 +95,7 @@ static void test_arm_mult_f32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_mult_f32((float32_t *)input1, (float32_t *)input2, output, length); + zdsp_mult_f32((float32_t *)input1, (float32_t *)input2, output, length); /* Validate output */ zassert_true( @@ -112,13 +112,13 @@ static void test_arm_mult_f32( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f32, arm_mult_f32, 3, in_com1, in_com2, ref_mult, 3); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_mult_f32, 8, in_com1, in_com2, ref_mult, 8); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_mult_f32, 11, in_com1, in_com2, ref_mult, 11); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_mult_f32, long, in_com1, in_com2, ref_mult, +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_mult_f32, 3, in_com1, in_com2, ref_mult, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_mult_f32, 8, in_com1, in_com2, ref_mult, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_mult_f32, 11, in_com1, in_com2, ref_mult, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_mult_f32, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); -static void test_arm_negate_f32( +static void test_zdsp_negate_f32( const uint32_t *input1, const uint32_t *ref, size_t length) { float32_t *output; @@ -128,7 +128,7 @@ static void test_arm_negate_f32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_negate_f32((float32_t *)input1, output, length); + zdsp_negate_f32((float32_t *)input1, output, length); /* Validate output */ zassert_true( @@ -145,13 +145,13 @@ static void test_arm_negate_f32( free(output); } -DEFINE_TEST_VARIANT3(basic_math_f32, arm_negate_f32, 3, in_com1, ref_negate, 3); -DEFINE_TEST_VARIANT3(basic_math_f32, arm_negate_f32, 8, in_com1, ref_negate, 8); -DEFINE_TEST_VARIANT3(basic_math_f32, arm_negate_f32, 11, in_com1, ref_negate, 11); -DEFINE_TEST_VARIANT3(basic_math_f32, arm_negate_f32, long, in_com1, ref_negate, +DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_negate_f32, 3, in_com1, ref_negate, 3); +DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_negate_f32, 8, in_com1, ref_negate, 8); +DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_negate_f32, 11, in_com1, ref_negate, 11); +DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_negate_f32, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); -static void test_arm_offset_f32( +static void test_zdsp_offset_f32( const uint32_t *input1, float32_t scalar, const uint32_t *ref, size_t length) { @@ -162,7 +162,7 @@ static void test_arm_offset_f32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_offset_f32((float32_t *)input1, scalar, output, length); + zdsp_offset_f32((float32_t *)input1, scalar, output, length); /* Validate output */ zassert_true( @@ -179,13 +179,13 @@ static void test_arm_offset_f32( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f32, arm_offset_f32, 0p5_3, in_com1, 0.5f, ref_offset, 3); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_offset_f32, 0p5_8, in_com1, 0.5f, ref_offset, 8); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_offset_f32, 0p5_11, in_com1, 0.5f, ref_offset, 11); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_offset_f32, long, in_com1, 0.5f, ref_offset, +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_offset_f32, 0p5_3, in_com1, 0.5f, ref_offset, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_offset_f32, 0p5_8, in_com1, 0.5f, ref_offset, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_offset_f32, 0p5_11, in_com1, 0.5f, ref_offset, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_offset_f32, long, in_com1, 0.5f, ref_offset, ARRAY_SIZE(in_com1)); -static void test_arm_scale_f32( +static void test_zdsp_scale_f32( const uint32_t *input1, float32_t scalar, const uint32_t *ref, size_t length) { @@ -196,7 +196,7 @@ static void test_arm_scale_f32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_scale_f32((float32_t *)input1, scalar, output, length); + zdsp_scale_f32((float32_t *)input1, scalar, output, length); /* Validate output */ zassert_true( @@ -213,13 +213,13 @@ static void test_arm_scale_f32( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f32, arm_scale_f32, 0p5_3, in_com1, 0.5f, ref_scale, 3); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_scale_f32, 0p5_8, in_com1, 0.5f, ref_scale, 8); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_scale_f32, 0p5_11, in_com1, 0.5f, ref_scale, 11); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_scale_f32, long, in_com1, 0.5f, ref_scale, +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_scale_f32, 0p5_3, in_com1, 0.5f, ref_scale, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_scale_f32, 0p5_8, in_com1, 0.5f, ref_scale, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_scale_f32, 0p5_11, in_com1, 0.5f, ref_scale, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_scale_f32, long, in_com1, 0.5f, ref_scale, ARRAY_SIZE(in_com1)); -static void test_arm_dot_prod_f32( +static void test_zdsp_dot_prod_f32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) { @@ -230,7 +230,7 @@ static void test_arm_dot_prod_f32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_dot_prod_f32( + zdsp_dot_prod_f32( (float32_t *)input1, (float32_t *)input2, length, &output[0]); /* Validate output */ @@ -248,13 +248,13 @@ static void test_arm_dot_prod_f32( free(output); } -DEFINE_TEST_VARIANT4(basic_math_f32, arm_dot_prod_f32, 3, in_com1, in_com2, ref_dot_prod_3, 3); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_dot_prod_f32, 8, in_com1, in_com2, ref_dot_prod_4, 8); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_dot_prod_f32, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); -DEFINE_TEST_VARIANT4(basic_math_f32, arm_dot_prod_f32, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_dot_prod_f32, 3, in_com1, in_com2, ref_dot_prod_3, 3); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_dot_prod_f32, 8, in_com1, in_com2, ref_dot_prod_4, 8); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_dot_prod_f32, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); +DEFINE_TEST_VARIANT4(basic_math_f32, zdsp_dot_prod_f32, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); -static void test_arm_abs_f32( +static void test_zdsp_abs_f32( const uint32_t *input1, const uint32_t *ref, size_t length) { float32_t *output; @@ -264,7 +264,7 @@ static void test_arm_abs_f32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_abs_f32((float32_t *)input1, output, length); + zdsp_abs_f32((float32_t *)input1, output, length); /* Validate output */ zassert_true( @@ -281,12 +281,12 @@ static void test_arm_abs_f32( free(output); } -DEFINE_TEST_VARIANT3(basic_math_f32, arm_abs_f32, 3, in_com1, ref_abs, 3); -DEFINE_TEST_VARIANT3(basic_math_f32, arm_abs_f32, 8, in_com1, ref_abs, 8); -DEFINE_TEST_VARIANT3(basic_math_f32, arm_abs_f32, 11, in_com1, ref_abs, 11); -DEFINE_TEST_VARIANT3(basic_math_f32, arm_abs_f32, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_abs_f32, 3, in_com1, ref_abs, 3); +DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_abs_f32, 8, in_com1, ref_abs, 8); +DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_abs_f32, 11, in_com1, ref_abs, 11); +DEFINE_TEST_VARIANT3(basic_math_f32, zdsp_abs_f32, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); -static void test_arm_clip_f32( +static void test_zdsp_clip_f32( const uint32_t *input, const uint32_t *ref, float32_t min, float32_t max, size_t length) { float32_t *output; @@ -296,7 +296,7 @@ static void test_arm_clip_f32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_clip_f32((float32_t *)input, output, min, max, length); + zdsp_clip_f32((float32_t *)input, output, min, max, length); /* Validate output */ zassert_true( @@ -313,11 +313,11 @@ static void test_arm_clip_f32( free(output); } -DEFINE_TEST_VARIANT5(basic_math_f32, arm_clip_f32, m0p5_m0p1, in_clip, ref_clip1, +DEFINE_TEST_VARIANT5(basic_math_f32, zdsp_clip_f32, m0p5_m0p1, in_clip, ref_clip1, -0.5f, -0.1f, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(basic_math_f32, arm_clip_f32, m0p5_0p5, in_clip, ref_clip2, +DEFINE_TEST_VARIANT5(basic_math_f32, zdsp_clip_f32, m0p5_0p5, in_clip, ref_clip2, -0.5f, 0.5f, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(basic_math_f32, arm_clip_f32, 0p1_0p5, in_clip, ref_clip3, +DEFINE_TEST_VARIANT5(basic_math_f32, zdsp_clip_f32, 0p1_0p5, in_clip, ref_clip3, 0.1f, 0.5f, ARRAY_SIZE(ref_clip3)); ZTEST_SUITE(basic_math_f32, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/dsp/basicmath/src/q15.c b/tests/subsys/dsp/basicmath/src/q15.c index c69120cf424d1..3e2b979136ca7 100644 --- a/tests/subsys/dsp/basicmath/src/q15.c +++ b/tests/subsys/dsp/basicmath/src/q15.c @@ -5,10 +5,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include #include -#include #include "common/test_common.h" #include "q15.pat" @@ -18,7 +18,7 @@ #define ABS_ERROR_THRESH_Q15 ((q15_t)2) #define ABS_ERROR_THRESH_Q63 ((q63_t)(1 << 17)) -static void test_arm_add_q15( +static void test_zdsp_add_q15( const q15_t *input1, const q15_t *input2, const q15_t *ref, size_t length) { @@ -29,7 +29,7 @@ static void test_arm_add_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_add_q15(input1, input2, output, length); + zdsp_add_q15(input1, input2, output, length); /* Validate output */ zassert_true( @@ -44,15 +44,17 @@ static void test_arm_add_q15( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, 7, in_com1, in_com2, ref_add, 7); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, 16, in_com1, in_com2, ref_add, 16); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, 23, in_com1, in_com2, ref_add, 23); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, possat, in_maxpos, in_maxpos, ref_add_possat, 17); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, negsat, in_maxneg, in_maxneg, ref_add_negsat, 17); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_add_q15, long, in_com1, in_com2, ref_add, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_add_q15, 7, in_com1, in_com2, ref_add, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_add_q15, 16, in_com1, in_com2, ref_add, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_add_q15, 23, in_com1, in_com2, ref_add, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_add_q15, possat, in_maxpos, in_maxpos, ref_add_possat, + 17); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_add_q15, negsat, in_maxneg, in_maxneg, ref_add_negsat, + 17); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_add_q15, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); -static void test_arm_sub_q15( +static void test_zdsp_sub_q15( const q15_t *input1, const q15_t *input2, const q15_t *ref, size_t length) { @@ -63,7 +65,7 @@ static void test_arm_sub_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_sub_q15(input1, input2, output, length); + zdsp_sub_q15(input1, input2, output, length); /* Validate output */ zassert_true( @@ -78,15 +80,17 @@ static void test_arm_sub_q15( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, 7, in_com1, in_com2, ref_sub, 7); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, 16, in_com1, in_com2, ref_sub, 16); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, 23, in_com1, in_com2, ref_sub, 23); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, possat, in_maxpos, in_maxneg, ref_sub_possat, 17); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 17); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_sub_q15, long, in_com1, in_com2, ref_sub, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_sub_q15, 7, in_com1, in_com2, ref_sub, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_sub_q15, 16, in_com1, in_com2, ref_sub, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_sub_q15, 23, in_com1, in_com2, ref_sub, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_sub_q15, possat, in_maxpos, in_maxneg, ref_sub_possat, + 17); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_sub_q15, negsat, in_maxneg, in_maxpos, ref_sub_negsat, + 17); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_sub_q15, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); -static void test_arm_mult_q15( +static void test_zdsp_mult_q15( const q15_t *input1, const q15_t *input2, const q15_t *ref, size_t length) { @@ -97,7 +101,7 @@ static void test_arm_mult_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_mult_q15(input1, input2, output, length); + zdsp_mult_q15(input1, input2, output, length); /* Validate output */ zassert_true( @@ -112,15 +116,15 @@ static void test_arm_mult_q15( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, 7, in_com1, in_com2, ref_mult, 7); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, 16, in_com1, in_com2, ref_mult, 16); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, 23, in_com1, in_com2, ref_mult, 23); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, possat, in_maxneg2, in_maxneg2, ref_mult_possat, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_mult_q15, 7, in_com1, in_com2, ref_mult, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_mult_q15, 16, in_com1, in_com2, ref_mult, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_mult_q15, 23, in_com1, in_com2, ref_mult, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_mult_q15, possat, in_maxneg2, in_maxneg2, ref_mult_possat, 17); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_mult_q15, long, in_com1, in_com2, ref_mult, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_mult_q15, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); -static void test_arm_negate_q15( +static void test_zdsp_negate_q15( const q15_t *input1, const q15_t *ref, size_t length) { q15_t *output; @@ -130,7 +134,7 @@ static void test_arm_negate_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_negate_q15(input1, output, length); + zdsp_negate_q15(input1, output, length); /* Validate output */ zassert_true( @@ -145,14 +149,14 @@ static void test_arm_negate_q15( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, 7, in_com1, ref_negate, 7); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, 16, in_com1, ref_negate, 16); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, 23, in_com1, ref_negate, 23); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, possat, in_maxneg2, ref_negate_possat, 17); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_negate_q15, long, in_com1, ref_negate, +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_negate_q15, 7, in_com1, ref_negate, 7); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_negate_q15, 16, in_com1, ref_negate, 16); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_negate_q15, 23, in_com1, ref_negate, 23); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_negate_q15, possat, in_maxneg2, ref_negate_possat, 17); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_negate_q15, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); -static void test_arm_offset_q15( +static void test_zdsp_offset_q15( const q15_t *input1, q15_t scalar, const q15_t *ref, size_t length) { q15_t *output; @@ -162,7 +166,7 @@ static void test_arm_offset_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_offset_q15(input1, scalar, output, length); + zdsp_offset_q15(input1, scalar, output, length); /* Validate output */ zassert_true( @@ -177,17 +181,17 @@ static void test_arm_offset_q15( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, 0p5_7, in_com1, 0x4000, ref_offset, 7); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, 0p5_16, in_com1, 0x4000, ref_offset, 16); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, 0p5_23, in_com1, 0x4000, ref_offset, 23); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, possat, in_maxpos, 0x7333, ref_offset_possat, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_offset_q15, 0p5_7, in_com1, 0x4000, ref_offset, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_offset_q15, 0p5_16, in_com1, 0x4000, ref_offset, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_offset_q15, 0p5_23, in_com1, 0x4000, ref_offset, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_offset_q15, possat, in_maxpos, 0x7333, ref_offset_possat, 17); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, negsat, in_maxneg, 0x8ccd, ref_offset_negsat, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_offset_q15, negsat, in_maxneg, 0x8ccd, ref_offset_negsat, 17); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_offset_q15, long, in_com1, 0x4000, ref_offset, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_offset_q15, long, in_com1, 0x4000, ref_offset, ARRAY_SIZE(in_com1)); -static void test_arm_scale_q15( +static void test_zdsp_scale_q15( const q15_t *input1, q15_t scalar, const q15_t *ref, size_t length) { q15_t *output; @@ -197,7 +201,7 @@ static void test_arm_scale_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_scale_q15(input1, scalar, 0, output, length); + zdsp_scale_q15(input1, scalar, 0, output, length); /* Validate output */ zassert_true( @@ -212,15 +216,15 @@ static void test_arm_scale_q15( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, 0p5_7, in_com1, 0x4000, ref_scale, 7); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, 0p5_16, in_com1, 0x4000, ref_scale, 16); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, 0p5_23, in_com1, 0x4000, ref_scale, 23); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, possat, in_maxneg2, 0x8000, ref_scale_possat, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_scale_q15, 0p5_7, in_com1, 0x4000, ref_scale, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_scale_q15, 0p5_16, in_com1, 0x4000, ref_scale, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_scale_q15, 0p5_23, in_com1, 0x4000, ref_scale, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_scale_q15, possat, in_maxneg2, 0x8000, ref_scale_possat, 17); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_scale_q15, long, in_com1, 0x4000, ref_scale, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_scale_q15, long, in_com1, 0x4000, ref_scale, ARRAY_SIZE(in_com1)); -static void test_arm_dot_prod_q15( +static void test_zdsp_dot_prod_q15( const q15_t *input1, const q15_t *input2, const q63_t *ref, size_t length) { @@ -231,7 +235,7 @@ static void test_arm_dot_prod_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_dot_prod_q15(input1, input2, length, &output[0]); + zdsp_dot_prod_q15(input1, input2, length, &output[0]); /* Validate output */ zassert_true( @@ -246,13 +250,13 @@ static void test_arm_dot_prod_q15( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q15, arm_dot_prod_q15, 7, in_com1, in_com2, ref_dot_prod_3, 7); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_dot_prod_q15, 16, in_com1, in_com2, ref_dot_prod_4, 16); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_dot_prod_q15, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_dot_prod_q15, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_dot_prod_q15, 7, in_com1, in_com2, ref_dot_prod_3, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_dot_prod_q15, 16, in_com1, in_com2, ref_dot_prod_4, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_dot_prod_q15, 23, in_com1, in_com2, ref_dot_prod_4n1, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_dot_prod_q15, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); -static void test_arm_abs_q15( +static void test_zdsp_abs_q15( const q15_t *input1, const q15_t *ref, size_t length) { q15_t *output; @@ -262,7 +266,7 @@ static void test_arm_abs_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_abs_q15(input1, output, length); + zdsp_abs_q15(input1, output, length); /* Validate output */ zassert_true( @@ -277,12 +281,12 @@ static void test_arm_abs_q15( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q15, arm_abs_q15, 7, in_com1, ref_abs, 7); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_abs_q15, 16, in_com1, ref_abs, 16); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_abs_q15, 23, in_com1, ref_abs, 23); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_abs_q15, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_abs_q15, 7, in_com1, ref_abs, 7); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_abs_q15, 16, in_com1, ref_abs, 16); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_abs_q15, 23, in_com1, ref_abs, 23); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_abs_q15, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); -static void test_arm_shift_q15( +static void test_zdsp_shift_q15( const q15_t *input1, const q15_t *ref, size_t length) { q15_t *output; @@ -292,7 +296,7 @@ static void test_arm_shift_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_shift_q15(input1, 1, output, length); + zdsp_shift_q15(input1, 1, output, length); /* Validate output */ zassert_true( @@ -307,11 +311,11 @@ static void test_arm_shift_q15( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q15, arm_shift_q15, rand, in_rand, ref_shift, 17); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_shift_q15, possat, in_maxpos, ref_shift_possat, 17); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_shift_q15, negsat, in_maxneg, ref_shift_negsat, 17); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_shift_q15, rand, in_rand, ref_shift, 17); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_shift_q15, possat, in_maxpos, ref_shift_possat, 17); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_shift_q15, negsat, in_maxneg, ref_shift_negsat, 17); -static void test_arm_and_u16( +static void test_zdsp_and_u16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, size_t length) { @@ -322,7 +326,7 @@ static void test_arm_and_u16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_and_u16(input1, input2, output, length); + zdsp_and_u16(input1, input2, output, length); /* Validate output */ zassert_true( @@ -333,11 +337,11 @@ static void test_arm_and_u16( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q15, arm_and_u16, 7, in_bitwise1, in_bitwise2, ref_and, 7); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_and_u16, 16, in_bitwise1, in_bitwise2, ref_and, 16); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_and_u16, 23, in_bitwise1, in_bitwise2, ref_and, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_and_u16, 7, in_bitwise1, in_bitwise2, ref_and, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_and_u16, 16, in_bitwise1, in_bitwise2, ref_and, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_and_u16, 23, in_bitwise1, in_bitwise2, ref_and, 23); -static void test_arm_or_u16( +static void test_zdsp_or_u16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, size_t length) { @@ -348,7 +352,7 @@ static void test_arm_or_u16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_or_u16(input1, input2, output, length); + zdsp_or_u16(input1, input2, output, length); /* Validate output */ zassert_true( @@ -359,11 +363,11 @@ static void test_arm_or_u16( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q15, arm_or_u16, 7, in_bitwise1, in_bitwise2, ref_or, 7); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_or_u16, 16, in_bitwise1, in_bitwise2, ref_or, 16); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_or_u16, 23, in_bitwise1, in_bitwise2, ref_or, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_or_u16, 7, in_bitwise1, in_bitwise2, ref_or, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_or_u16, 16, in_bitwise1, in_bitwise2, ref_or, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_or_u16, 23, in_bitwise1, in_bitwise2, ref_or, 23); -static void test_arm_not_u16( +static void test_zdsp_not_u16( const uint16_t *input1, const uint16_t *ref, size_t length) { uint16_t *output; @@ -373,7 +377,7 @@ static void test_arm_not_u16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_not_u16(input1, output, length); + zdsp_not_u16(input1, output, length); /* Validate output */ zassert_true( @@ -384,11 +388,11 @@ static void test_arm_not_u16( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q15, arm_not_u16, 7, in_bitwise1, ref_not, 7); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_not_u16, 16, in_bitwise1, ref_not, 16); -DEFINE_TEST_VARIANT3(basic_math_q15, arm_not_u16, 23, in_bitwise1, ref_not, 23); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_not_u16, 7, in_bitwise1, ref_not, 7); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_not_u16, 16, in_bitwise1, ref_not, 16); +DEFINE_TEST_VARIANT3(basic_math_q15, zdsp_not_u16, 23, in_bitwise1, ref_not, 23); -static void test_arm_xor_u16( +static void test_zdsp_xor_u16( const uint16_t *input1, const uint16_t *input2, const uint16_t *ref, size_t length) { @@ -399,7 +403,7 @@ static void test_arm_xor_u16( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_xor_u16(input1, input2, output, length); + zdsp_xor_u16(input1, input2, output, length); /* Validate output */ zassert_true( @@ -410,11 +414,11 @@ static void test_arm_xor_u16( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q15, arm_xor_u16, 7, in_bitwise1, in_bitwise2, ref_xor, 7); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_xor_u16, 16, in_bitwise1, in_bitwise2, ref_xor, 16); -DEFINE_TEST_VARIANT4(basic_math_q15, arm_xor_u16, 23, in_bitwise1, in_bitwise2, ref_xor, 23); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_xor_u16, 7, in_bitwise1, in_bitwise2, ref_xor, 7); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_xor_u16, 16, in_bitwise1, in_bitwise2, ref_xor, 16); +DEFINE_TEST_VARIANT4(basic_math_q15, zdsp_xor_u16, 23, in_bitwise1, in_bitwise2, ref_xor, 23); -static void test_arm_clip_q15( +static void test_zdsp_clip_q15( const q15_t *input, const q15_t *ref, q15_t min, q15_t max, size_t length) { q15_t *output; @@ -424,7 +428,7 @@ static void test_arm_clip_q15( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_clip_q15(input, output, min, max, length); + zdsp_clip_q15(input, output, min, max, length); /* Validate output */ zassert_true( @@ -435,11 +439,11 @@ static void test_arm_clip_q15( free(output); } -DEFINE_TEST_VARIANT5(basic_math_q15, arm_clip_q15, c000_f333, in_clip, ref_clip1, +DEFINE_TEST_VARIANT5(basic_math_q15, zdsp_clip_q15, c000_f333, in_clip, ref_clip1, 0xc000, 0xf333, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(basic_math_q15, arm_clip_q15, c000_4000, in_clip, ref_clip2, +DEFINE_TEST_VARIANT5(basic_math_q15, zdsp_clip_q15, c000_4000, in_clip, ref_clip2, 0xc000, 0x4000, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(basic_math_q15, arm_clip_q15, 0ccd_4000, in_clip, ref_clip3, +DEFINE_TEST_VARIANT5(basic_math_q15, zdsp_clip_q15, 0ccd_4000, in_clip, ref_clip3, 0x0ccd, 0x4000, ARRAY_SIZE(ref_clip3)); ZTEST_SUITE(basic_math_q15, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/dsp/basicmath/src/q31.c b/tests/subsys/dsp/basicmath/src/q31.c index 87b8048c27dc6..7027d8c194cf1 100644 --- a/tests/subsys/dsp/basicmath/src/q31.c +++ b/tests/subsys/dsp/basicmath/src/q31.c @@ -5,10 +5,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include #include -#include #include "common/test_common.h" #include "q31.pat" @@ -17,7 +17,7 @@ #define ABS_ERROR_THRESH_Q31 ((q31_t)4) #define ABS_ERROR_THRESH_Q63 ((q63_t)(1 << 17)) -static void test_arm_add_q31( +static void test_zdsp_add_q31( const q31_t *input1, const q31_t *input2, const q31_t *ref, size_t length) { q31_t *output; @@ -27,7 +27,7 @@ static void test_arm_add_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_add_q31(input1, input2, output, length); + zdsp_add_q31(input1, input2, output, length); /* Validate output */ zassert_true( @@ -42,15 +42,15 @@ static void test_arm_add_q31( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, 3, in_com1, in_com2, ref_add, 3); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, 8, in_com1, in_com2, ref_add, 8); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, 11, in_com1, in_com2, ref_add, 11); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, possat, in_maxpos, in_maxpos, ref_add_possat, 9); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, negsat, in_maxneg, in_maxneg, ref_add_negsat, 9); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_add_q31, long, in_com1, in_com2, ref_add, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_add_q31, 3, in_com1, in_com2, ref_add, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_add_q31, 8, in_com1, in_com2, ref_add, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_add_q31, 11, in_com1, in_com2, ref_add, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_add_q31, possat, in_maxpos, in_maxpos, ref_add_possat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_add_q31, negsat, in_maxneg, in_maxneg, ref_add_negsat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_add_q31, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); -static void test_arm_sub_q31( +static void test_zdsp_sub_q31( const q31_t *input1, const q31_t *input2, const q31_t *ref, size_t length) { q31_t *output; @@ -60,7 +60,7 @@ static void test_arm_sub_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_sub_q31(input1, input2, output, length); + zdsp_sub_q31(input1, input2, output, length); /* Validate output */ zassert_true( @@ -75,15 +75,15 @@ static void test_arm_sub_q31( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, 3, in_com1, in_com2, ref_sub, 3); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, 8, in_com1, in_com2, ref_sub, 8); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, 11, in_com1, in_com2, ref_sub, 11); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, possat, in_maxpos, in_maxneg, ref_sub_possat, 9); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 9); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_sub_q31, long, in_com1, in_com2, ref_sub, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_sub_q31, 3, in_com1, in_com2, ref_sub, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_sub_q31, 8, in_com1, in_com2, ref_sub, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_sub_q31, 11, in_com1, in_com2, ref_sub, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_sub_q31, possat, in_maxpos, in_maxneg, ref_sub_possat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_sub_q31, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 9); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_sub_q31, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); -static void test_arm_mult_q31( +static void test_zdsp_mult_q31( const q31_t *input1, const q31_t *input2, const q31_t *ref, size_t length) { q31_t *output; @@ -93,7 +93,7 @@ static void test_arm_mult_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_mult_q31(input1, input2, output, length); + zdsp_mult_q31(input1, input2, output, length); /* Validate output */ zassert_true( @@ -108,15 +108,15 @@ static void test_arm_mult_q31( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, 3, in_com1, in_com2, ref_mult, 3); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, 8, in_com1, in_com2, ref_mult, 8); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, 11, in_com1, in_com2, ref_mult, 11); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, possat, in_maxneg2, in_maxneg2, ref_mult_possat, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_mult_q31, 3, in_com1, in_com2, ref_mult, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_mult_q31, 8, in_com1, in_com2, ref_mult, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_mult_q31, 11, in_com1, in_com2, ref_mult, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_mult_q31, possat, in_maxneg2, in_maxneg2, ref_mult_possat, 9); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_mult_q31, long, in_com1, in_com2, ref_mult, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_mult_q31, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); -static void test_arm_negate_q31( +static void test_zdsp_negate_q31( const q31_t *input1, const q31_t *ref, size_t length) { q31_t *output; @@ -126,7 +126,7 @@ static void test_arm_negate_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_negate_q31(input1, output, length); + zdsp_negate_q31(input1, output, length); /* Validate output */ zassert_true( @@ -141,14 +141,14 @@ static void test_arm_negate_q31( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, 3, in_com1, ref_negate, 3); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, 8, in_com1, ref_negate, 8); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, 11, in_com1, ref_negate, 11); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, possat, in_maxneg2, ref_negate_possat, 9); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_negate_q31, long, in_com1, ref_negate, +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_negate_q31, 3, in_com1, ref_negate, 3); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_negate_q31, 8, in_com1, ref_negate, 8); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_negate_q31, 11, in_com1, ref_negate, 11); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_negate_q31, possat, in_maxneg2, ref_negate_possat, 9); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_negate_q31, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); -static void test_arm_offset_q31( +static void test_zdsp_offset_q31( const q31_t *input1, q31_t scalar, const q31_t *ref, size_t length) { q31_t *output; @@ -158,7 +158,7 @@ static void test_arm_offset_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_offset_q31(input1, scalar, output, length); + zdsp_offset_q31(input1, scalar, output, length); /* Validate output */ zassert_true( @@ -173,17 +173,17 @@ static void test_arm_offset_q31( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, 0p5_3, in_com1, 0x40000000, ref_offset, 3); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, 0p5_8, in_com1, 0x40000000, ref_offset, 8); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, 0p5_11, in_com1, 0x40000000, ref_offset, 11); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, possat, in_maxpos, 0x73333333, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_offset_q31, 0p5_3, in_com1, 0x40000000, ref_offset, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_offset_q31, 0p5_8, in_com1, 0x40000000, ref_offset, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_offset_q31, 0p5_11, in_com1, 0x40000000, ref_offset, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_offset_q31, possat, in_maxpos, 0x73333333, ref_offset_possat, 9); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, negsat, in_maxneg, 0x8ccccccd, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_offset_q31, negsat, in_maxneg, 0x8ccccccd, ref_offset_negsat, 9); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_offset_q31, long, in_com1, 0x40000000, ref_offset, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_offset_q31, long, in_com1, 0x40000000, ref_offset, ARRAY_SIZE(in_com1)); -static void test_arm_scale_q31( +static void test_zdsp_scale_q31( const q31_t *input1, q31_t scalar, const q31_t *ref, size_t length) { q31_t *output; @@ -193,7 +193,7 @@ static void test_arm_scale_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_scale_q31(input1, scalar, 0, output, length); + zdsp_scale_q31(input1, scalar, 0, output, length); /* Validate output */ zassert_true( @@ -208,15 +208,15 @@ static void test_arm_scale_q31( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, 0p5_3, in_com1, 0x40000000, ref_scale, 3); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, 0p5_8, in_com1, 0x40000000, ref_scale, 8); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, 0p5_11, in_com1, 0x40000000, ref_scale, 11); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, possat, in_maxneg2, 0x80000000, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_scale_q31, 0p5_3, in_com1, 0x40000000, ref_scale, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_scale_q31, 0p5_8, in_com1, 0x40000000, ref_scale, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_scale_q31, 0p5_11, in_com1, 0x40000000, ref_scale, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_scale_q31, possat, in_maxneg2, 0x80000000, ref_scale_possat, 9); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_scale_q31, long, in_com1, 0x40000000, ref_scale, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_scale_q31, long, in_com1, 0x40000000, ref_scale, ARRAY_SIZE(in_com1)); -static void test_arm_dot_prod_q31( +static void test_zdsp_dot_prod_q31( const q31_t *input1, const q31_t *input2, const q63_t *ref, size_t length) { q63_t *output; @@ -226,7 +226,7 @@ static void test_arm_dot_prod_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_dot_prod_q31(input1, input2, length, &output[0]); + zdsp_dot_prod_q31(input1, input2, length, &output[0]); /* Validate output */ zassert_true( @@ -241,13 +241,13 @@ static void test_arm_dot_prod_q31( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q31, arm_dot_prod_q31, 3, in_com1, in_com2, ref_dot_prod_3, 3); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_dot_prod_q31, 8, in_com1, in_com2, ref_dot_prod_4, 8); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_dot_prod_q31, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_dot_prod_q31, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_dot_prod_q31, 3, in_com1, in_com2, ref_dot_prod_3, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_dot_prod_q31, 8, in_com1, in_com2, ref_dot_prod_4, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_dot_prod_q31, 11, in_com1, in_com2, ref_dot_prod_4n1, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_dot_prod_q31, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); -static void test_arm_abs_q31( +static void test_zdsp_abs_q31( const q31_t *input1, const q31_t *ref, size_t length) { q31_t *output; @@ -257,7 +257,7 @@ static void test_arm_abs_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_abs_q31(input1, output, length); + zdsp_abs_q31(input1, output, length); /* Validate output */ zassert_true( @@ -272,12 +272,12 @@ static void test_arm_abs_q31( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q31, arm_abs_q31, 3, in_com1, ref_abs, 3); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_abs_q31, 8, in_com1, ref_abs, 8); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_abs_q31, 11, in_com1, ref_abs, 11); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_abs_q31, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_abs_q31, 3, in_com1, ref_abs, 3); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_abs_q31, 8, in_com1, ref_abs, 8); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_abs_q31, 11, in_com1, ref_abs, 11); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_abs_q31, long, in_com1, ref_abs, ARRAY_SIZE(in_com1)); -static void test_arm_shift_q31( +static void test_zdsp_shift_q31( const q31_t *input1, const q31_t *ref, size_t length) { q31_t *output; @@ -287,7 +287,7 @@ static void test_arm_shift_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_shift_q31(input1, 1, output, length); + zdsp_shift_q31(input1, 1, output, length); /* Validate output */ zassert_true( @@ -302,11 +302,11 @@ static void test_arm_shift_q31( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q31, arm_shift_q31, rand, in_rand, ref_shift, 9); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_shift_q31, possat, in_maxpos, ref_shift_possat, 9); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_shift_q31, negsat, in_maxneg, ref_shift_negsat, 9); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_shift_q31, rand, in_rand, ref_shift, 9); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_shift_q31, possat, in_maxpos, ref_shift_possat, 9); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_shift_q31, negsat, in_maxneg, ref_shift_negsat, 9); -static void test_arm_and_u32( +static void test_zdsp_and_u32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) { uint32_t *output; @@ -316,7 +316,7 @@ static void test_arm_and_u32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_and_u32(input1, input2, output, length); + zdsp_and_u32(input1, input2, output, length); /* Validate output */ zassert_true( @@ -327,11 +327,11 @@ static void test_arm_and_u32( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q31, arm_and_u32, 3, in_bitwise1, in_bitwise2, ref_and, 3); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_and_u32, 8, in_bitwise1, in_bitwise2, ref_and, 8); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_and_u32, 11, in_bitwise1, in_bitwise2, ref_and, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_and_u32, 3, in_bitwise1, in_bitwise2, ref_and, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_and_u32, 8, in_bitwise1, in_bitwise2, ref_and, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_and_u32, 11, in_bitwise1, in_bitwise2, ref_and, 11); -static void test_arm_or_u32( +static void test_zdsp_or_u32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) { uint32_t *output; @@ -341,7 +341,7 @@ static void test_arm_or_u32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_or_u32(input1, input2, output, length); + zdsp_or_u32(input1, input2, output, length); /* Validate output */ zassert_true( @@ -352,11 +352,11 @@ static void test_arm_or_u32( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q31, arm_or_u32, 3, in_bitwise1, in_bitwise2, ref_or, 3); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_or_u32, 8, in_bitwise1, in_bitwise2, ref_or, 8); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_or_u32, 11, in_bitwise1, in_bitwise2, ref_or, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_or_u32, 3, in_bitwise1, in_bitwise2, ref_or, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_or_u32, 8, in_bitwise1, in_bitwise2, ref_or, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_or_u32, 11, in_bitwise1, in_bitwise2, ref_or, 11); -static void test_arm_not_u32( +static void test_zdsp_not_u32( const uint32_t *input1, const uint32_t *ref, size_t length) { uint32_t *output; @@ -366,7 +366,7 @@ static void test_arm_not_u32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_not_u32(input1, output, length); + zdsp_not_u32(input1, output, length); /* Validate output */ zassert_true( @@ -377,11 +377,11 @@ static void test_arm_not_u32( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q31, arm_not_u32, 3, in_bitwise1, ref_not, 3); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_not_u32, 8, in_bitwise1, ref_not, 8); -DEFINE_TEST_VARIANT3(basic_math_q31, arm_not_u32, 11, in_bitwise1, ref_not, 11); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_not_u32, 3, in_bitwise1, ref_not, 3); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_not_u32, 8, in_bitwise1, ref_not, 8); +DEFINE_TEST_VARIANT3(basic_math_q31, zdsp_not_u32, 11, in_bitwise1, ref_not, 11); -static void test_arm_xor_u32( +static void test_zdsp_xor_u32( const uint32_t *input1, const uint32_t *input2, const uint32_t *ref, size_t length) { uint32_t *output; @@ -391,7 +391,7 @@ static void test_arm_xor_u32( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_xor_u32(input1, input2, output, length); + zdsp_xor_u32(input1, input2, output, length); /* Validate output */ zassert_true( @@ -402,11 +402,11 @@ static void test_arm_xor_u32( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q31, arm_xor_u32, 3, in_bitwise1, in_bitwise2, ref_xor, 3); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_xor_u32, 8, in_bitwise1, in_bitwise2, ref_xor, 8); -DEFINE_TEST_VARIANT4(basic_math_q31, arm_xor_u32, 11, in_bitwise1, in_bitwise2, ref_xor, 11); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_xor_u32, 3, in_bitwise1, in_bitwise2, ref_xor, 3); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_xor_u32, 8, in_bitwise1, in_bitwise2, ref_xor, 8); +DEFINE_TEST_VARIANT4(basic_math_q31, zdsp_xor_u32, 11, in_bitwise1, in_bitwise2, ref_xor, 11); -static void test_arm_clip_q31( +static void test_zdsp_clip_q31( const q31_t *input, const q31_t *ref, q31_t min, q31_t max, size_t length) { q31_t *output; @@ -416,7 +416,7 @@ static void test_arm_clip_q31( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_clip_q31(input, output, min, max, length); + zdsp_clip_q31(input, output, min, max, length); /* Validate output */ zassert_true( @@ -427,11 +427,11 @@ static void test_arm_clip_q31( free(output); } -DEFINE_TEST_VARIANT5(basic_math_q31, arm_clip_q31, c0000000_f3333333, in_clip, ref_clip1, +DEFINE_TEST_VARIANT5(basic_math_q31, zdsp_clip_q31, c0000000_f3333333, in_clip, ref_clip1, 0xc0000000, 0xf3333333, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(basic_math_q31, arm_clip_q31, c0000000_40000000, in_clip, ref_clip2, +DEFINE_TEST_VARIANT5(basic_math_q31, zdsp_clip_q31, c0000000_40000000, in_clip, ref_clip2, 0xc0000000, 0x40000000, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(basic_math_q31, arm_clip_q31, 0ccccccd_40000000, in_clip, ref_clip3, +DEFINE_TEST_VARIANT5(basic_math_q31, zdsp_clip_q31, 0ccccccd_40000000, in_clip, ref_clip3, 0x0ccccccd, 0x40000000, ARRAY_SIZE(ref_clip3)); ZTEST_SUITE(basic_math_q31, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/dsp/basicmath/src/q7.c b/tests/subsys/dsp/basicmath/src/q7.c index dc9f3979bba6c..1193903810838 100644 --- a/tests/subsys/dsp/basicmath/src/q7.c +++ b/tests/subsys/dsp/basicmath/src/q7.c @@ -5,10 +5,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include #include -#include #include "common/test_common.h" #include "q7.pat" @@ -17,7 +17,7 @@ #define ABS_ERROR_THRESH_Q7 ((q7_t)2) #define ABS_ERROR_THRESH_Q31 ((q31_t)(1 << 15)) -static void test_arm_add_q7( +static void test_zdsp_add_q7( const q7_t *input1, const q7_t *input2, const q7_t *ref, size_t length) { q7_t *output; @@ -27,7 +27,7 @@ static void test_arm_add_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_add_q7(input1, input2, output, length); + zdsp_add_q7(input1, input2, output, length); /* Validate output */ zassert_true( @@ -42,15 +42,15 @@ static void test_arm_add_q7( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, 15, in_com1, in_com2, ref_add, 15); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, 32, in_com1, in_com2, ref_add, 32); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, 47, in_com1, in_com2, ref_add, 47); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, possat, in_maxpos, in_maxpos, ref_add_possat, 33); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, negsat, in_maxneg, in_maxneg, ref_add_negsat, 33); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_add_q7, long, in_com1, in_com2, ref_add, +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_add_q7, 15, in_com1, in_com2, ref_add, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_add_q7, 32, in_com1, in_com2, ref_add, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_add_q7, 47, in_com1, in_com2, ref_add, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_add_q7, possat, in_maxpos, in_maxpos, ref_add_possat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_add_q7, negsat, in_maxneg, in_maxneg, ref_add_negsat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_add_q7, long, in_com1, in_com2, ref_add, ARRAY_SIZE(in_com1)); -static void test_arm_sub_q7( +static void test_zdsp_sub_q7( const q7_t *input1, const q7_t *input2, const q7_t *ref, size_t length) { q7_t *output; @@ -60,7 +60,7 @@ static void test_arm_sub_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_sub_q7(input1, input2, output, length); + zdsp_sub_q7(input1, input2, output, length); /* Validate output */ zassert_true( @@ -75,15 +75,15 @@ static void test_arm_sub_q7( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, 15, in_com1, in_com2, ref_sub, 15); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, 32, in_com1, in_com2, ref_sub, 32); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, 47, in_com1, in_com2, ref_sub, 47); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, possat, in_maxpos, in_maxneg, ref_sub_possat, 33); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 33); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_sub_q7, long, in_com1, in_com2, ref_sub, +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_sub_q7, 15, in_com1, in_com2, ref_sub, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_sub_q7, 32, in_com1, in_com2, ref_sub, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_sub_q7, 47, in_com1, in_com2, ref_sub, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_sub_q7, possat, in_maxpos, in_maxneg, ref_sub_possat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_sub_q7, negsat, in_maxneg, in_maxpos, ref_sub_negsat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_sub_q7, long, in_com1, in_com2, ref_sub, ARRAY_SIZE(in_com1)); -static void test_arm_mult_q7( +static void test_zdsp_mult_q7( const q7_t *input1, const q7_t *input2, const q7_t *ref, size_t length) { q7_t *output; @@ -93,7 +93,7 @@ static void test_arm_mult_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_mult_q7(input1, input2, output, length); + zdsp_mult_q7(input1, input2, output, length); /* Validate output */ zassert_true( @@ -108,15 +108,15 @@ static void test_arm_mult_q7( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, 15, in_com1, in_com2, ref_mult, 15); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, 32, in_com1, in_com2, ref_mult, 32); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, 47, in_com1, in_com2, ref_mult, 47); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, possat, in_maxneg2, in_maxneg2, ref_mult_possat, +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_mult_q7, 15, in_com1, in_com2, ref_mult, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_mult_q7, 32, in_com1, in_com2, ref_mult, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_mult_q7, 47, in_com1, in_com2, ref_mult, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_mult_q7, possat, in_maxneg2, in_maxneg2, ref_mult_possat, 33); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_mult_q7, long, in_com1, in_com2, ref_mult, +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_mult_q7, long, in_com1, in_com2, ref_mult, ARRAY_SIZE(in_com1)); -static void test_arm_negate_q7( +static void test_zdsp_negate_q7( const q7_t *input1, const q7_t *ref, size_t length) { q7_t *output; @@ -126,7 +126,7 @@ static void test_arm_negate_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_negate_q7(input1, output, length); + zdsp_negate_q7(input1, output, length); /* Validate output */ zassert_true( @@ -141,13 +141,13 @@ static void test_arm_negate_q7( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, 15, in_com1, ref_negate, 15); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, 32, in_com1, ref_negate, 32); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, 47, in_com1, ref_negate, 47); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, possat, in_maxneg2, ref_negate_possat, 33); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_negate_q7, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_negate_q7, 15, in_com1, ref_negate, 15); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_negate_q7, 32, in_com1, ref_negate, 32); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_negate_q7, 47, in_com1, ref_negate, 47); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_negate_q7, possat, in_maxneg2, ref_negate_possat, 33); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_negate_q7, long, in_com1, ref_negate, ARRAY_SIZE(in_com1)); -static void test_arm_offset_q7( +static void test_zdsp_offset_q7( const q7_t *input1, q7_t scalar, const q7_t *ref, size_t length) { q7_t *output; @@ -157,7 +157,7 @@ static void test_arm_offset_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_offset_q7(input1, scalar, output, length); + zdsp_offset_q7(input1, scalar, output, length); /* Validate output */ zassert_true( @@ -172,15 +172,15 @@ static void test_arm_offset_q7( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, 0p5_15, in_com1, 0x40, ref_offset, 15); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, 0p5_32, in_com1, 0x40, ref_offset, 32); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, 0p5_47, in_com1, 0x40, ref_offset, 47); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, possat, in_maxpos, 0x73, ref_offset_possat, 33); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, negsat, in_maxneg, 0x8d, ref_offset_negsat, 33); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_offset_q7, long, in_com1, 0x40, ref_offset, +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_offset_q7, 0p5_15, in_com1, 0x40, ref_offset, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_offset_q7, 0p5_32, in_com1, 0x40, ref_offset, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_offset_q7, 0p5_47, in_com1, 0x40, ref_offset, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_offset_q7, possat, in_maxpos, 0x73, ref_offset_possat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_offset_q7, negsat, in_maxneg, 0x8d, ref_offset_negsat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_offset_q7, long, in_com1, 0x40, ref_offset, ARRAY_SIZE(in_com1)); -static void test_arm_scale_q7( +static void test_zdsp_scale_q7( const q7_t *input1, q7_t scalar, const q7_t *ref, size_t length) { q7_t *output; @@ -190,7 +190,7 @@ static void test_arm_scale_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_scale_q7(input1, scalar, 0, output, length); + zdsp_scale_q7(input1, scalar, 0, output, length); /* Validate output */ zassert_true( @@ -205,14 +205,14 @@ static void test_arm_scale_q7( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, 0p5_15, in_com1, 0x40, ref_scale, 15); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, 0p5_32, in_com1, 0x40, ref_scale, 32); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, 0p5_47, in_com1, 0x40, ref_scale, 47); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, possat, in_maxneg2, 0x80, ref_scale_possat, 33); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_scale_q7, long, in_com1, 0x40, ref_scale, +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_scale_q7, 0p5_15, in_com1, 0x40, ref_scale, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_scale_q7, 0p5_32, in_com1, 0x40, ref_scale, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_scale_q7, 0p5_47, in_com1, 0x40, ref_scale, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_scale_q7, possat, in_maxneg2, 0x80, ref_scale_possat, 33); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_scale_q7, long, in_com1, 0x40, ref_scale, ARRAY_SIZE(in_com1)); -static void test_arm_dot_prod_q7( +static void test_zdsp_dot_prod_q7( const q7_t *input1, const q7_t *input2, const q31_t *ref, size_t length) { @@ -223,7 +223,7 @@ static void test_arm_dot_prod_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_dot_prod_q7(input1, input2, length, &output[0]); + zdsp_dot_prod_q7(input1, input2, length, &output[0]); /* Validate output */ zassert_true( @@ -238,13 +238,13 @@ static void test_arm_dot_prod_q7( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q7, arm_dot_prod_q7, 15, in_com1, in_com2, ref_dot_prod_3, 15); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_dot_prod_q7, 32, in_com1, in_com2, ref_dot_prod_4, 32); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_dot_prod_q7, 47, in_com1, in_com2, ref_dot_prod_4n1, 47); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_dot_prod_q7, long, in_com1, in_com2, ref_dot_prod_long, +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_dot_prod_q7, 15, in_com1, in_com2, ref_dot_prod_3, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_dot_prod_q7, 32, in_com1, in_com2, ref_dot_prod_4, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_dot_prod_q7, 47, in_com1, in_com2, ref_dot_prod_4n1, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_dot_prod_q7, long, in_com1, in_com2, ref_dot_prod_long, ARRAY_SIZE(in_com1)); -static void test_arm_abs_q7( +static void test_zdsp_abs_q7( const q7_t *input1, const q7_t *ref, size_t length) { q7_t *output; @@ -254,7 +254,7 @@ static void test_arm_abs_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_abs_q7(input1, output, length); + zdsp_abs_q7(input1, output, length); /* Validate output */ zassert_true( @@ -269,12 +269,12 @@ static void test_arm_abs_q7( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q7, arm_abs_q7, 15, in_com1, ref_abs, 15); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_abs_q7, 32, in_com1, ref_abs, 32); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_abs_q7, 47, in_com1, ref_abs, 47); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_abs_q7, long, in_com1, ref_abs, ARRAY_SIZE(ref_abs)); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_abs_q7, 15, in_com1, ref_abs, 15); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_abs_q7, 32, in_com1, ref_abs, 32); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_abs_q7, 47, in_com1, ref_abs, 47); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_abs_q7, long, in_com1, ref_abs, ARRAY_SIZE(ref_abs)); -static void test_arm_shift_q7( +static void test_zdsp_shift_q7( const q7_t *input1, const q7_t *ref, size_t length) { q7_t *output; @@ -284,7 +284,7 @@ static void test_arm_shift_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_shift_q7(input1, 1, output, length); + zdsp_shift_q7(input1, 1, output, length); /* Validate output */ zassert_true( @@ -299,11 +299,11 @@ static void test_arm_shift_q7( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q7, arm_shift_q7, rand, in_rand, ref_shift, 33); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_shift_q7, possat, in_maxpos, ref_shift_possat, 33); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_shift_q7, negsat, in_maxneg, ref_shift_negsat, 33); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_shift_q7, rand, in_rand, ref_shift, 33); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_shift_q7, possat, in_maxpos, ref_shift_possat, 33); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_shift_q7, negsat, in_maxneg, ref_shift_negsat, 33); -static void test_arm_and_u8( +static void test_zdsp_and_u8( const uint8_t *input1, const uint8_t *input2, const uint8_t *ref, size_t length) { uint8_t *output; @@ -313,7 +313,7 @@ static void test_arm_and_u8( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_and_u8(input1, input2, output, length); + zdsp_and_u8(input1, input2, output, length); /* Validate output */ zassert_true( @@ -324,11 +324,11 @@ static void test_arm_and_u8( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q7, arm_and_u8, 15, in_bitwise1, in_bitwise2, ref_and, 15); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_and_u8, 32, in_bitwise1, in_bitwise2, ref_and, 32); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_and_u8, 47, in_bitwise1, in_bitwise2, ref_and, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_and_u8, 15, in_bitwise1, in_bitwise2, ref_and, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_and_u8, 32, in_bitwise1, in_bitwise2, ref_and, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_and_u8, 47, in_bitwise1, in_bitwise2, ref_and, 47); -static void test_arm_or_u8( +static void test_zdsp_or_u8( const uint8_t *input1, const uint8_t *input2, const uint8_t *ref, size_t length) { uint8_t *output; @@ -338,7 +338,7 @@ static void test_arm_or_u8( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_or_u8(input1, input2, output, length); + zdsp_or_u8(input1, input2, output, length); /* Validate output */ zassert_true( @@ -349,11 +349,11 @@ static void test_arm_or_u8( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q7, arm_or_u8, 15, in_bitwise1, in_bitwise2, ref_or, 15); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_or_u8, 32, in_bitwise1, in_bitwise2, ref_or, 32); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_or_u8, 47, in_bitwise1, in_bitwise2, ref_or, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_or_u8, 15, in_bitwise1, in_bitwise2, ref_or, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_or_u8, 32, in_bitwise1, in_bitwise2, ref_or, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_or_u8, 47, in_bitwise1, in_bitwise2, ref_or, 47); -static void test_arm_not_u8( +static void test_zdsp_not_u8( const uint8_t *input1, const uint8_t *ref, size_t length) { uint8_t *output; @@ -363,7 +363,7 @@ static void test_arm_not_u8( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_not_u8(input1, output, length); + zdsp_not_u8(input1, output, length); /* Validate output */ zassert_true( @@ -374,11 +374,11 @@ static void test_arm_not_u8( free(output); } -DEFINE_TEST_VARIANT3(basic_math_q7, arm_not_u8, 15, in_bitwise1, ref_not, 15); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_not_u8, 32, in_bitwise1, ref_not, 32); -DEFINE_TEST_VARIANT3(basic_math_q7, arm_not_u8, 47, in_bitwise1, ref_not, 47); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_not_u8, 15, in_bitwise1, ref_not, 15); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_not_u8, 32, in_bitwise1, ref_not, 32); +DEFINE_TEST_VARIANT3(basic_math_q7, zdsp_not_u8, 47, in_bitwise1, ref_not, 47); -static void test_arm_xor_u8( +static void test_zdsp_xor_u8( const uint8_t *input1, const uint8_t *input2, const uint8_t *ref, size_t length) { uint8_t *output; @@ -388,7 +388,7 @@ static void test_arm_xor_u8( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_xor_u8(input1, input2, output, length); + zdsp_xor_u8(input1, input2, output, length); /* Validate output */ zassert_true( @@ -399,11 +399,11 @@ static void test_arm_xor_u8( free(output); } -DEFINE_TEST_VARIANT4(basic_math_q7, arm_xor_u8, 15, in_bitwise1, in_bitwise2, ref_xor, 15); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_xor_u8, 32, in_bitwise1, in_bitwise2, ref_xor, 32); -DEFINE_TEST_VARIANT4(basic_math_q7, arm_xor_u8, 47, in_bitwise1, in_bitwise2, ref_xor, 47); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_xor_u8, 15, in_bitwise1, in_bitwise2, ref_xor, 15); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_xor_u8, 32, in_bitwise1, in_bitwise2, ref_xor, 32); +DEFINE_TEST_VARIANT4(basic_math_q7, zdsp_xor_u8, 47, in_bitwise1, in_bitwise2, ref_xor, 47); -static void test_arm_clip_q7( +static void test_zdsp_clip_q7( const q7_t *input, const q7_t *ref, q7_t min, q7_t max, size_t length) { q7_t *output; @@ -413,7 +413,7 @@ static void test_arm_clip_q7( zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED); /* Run test function */ - arm_clip_q7(input, output, min, max, length); + zdsp_clip_q7(input, output, min, max, length); /* Validate output */ zassert_true( @@ -424,11 +424,11 @@ static void test_arm_clip_q7( free(output); } -DEFINE_TEST_VARIANT5(basic_math_q7, arm_clip_q7, c0_f3, in_clip, ref_clip1, 0xc0, 0xf3, +DEFINE_TEST_VARIANT5(basic_math_q7, zdsp_clip_q7, c0_f3, in_clip, ref_clip1, 0xc0, 0xf3, ARRAY_SIZE(ref_clip1)); -DEFINE_TEST_VARIANT5(basic_math_q7, arm_clip_q7, c0_40, in_clip, ref_clip2, 0xc0, 0x40, +DEFINE_TEST_VARIANT5(basic_math_q7, zdsp_clip_q7, c0_40, in_clip, ref_clip2, 0xc0, 0x40, ARRAY_SIZE(ref_clip2)); -DEFINE_TEST_VARIANT5(basic_math_q7, arm_clip_q7, 0d_40, in_clip, ref_clip3, 0x0d, 0x40, +DEFINE_TEST_VARIANT5(basic_math_q7, zdsp_clip_q7, 0d_40, in_clip, ref_clip3, 0x0d, 0x40, ARRAY_SIZE(ref_clip3)); ZTEST_SUITE(basic_math_q7, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/dsp/basicmath/testcase.yaml b/tests/subsys/dsp/basicmath/testcase.yaml index 49166351b8a15..b0cd202d3ffdc 100644 --- a/tests/subsys/dsp/basicmath/testcase.yaml +++ b/tests/subsys/dsp/basicmath/testcase.yaml @@ -1,20 +1,20 @@ tests: - libraries.cmsis_dsp.basicmath: - filter: ((CONFIG_CPU_AARCH32_CORTEX_R or CONFIG_CPU_CORTEX_M) and TOOLCHAIN_HAS_NEWLIB == 1) or CONFIG_ARCH_POSIX + zdsp.basicmath: + filter: TOOLCHAIN_HAS_NEWLIB == 1 or CONFIG_ARCH_POSIX integration_platforms: - frdm_k64f - sam_e70_xplained - mps2_an521 - native_posix - tags: cmsis_dsp + tags: zdsp min_flash: 128 min_ram: 64 - libraries.cmsis_dsp.basicmath.fpu: - filter: ((CONFIG_CPU_AARCH32_CORTEX_R or CONFIG_CPU_CORTEX_M) and CONFIG_CPU_HAS_FPU and TOOLCHAIN_HAS_NEWLIB == 1) or CONFIG_ARCH_POSIX + zdsp.basicmath.fpu: + filter: (CONFIG_CPU_HAS_FPU and TOOLCHAIN_HAS_NEWLIB == 1) or CONFIG_ARCH_POSIX integration_platforms: - mps2_an521_remote - mps3_an547 - tags: cmsis_dsp fpu + tags: zdsp fpu extra_configs: - CONFIG_FPU=y min_flash: 128