1 /* Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
2  * SPDX-License-Identifier: Apache-2.0
3  */
4 
5 /**
6  * @file zephyr/dsp/basicmath.h
7  *
8  * @brief Public APIs for DSP basicmath
9  */
10 
11 #ifndef INCLUDE_ZEPHYR_DSP_BASICMATH_H_
12 #define INCLUDE_ZEPHYR_DSP_BASICMATH_H_
13 
14 #include <zephyr/dsp/dsp.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /**
21  * @ingroup math_dsp
22  * @defgroup math_dsp_basic Basic Math Functions
23  */
24 
25 /**
26  * @ingroup math_dsp_basic
27  * @addtogroup math_dsp_basic_mult Vector Multiplication
28  *
29  * Element-by-element multiplication of two vectors.
30  * <pre>
31  *     dst[n] = src_a[n] * src_b[n],   0 <= n < block_size.
32  * </pre>
33  * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
34  * @{
35  */
36 
37 /**
38  * @brief Q7 vector multiplication.
39  *
40  * @par Scaling and Overflow Behavior
41  *   The function uses saturating arithmetic.
42  *   Results outside of the allowable Q7 range [0x80 0x7F] are saturated.
43  *
44  * @param[in]  src_a      points to the first input vector
45  * @param[in]  src_b      points to the second input vector
46  * @param[out] dst        points to the output vector
47  * @param[in]  block_size number of samples in each vector
48  */
49 DSP_FUNC_SCOPE void zdsp_mult_q7(const DSP_DATA q7_t *src_a, const DSP_DATA q7_t *src_b,
50 				DSP_DATA q7_t *dst, uint32_t block_size);
51 
52 /**
53  * @brief Q15 vector multiplication.
54  *
55  * @par Scaling and Overflow Behavior
56  *   The function uses saturating arithmetic.
57  *   Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated.
58  *
59  * @param[in]  src_a      points to the first input vector
60  * @param[in]  src_b      points to the second input vector
61  * @param[out] dst        points to the output vector
62  * @param[in]  block_size number of samples in each vector
63  */
64 DSP_FUNC_SCOPE void zdsp_mult_q15(const DSP_DATA q15_t *src_a, const DSP_DATA q15_t *src_b,
65 				DSP_DATA q15_t *dst, uint32_t block_size);
66 
67 /**
68  * @brief Q31 vector multiplication.
69  *
70  * @par Scaling and Overflow Behavior
71  *   The function uses saturating arithmetic.
72  *   Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] are saturated.
73  *
74  * @param[in]  src_a      points to the first input vector
75  * @param[in]  src_b      points to the second input vector
76  * @param[out] dst        points to the output vector
77  * @param[in]  block_size number of samples in each vector
78  */
79 DSP_FUNC_SCOPE void zdsp_mult_q31(const DSP_DATA q31_t *src_a, const DSP_DATA q31_t *src_b,
80 				DSP_DATA q31_t *dst, uint32_t block_size);
81 
82 /**
83  * @brief Floating-point vector multiplication.
84  * @param[in]  src_a      points to the first input vector
85  * @param[in]  src_b      points to the second input vector
86  * @param[out] dst        points to the output vector
87  * @param[in]  block_size number of samples in each vector
88  */
89 DSP_FUNC_SCOPE void zdsp_mult_f32(const DSP_DATA float32_t *src_a, const DSP_DATA float32_t *src_b,
90 				DSP_DATA float32_t *dst, uint32_t block_size);
91 
92 /**
93  * @}
94  */
95 
96 /**
97  * @ingroup math_dsp_basic
98  * @addtogroup math_dsp_basic_add Vector Addition
99  *
100  * Element-by-element addition of two vectors.
101  * <pre>
102  *     dst[n] = src_a[n] + src_b[n],   0 <= n < block_size.
103  * </pre>
104  * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
105  * @{
106  */
107 
108 /**
109  * @brief Floating-point vector addition.
110  * @param[in]  src_a      points to the first input vector
111  * @param[in]  src_b      points to the second input vector
112  * @param[out] dst        points to the output vector
113  * @param[in]  block_size number of samples in each vector
114  */
115 DSP_FUNC_SCOPE void zdsp_add_f32(const DSP_DATA float32_t *src_a, const DSP_DATA float32_t *src_b,
116 				DSP_DATA float32_t *dst, uint32_t block_size);
117 
118 /**
119  * @brief Q7 vector addition.
120  *
121  * @par Scaling and Overflow Behavior
122  *   The function uses saturating arithmetic.
123  *   Results outside of the allowable Q7 range [0x80 0x7F] are saturated.
124  *
125  * @param[in]  src_a      points to the first input vector
126  * @param[in]  src_b      points to the second input vector
127  * @param[out] dst        points to the output vector
128  * @param[in]  block_size number of samples in each vector
129  */
130 DSP_FUNC_SCOPE void zdsp_add_q7(const DSP_DATA q7_t *src_a, const DSP_DATA q7_t *src_b,
131 				DSP_DATA q7_t *dst, uint32_t block_size);
132 
133 /**
134  * @brief Q15 vector addition.
135  *
136  * @par Scaling and Overflow Behavior
137  *   The function uses saturating arithmetic.
138  *   Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated.
139  *
140  * @param[in]  src_a      points to the first input vector
141  * @param[in]  src_b      points to the second input vector
142  * @param[out] dst        points to the output vector
143  * @param[in]  block_size number of samples in each vector
144  */
145 DSP_FUNC_SCOPE void zdsp_add_q15(const DSP_DATA q15_t *src_a, const DSP_DATA q15_t *src_b,
146 				DSP_DATA q15_t *dst, uint32_t block_size);
147 
148 /**
149  * @brief Q31 vector addition.
150  *
151  * @par Scaling and Overflow Behavior
152  *   The function uses saturating arithmetic.
153  *   Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated.
154  *
155  * @param[in]  src_a      points to the first input vector
156  * @param[in]  src_b      points to the second input vector
157  * @param[out] dst        points to the output vector
158  * @param[in]  block_size number of samples in each vector
159  */
160 DSP_FUNC_SCOPE void zdsp_add_q31(const DSP_DATA q31_t *src_a, const DSP_DATA q31_t *src_b,
161 				DSP_DATA q31_t *dst, uint32_t block_size);
162 
163 /**
164  * @}
165  */
166 
167 /**
168  * @ingroup math_dsp_basic
169  * @addtogroup math_dsp_basic_sub Vector Subtraction
170  *
171  * Element-by-element subtraction of two vectors.
172  * <pre>
173  *     dst[n] = src_a[n] - src_b[n],   0 <= n < block_size.
174  * </pre>
175  * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
176  * @{
177  */
178 
179 /**
180  * @brief Floating-point vector subtraction.
181  * @param[in]  src_a      points to the first input vector
182  * @param[in]  src_b      points to the second input vector
183  * @param[out] dst        points to the output vector
184  * @param[in]  block_size number of samples in each vector
185  */
186 DSP_FUNC_SCOPE void zdsp_sub_f32(const DSP_DATA float32_t *src_a, const DSP_DATA float32_t *src_b,
187 				DSP_DATA float32_t *dst, uint32_t block_size);
188 
189 /**
190  * @brief Q7 vector subtraction.
191  *
192  * @par Scaling and Overflow Behavior
193  *   The function uses saturating arithmetic.
194  *   Results outside of the allowable Q7 range [0x80 0x7F] will be saturated.
195  *
196  * @param[in]  src_a      points to the first input vector
197  * @param[in]  src_b      points to the second input vector
198  * @param[out] dst        points to the output vector
199  * @param[in]  block_size number of samples in each vector
200  */
201 DSP_FUNC_SCOPE void zdsp_sub_q7(const DSP_DATA q7_t *src_a, const DSP_DATA q7_t *src_b,
202 				DSP_DATA q7_t *dst, uint32_t block_size);
203 
204 /**
205  * @brief Q15 vector subtraction.
206  *
207  * @par Scaling and Overflow Behavior
208  *   The function uses saturating arithmetic.
209  *   Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated.
210  *
211  * @param[in]  src_a      points to the first input vector
212  * @param[in]  src_b      points to the second input vector
213  * @param[out] dst        points to the output vector
214  * @param[in]  block_size number of samples in each vector
215  */
216 DSP_FUNC_SCOPE void zdsp_sub_q15(const DSP_DATA q15_t *src_a, const DSP_DATA q15_t *src_b,
217 				DSP_DATA q15_t *dst, uint32_t block_size);
218 
219 /**
220  * @brief Q31 vector subtraction.
221  *
222  * @par Scaling and Overflow Behavior
223  *   The function uses saturating arithmetic.
224  *   Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated.
225  *
226  * @param[in]  src_a      points to the first input vector
227  * @param[in]  src_b      points to the second input vector
228  * @param[out] dst        points to the output vector
229  * @param[in]  block_size number of samples in each vector
230  */
231 DSP_FUNC_SCOPE void zdsp_sub_q31(const DSP_DATA q31_t *src_a, const DSP_DATA q31_t *src_b,
232 				DSP_DATA q31_t *dst, uint32_t block_size);
233 
234 /**
235  * @}
236  */
237 
238 /**
239  * @ingroup math_dsp_basic
240  * @addtogroup math_dsp_basic_scale Vector Scale
241  *
242  * Multiply a vector by a scalar value. For floating-point data, the algorithm used is:
243  * <pre>
244  *     dst[n] = src[n] * scale,   0 <= n < block_size.
245  * </pre>
246  *
247  * In the fixed-point Q7, Q15, and Q31 functions, scale is represented by a fractional
248  * multiplication <code>scale_fract</code> and an arithmetic shift <code>shift</code>. The shift
249  * allows the gain of the scaling operation to exceed 1.0. The algorithm used with fixed-point data
250  * is:
251  * <pre>
252  *     dst[n] = (src[n] * scale_fract) << shift,   0 <= n < block_size.
253  * </pre>
254  *
255  * The overall scale factor applied to the fixed-point data is
256  * <pre>
257  *     scale = scale_fract * 2^shift.
258  * </pre>
259  * The functions support in-place computation allowing the source and destination pointers to
260  * reference the same memory buffer.
261  * @{
262  */
263 
264 /**
265  * @brief Multiplies a floating-point vector by a scalar.
266  * @param[in]  src        points to the input vector
267  * @param[in]  scale      scale factor to be applied
268  * @param[out] dst        points to the output vector
269  * @param[in]  block_size number of samples in the vector
270  */
271 DSP_FUNC_SCOPE void zdsp_scale_f32(const DSP_DATA float32_t *src, float32_t scale,
272 				DSP_DATA float32_t *dst, uint32_t block_size);
273 
274 /**
275  * @brief Multiplies a Q7 vector by a scalar.
276  *
277  * @par Scaling and Overflow Behavior
278  *   The input data <code>*src</code> and <code>scale_fract</code> are in 1.7 format.
279  *   These are multiplied to yield a 2.14 intermediate result and this is shifted with saturation to
280  *   1.7 format.
281  *
282  * @param[in]  src         points to the input vector
283  * @param[in]  scale_fract fractional portion of the scale value
284  * @param[in]  shift       number of bits to shift the result by
285  * @param[out] dst         points to the output vector
286  * @param[in]  block_size  number of samples in the vector
287  */
288 DSP_FUNC_SCOPE void zdsp_scale_q7(const DSP_DATA q7_t *src, q7_t scale_fract, int8_t shift,
289 				DSP_DATA q7_t *dst, uint32_t block_size);
290 
291 /**
292  * @brief Multiplies a Q15 vector by a scalar.
293  *
294  * @par Scaling and Overflow Behavior
295  *   The input data <code>*src</code> and <code>scale_fract</code> are in 1.15 format.
296  *   These are multiplied to yield a 2.30 intermediate result and this is shifted with saturation to
297  *   1.15 format.
298  *
299  * @param[in]  src         points to the input vector
300  * @param[in]  scale_fract fractional portion of the scale value
301  * @param[in]  shift       number of bits to shift the result by
302  * @param[out] dst         points to the output vector
303  * @param[in]  block_size  number of samples in the vector
304  */
305 DSP_FUNC_SCOPE void zdsp_scale_q15(const DSP_DATA q15_t *src, q15_t scale_fract, int8_t shift,
306 				DSP_DATA q15_t *dst, uint32_t block_size);
307 
308 /**
309  * @brief Multiplies a Q31 vector by a scalar.
310  *
311  * @par Scaling and Overflow Behavior
312  *   The input data <code>*src</code> and <code>scale_fract</code> are in 1.31 format.
313  *   These are multiplied to yield a 2.62 intermediate result and this is shifted with saturation to
314  *   1.31 format.
315  *
316  * @param[in]  src         points to the input vector
317  * @param[in]  scale_fract fractional portion of the scale value
318  * @param[in]  shift       number of bits to shift the result by
319  * @param[out] dst         points to the output vector
320  * @param[in]  block_size  number of samples in the vector
321  */
322 DSP_FUNC_SCOPE void zdsp_scale_q31(const DSP_DATA q31_t *src, q31_t scale_fract, int8_t shift,
323 				DSP_DATA q31_t *dst, uint32_t block_size);
324 
325 /**
326  * @}
327  */
328 
329 /**
330  * @ingroup math_dsp_basic
331  * @addtogroup math_dsp_basic_abs Vector Absolute Value
332  *
333  * Computes the absolute value of a vector on an element-by-element basis.
334  * <pre>
335  *     dst[n] = abs(src[n]),   0 <= n < block_size.
336  * </pre>
337  * The functions support in-place computation allowing the source and destination pointers to
338  * reference the same memory buffer. There are separate functions for floating-point, Q7, Q15, and
339  * Q31 data types.
340  * @{
341  */
342 
343 /**
344  * @brief Floating-point vector absolute value.
345  * @param[in]  src        points to the input buffer
346  * @param[out] dst        points to the output buffer
347  * @param[in]  block_size number of samples in each vector
348  */
349 DSP_FUNC_SCOPE void zdsp_abs_f32(const DSP_DATA float32_t *src, DSP_DATA float32_t *dst,
350 				uint32_t block_size);
351 
352 /**
353  * @brief Q7 vector absolute value.
354  *
355  * @par Scaling and Overflow Behavior
356  *   The function uses saturating arithmetic.
357  *   The Q7 value -1 (0x80) will be saturated to the maximum allowable positive value 0x7F.
358  *
359  * @param[in]  src        points to the input buffer
360  * @param[out] dst        points to the output buffer
361  * @param[in]  block_size number of samples in each vector
362  */
363 DSP_FUNC_SCOPE void zdsp_abs_q7(const DSP_DATA q7_t *src, DSP_DATA q7_t *dst, uint32_t block_size);
364 
365 /**
366  * @brief Q15 vector absolute value.
367  *
368  * @par Scaling and Overflow Behavior
369  *   The function uses saturating arithmetic.
370  *   The Q15 value -1 (0x8000) will be saturated to the maximum allowable positive value 0x7FFF.
371  *
372  * @param[in]  src        points to the input buffer
373  * @param[out] dst        points to the output buffer
374  * @param[in]  block_size number of samples in each vector
375  */
376 DSP_FUNC_SCOPE void zdsp_abs_q15(const DSP_DATA q15_t *src, DSP_DATA q15_t *dst,
377 				uint32_t block_size);
378 
379 /**
380  * @brief Q31 vector absolute value.
381  *
382  * @par Scaling and Overflow Behavior
383  *   The function uses saturating arithmetic.
384  *   The Q31 value -1 (0x80000000) will be saturated to the maximum allowable positive value
385  *   0x7FFFFFFF.
386  *
387  * @param[in]  src        points to the input buffer
388  * @param[out] dst        points to the output buffer
389  * @param[in]  block_size number of samples in each vector
390  */
391 DSP_FUNC_SCOPE void zdsp_abs_q31(const DSP_DATA q31_t *src, DSP_DATA q31_t *dst,
392 				uint32_t block_size);
393 
394 /**
395  * @}
396  */
397 
398 /**
399  * @ingroup math_dsp_basic
400  * @addtogroup math_dsp_basic_dot Vector Dot Product
401  *
402  * Computes the dot product of two vectors. The vectors are multiplied element-by-element and then
403  * summed.
404  * <pre>
405  *     sum = src_a[0]*src_b[0] + src_a[1]*src_b[1] + ... + src_a[block_size-1]*src_b[block_size-1]
406  * </pre>
407  * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
408  * @{
409  */
410 
411 /**
412  * @brief Dot product of floating-point vectors.
413  * @param[in]  src_a      points to the first input vector
414  * @param[in]  src_b      points to the second input vector
415  * @param[in]  block_size number of samples in each vector
416  * @param[out] result     output result returned here
417  */
418 DSP_FUNC_SCOPE void zdsp_dot_prod_f32(const DSP_DATA float32_t *src_a,
419 				const DSP_DATA float32_t *src_b, uint32_t block_size,
420 				DSP_DATA float32_t *result);
421 
422 /**
423  * @brief Dot product of Q7 vectors.
424  *
425  * @par Scaling and Overflow Behavior
426  *   The intermediate multiplications are in 1.7 x 1.7 = 2.14 format and these results are added to
427  *   an accumulator in 18.14 format. Nonsaturating additions are used and there is no danger of wrap
428  *   around as long as the vectors are less than 2^18 elements long. The return result is in 18.14
429  *   format.
430  *
431  * @param[in]  src_a      points to the first input vector
432  * @param[in]  src_b      points to the second input vector
433  * @param[in]  block_size number of samples in each vector
434  * @param[out] result     output result returned here
435  */
436 DSP_FUNC_SCOPE void zdsp_dot_prod_q7(const DSP_DATA q7_t *src_a, const DSP_DATA q7_t *src_b,
437 				uint32_t block_size, DSP_DATA q31_t *result);
438 
439 /**
440  * @brief Dot product of Q15 vectors.
441  *
442  * @par Scaling and Overflow Behavior
443  *   The intermediate multiplications are in 1.15 x 1.15 = 2.30 format and these results are added
444  *   to a 64-bit accumulator in 34.30 format. Nonsaturating additions are used and given that there
445  *   are 33 guard bits in the accumulator there is no risk of overflow. The return result is in
446  *   34.30 format.
447  *
448  * @param[in]  src_a      points to the first input vector
449  * @param[in]  src_b      points to the second input vector
450  * @param[in]  block_size number of samples in each vector
451  * @param[out] result     output result returned here
452  */
453 DSP_FUNC_SCOPE void zdsp_dot_prod_q15(const DSP_DATA q15_t *src_a, const DSP_DATA q15_t *src_b,
454 				uint32_t block_size, DSP_DATA q63_t *result);
455 
456 /**
457  * @brief Dot product of Q31 vectors.
458  *
459  * @par Scaling and Overflow Behavior
460  *   The intermediate multiplications are in 1.31 x 1.31 = 2.62 format and these are truncated to
461  *   2.48 format by discarding the lower 14 bits. The 2.48 result is then added without saturation
462  *   to a 64-bit accumulator in 16.48 format. There are 15 guard bits in the accumulator and there
463  *   is no risk of overflow as long as the length of the vectors is less than 2^16 elements. The
464  *   return result is in 16.48 format.
465  *
466  * @param[in]  src_a      points to the first input vector
467  * @param[in]  src_b      points to the second input vector
468  * @param[in]  block_size number of samples in each vector
469  * @param[out] result     output result returned here
470  */
471 DSP_FUNC_SCOPE void zdsp_dot_prod_q31(const DSP_DATA q31_t *src_a, const DSP_DATA q31_t *src_b,
472 				uint32_t block_size, DSP_DATA q63_t *result);
473 
474 /**
475  * @}
476  */
477 
478 /**
479  * @ingroup math_dsp_basic
480  * @addtogroup math_dsp_basic_shift Vector Shift
481  *
482  * Shifts the elements of a fixed-point vector by a specified number of bits.
483  * There are separate functions for Q7, Q15, and Q31 data types. The underlying algorithm used is:
484  * <pre>
485  *     dst[n] = src[n] << shift,   0 <= n < block_size.
486  * </pre>
487  * If <code>shift</code> is positive then the elements of the vector are shifted to the left.
488  * If <code>shift</code> is negative then the elements of the vector are shifted to the right.
489  *
490  * The functions support in-place computation allowing the source and destination pointers to
491  * reference the same memory buffer.
492  * @{
493  */
494 
495 /**
496  * @brief  Shifts the elements of a Q7 vector a specified number of bits.
497  *
498  * @par Scaling and Overflow Behavior
499  *   The function uses saturating arithmetic.
500  *   Results outside of the allowable Q7 range [0x80 0x7F] are saturated.
501  *
502  * @param[in]  src        points to the input vector
503  * @param[in]  shift_bits number of bits to shift.  A positive value shifts left; a negative value
504  *                        shifts right.
505  * @param[out] dst        points to the output vector
506  * @param[in]  block_size number of samples in the vector
507  */
508 DSP_FUNC_SCOPE void zdsp_shift_q7(const DSP_DATA q7_t *src, int8_t shift_bits, DSP_DATA q7_t *dst,
509 				uint32_t block_size);
510 
511 /**
512  * @brief  Shifts the elements of a Q15 vector a specified number of bits.
513  *
514  * @pre Scaling and Overflow Behavior
515  *   The function uses saturating arithmetic.
516  *   Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated.
517  *
518  * @param[in]  src        points to the input vector
519  * @param[in]  shift_bits number of bits to shift.  A positive value shifts left; a negative value
520  *                        shifts right.
521  * @param[out] dst        points to the output vector
522  * @param[in]  block_size number of samples in the vector
523  */
524 DSP_FUNC_SCOPE void zdsp_shift_q15(const DSP_DATA q15_t *src, int8_t shift_bits,
525 				DSP_DATA q15_t *dst, uint32_t block_size);
526 
527 /**
528  * @brief  Shifts the elements of a Q31 vector a specified number of bits.
529  *
530  * @par Scaling and Overflow Behavior
531  *   The function uses saturating arithmetic.
532  *   Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated.
533  *
534  * @param[in]  src       points to the input vector
535  * @param[in]  shift_bits  number of bits to shift.  A positive value shifts left; a negative value
536  * shifts right.
537  * @param[out] dst       points to the output vector
538  * @param[in]  block_size  number of samples in the vector
539  */
540 DSP_FUNC_SCOPE void zdsp_shift_q31(const DSP_DATA q31_t *src, int8_t shift_bits,
541 				DSP_DATA q31_t *dst, uint32_t block_size);
542 
543 /**
544  * @}
545  */
546 
547 /**
548  * @ingroup math_dsp_basic
549  * @addtogroup math_dsp_basic_offset Vector Offset
550  *
551  * Adds a constant offset to each element of a vector.
552  * <pre>
553  *     dst[n] = src[n] + offset,   0 <= n < block_size.
554  * </pre>
555  * The functions support in-place computation allowing the source and destination pointers to
556  * reference the same memory buffer. There are separate functions for floating-point, Q7, Q15, and
557  * Q31 data types.
558  *
559  * @{
560  */
561 
562 /**
563  * @brief  Adds a constant offset to a floating-point vector.
564  * @param[in]  src       points to the input vector
565  * @param[in]  offset     is the offset to be added
566  * @param[out] dst       points to the output vector
567  * @param[in]  block_size  number of samples in the vector
568  */
569 DSP_FUNC_SCOPE void zdsp_offset_f32(const DSP_DATA float32_t *src, float32_t offset,
570 				DSP_DATA float32_t *dst, uint32_t block_size);
571 
572 /**
573  * @brief  Adds a constant offset to a Q7 vector.
574  *
575  * @par Scaling and Overflow Behavior
576  *   The function uses saturating arithmetic.
577  *   Results outside of the allowable Q7 range [0x80 0x7F] are saturated.
578  *
579  * @param[in]  src       points to the input vector
580  * @param[in]  offset     is the offset to be added
581  * @param[out] dst       points to the output vector
582  * @param[in]  block_size  number of samples in the vector
583  */
584 DSP_FUNC_SCOPE void zdsp_offset_q7(const DSP_DATA q7_t *src, q7_t offset, DSP_DATA q7_t *dst,
585 				uint32_t block_size);
586 
587 /**
588  * @brief  Adds a constant offset to a Q15 vector.
589  *
590  * @par Scaling and Overflow Behavior
591  *   The function uses saturating arithmetic.
592  *   Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated.
593  *
594  * @param[in]  src        points to the input vector
595  * @param[in]  offset     is the offset to be added
596  * @param[out] dst        points to the output vector
597  * @param[in]  block_size number of samples in the vector
598  */
599 DSP_FUNC_SCOPE void zdsp_offset_q15(const DSP_DATA q15_t *src, q15_t offset, DSP_DATA q15_t *dst,
600 				uint32_t block_size);
601 
602 /**
603  * @brief  Adds a constant offset to a Q31 vector.
604  *
605  * @par Scaling and Overflow Behavior
606  *   The function uses saturating arithmetic.
607  *   Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated.
608  *
609  * @param[in]  src       points to the input vector
610  * @param[in]  offset     is the offset to be added
611  * @param[out] dst       points to the output vector
612  * @param[in]  block_size  number of samples in the vector
613  */
614 DSP_FUNC_SCOPE void zdsp_offset_q31(const DSP_DATA q31_t *src, q31_t offset, DSP_DATA q31_t *dst,
615 				uint32_t block_size);
616 
617 /**
618  * @}
619  */
620 
621 /**
622  * @ingroup math_dsp_basic
623  * @addtogroup math_dsp_basic_negate Vector Negate
624  *
625  * Negates the elements of a vector.
626  * <pre>
627  *     dst[n] = -src[n],   0 <= n < block_size.
628  * </pre>
629  * The functions support in-place computation allowing the source and destination pointers to
630  * reference the same memory buffer. There are separate functions for floating-point, Q7, Q15, and
631  * Q31 data types.
632  *
633  * @{
634  */
635 
636 /**
637  * @brief  Negates the elements of a floating-point vector.
638  * @param[in]  src        points to the input vector
639  * @param[out] dst        points to the output vector
640  * @param[in]  block_size number of samples in the vector
641  */
642 DSP_FUNC_SCOPE void zdsp_negate_f32(const DSP_DATA float32_t *src, DSP_DATA float32_t *dst,
643 				uint32_t block_size);
644 
645 /**
646  * @brief  Negates the elements of a Q7 vector.
647  *
648  * @par Scaling and Overflow Behavior
649  *   The function uses saturating arithmetic.
650  *   The Q7 value -1 (0x80) is saturated to the maximum allowable positive value 0x7F.
651  *
652  * @param[in]  src        points to the input vector
653  * @param[out] dst        points to the output vector
654  * @param[in]  block_size number of samples in the vector
655  */
656 DSP_FUNC_SCOPE void zdsp_negate_q7(const DSP_DATA q7_t *src, DSP_DATA q7_t *dst,
657 				uint32_t block_size);
658 
659 /**
660  * @brief  Negates the elements of a Q15 vector.
661  *
662  * @par Scaling and Overflow Behavior
663  *   The function uses saturating arithmetic.
664  *   The Q15 value -1 (0x8000) is saturated to the maximum allowable positive value 0x7FFF.
665  *
666  * @param[in]  src        points to the input vector
667  * @param[out] dst        points to the output vector
668  * @param[in]  block_size number of samples in the vector
669  */
670 DSP_FUNC_SCOPE void zdsp_negate_q15(const DSP_DATA q15_t *src, DSP_DATA q15_t *dst,
671 				uint32_t block_size);
672 
673 /**
674  * @brief  Negates the elements of a Q31 vector.
675  *
676  * @par Scaling and Overflow Behavior
677  *   The function uses saturating arithmetic.
678  *   The Q31 value -1 (0x80000000) is saturated to the maximum allowable positive value 0x7FFFFFFF.
679  *
680  * @param[in]  src        points to the input vector
681  * @param[out] dst        points to the output vector
682  * @param[in]  block_size number of samples in the vector
683  */
684 DSP_FUNC_SCOPE void zdsp_negate_q31(const DSP_DATA q31_t *src, DSP_DATA q31_t *dst,
685 				uint32_t block_size);
686 
687 /**
688  * @}
689  */
690 
691 /**
692  * @ingroup math_dsp_basic
693  * @addtogroup math_dsp_basic_and Vector bitwise AND
694  *
695  * Compute the logical bitwise AND.
696  *
697  * There are separate functions for uint32_t, uint16_t, and uint7_t data types.
698  * @{
699  */
700 
701 /**
702  * @brief         Compute the logical bitwise AND of two fixed-point vectors.
703  * @param[in]     src_a      points to input vector A
704  * @param[in]     src_b      points to input vector B
705  * @param[out]    dst        points to output vector
706  * @param[in]     block_size number of samples in each vector
707  */
708 DSP_FUNC_SCOPE void zdsp_and_u8(const DSP_DATA uint8_t *src_a, const DSP_DATA uint8_t *src_b,
709 				DSP_DATA uint8_t *dst, uint32_t block_size);
710 
711 /**
712  * @brief         Compute the logical bitwise AND of two fixed-point vectors.
713  * @param[in]     src_a      points to input vector A
714  * @param[in]     src_b      points to input vector B
715  * @param[out]    dst        points to output vector
716  * @param[in]     block_size number of samples in each vector
717  */
718 DSP_FUNC_SCOPE void zdsp_and_u16(const DSP_DATA uint16_t *src_a, const DSP_DATA uint16_t *src_b,
719 				DSP_DATA uint16_t *dst, uint32_t block_size);
720 
721 /**
722  * @brief         Compute the logical bitwise AND of two fixed-point vectors.
723  * @param[in]     src_a      points to input vector A
724  * @param[in]     src_b      points to input vector B
725  * @param[out]    dst        points to output vector
726  * @param[in]     block_size number of samples in each vector
727  */
728 DSP_FUNC_SCOPE void zdsp_and_u32(const DSP_DATA uint32_t *src_a, const DSP_DATA uint32_t *src_b,
729 				DSP_DATA uint32_t *dst, uint32_t block_size);
730 
731 /**
732  * @}
733  */
734 
735 /**
736  * @ingroup math_dsp_basic
737  * @addtogroup math_dsp_basic_or Vector bitwise OR
738  *
739  * Compute the logical bitwise OR.
740  *
741  * There are separate functions for uint32_t, uint16_t, and uint7_t data types.
742  * @{
743  */
744 
745 /**
746  * @brief         Compute the logical bitwise OR of two fixed-point vectors.
747  * @param[in]     src_a      points to input vector A
748  * @param[in]     src_b      points to input vector B
749  * @param[out]    dst        points to output vector
750  * @param[in]     block_size number of samples in each vector
751  */
752 DSP_FUNC_SCOPE void zdsp_or_u8(const DSP_DATA uint8_t *src_a, const DSP_DATA uint8_t *src_b,
753 				DSP_DATA uint8_t *dst, uint32_t block_size);
754 
755 /**
756  * @brief         Compute the logical bitwise OR of two fixed-point vectors.
757  * @param[in]     src_a      points to input vector A
758  * @param[in]     src_b      points to input vector B
759  * @param[out]    dst        points to output vector
760  * @param[in]     block_size number of samples in each vector
761  */
762 DSP_FUNC_SCOPE void zdsp_or_u16(const DSP_DATA uint16_t *src_a, const DSP_DATA uint16_t *src_b,
763 				DSP_DATA uint16_t *dst, uint32_t block_size);
764 
765 /**
766  * @brief         Compute the logical bitwise OR of two fixed-point vectors.
767  * @param[in]     src_a      points to input vector A
768  * @param[in]     src_b      points to input vector B
769  * @param[out]    dst        points to output vector
770  * @param[in]     block_size number of samples in each vector
771  */
772 DSP_FUNC_SCOPE void zdsp_or_u32(const DSP_DATA uint32_t *src_a, const DSP_DATA uint32_t *src_b,
773 				DSP_DATA uint32_t *dst, uint32_t block_size);
774 
775 /**
776  * @}
777  */
778 
779 /**
780  * @ingroup math_dsp_basic
781  * @addtogroup math_dsp_basic_not Vector bitwise NOT
782  *
783  * Compute the logical bitwise NOT.
784  *
785  * There are separate functions for uint32_t, uint16_t, and uint7_t data types.
786  * @{
787  */
788 
789 /**
790  * @brief         Compute the logical bitwise NOT of a fixed-point vector.
791  * @param[in]     src        points to input vector
792  * @param[out]    dst        points to output vector
793  * @param[in]     block_size number of samples in each vector
794  */
795 DSP_FUNC_SCOPE void zdsp_not_u8(const DSP_DATA uint8_t *src, DSP_DATA uint8_t *dst,
796 				uint32_t block_size);
797 
798 /**
799  * @brief         Compute the logical bitwise NOT of a fixed-point vector.
800  * @param[in]     src        points to input vector
801  * @param[out]    dst        points to output vector
802  * @param[in]     block_size number of samples in each vector
803  */
804 DSP_FUNC_SCOPE void zdsp_not_u16(const DSP_DATA uint16_t *src, DSP_DATA uint16_t *dst,
805 				uint32_t block_size);
806 
807 /**
808  * @brief         Compute the logical bitwise NOT of a fixed-point vector.
809  * @param[in]     src        points to input vector
810  * @param[out]    dst        points to output vector
811  * @param[in]     block_size number of samples in each vector
812  */
813 DSP_FUNC_SCOPE void zdsp_not_u32(const DSP_DATA uint32_t *src, DSP_DATA uint32_t *dst,
814 				uint32_t block_size);
815 
816 /**
817  * @}
818  */
819 
820 /**
821  * @ingroup math_dsp_basic
822  * @addtogroup math_dsp_basic_xor Vector bitwise XOR
823  *
824  * Compute the logical bitwise XOR.
825  *
826  * There are separate functions for uint32_t, uint16_t, and uint7_t data types.
827  * @{
828  */
829 
830 /**
831  * @brief         Compute the logical bitwise XOR of two fixed-point vectors.
832  * @param[in]     src_a      points to input vector A
833  * @param[in]     src_b      points to input vector B
834  * @param[out]    dst        points to output vector
835  * @param[in]     block_size number of samples in each vector
836  */
837 DSP_FUNC_SCOPE void zdsp_xor_u8(const DSP_DATA uint8_t *src_a, const DSP_DATA uint8_t *src_b,
838 				DSP_DATA uint8_t *dst, uint32_t block_size);
839 
840 /**
841  * @brief         Compute the logical bitwise XOR of two fixed-point vectors.
842  * @param[in]     src_a      points to input vector A
843  * @param[in]     src_b      points to input vector B
844  * @param[out]    dst        points to output vector
845  * @param[in]     block_size number of samples in each vector
846  */
847 DSP_FUNC_SCOPE void zdsp_xor_u16(const DSP_DATA uint16_t *src_a, const DSP_DATA uint16_t *src_b,
848 				DSP_DATA uint16_t *dst, uint32_t block_size);
849 
850 /**
851  * @brief         Compute the logical bitwise XOR of two fixed-point vectors.
852  * @param[in]     src_a      points to input vector A
853  * @param[in]     src_b      points to input vector B
854  * @param[out]    dst        points to output vector
855  * @param[in]     block_size number of samples in each vector
856  */
857 DSP_FUNC_SCOPE void zdsp_xor_u32(const DSP_DATA uint32_t *src_a, const DSP_DATA uint32_t *src_b,
858 				DSP_DATA uint32_t *dst, uint32_t block_size);
859 
860 /**
861  * @}
862  */
863 
864 /**
865  * @ingroup math_dsp_basic
866  * @addtogroup math_dsp_basic_clip Vector Clipping
867  *
868  * Element-by-element clipping of a value.
869  *
870  * The value is constrained between 2 bounds.
871  *
872  * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
873  * @{
874  */
875 
876 /**
877  * @brief         Elementwise floating-point clipping
878  * @param[in]     src          points to input values
879  * @param[out]    dst          points to output clipped values
880  * @param[in]     low          lower bound
881  * @param[in]     high         higher bound
882  * @param[in]     num_samples  number of samples to clip
883  */
884 DSP_FUNC_SCOPE void zdsp_clip_f32(const DSP_DATA float32_t *src, DSP_DATA float32_t *dst,
885 				float32_t low, float32_t high, uint32_t num_samples);
886 
887 /**
888  * @brief         Elementwise fixed-point clipping
889  * @param[in]     src          points to input values
890  * @param[out]    dst          points to output clipped values
891  * @param[in]     low          lower bound
892  * @param[in]     high         higher bound
893  * @param[in]     num_samples  number of samples to clip
894  */
895 DSP_FUNC_SCOPE void zdsp_clip_q31(const DSP_DATA q31_t *src, DSP_DATA q31_t *dst, q31_t low,
896 				q31_t high, uint32_t num_samples);
897 
898 /**
899  * @brief         Elementwise fixed-point clipping
900  * @param[in]     src          points to input values
901  * @param[out]    dst          points to output clipped values
902  * @param[in]     low          lower bound
903  * @param[in]     high         higher bound
904  * @param[in]     num_samples  number of samples to clip
905  */
906 DSP_FUNC_SCOPE void zdsp_clip_q15(const DSP_DATA q15_t *src, DSP_DATA q15_t *dst, q15_t low,
907 				q15_t high, uint32_t num_samples);
908 
909 /**
910  * @brief         Elementwise fixed-point clipping
911  * @param[in]     src          points to input values
912  * @param[out]    dst          points to output clipped values
913  * @param[in]     low          lower bound
914  * @param[in]     high         higher bound
915  * @param[in]     num_samples  number of samples to clip
916  */
917 DSP_FUNC_SCOPE void zdsp_clip_q7(const DSP_DATA q7_t *src, DSP_DATA q7_t *dst, q7_t low, q7_t high,
918 				uint32_t num_samples);
919 
920 /**
921  * @}
922  */
923 
924 #ifdef __cplusplus
925 }
926 #endif
927 
928 #ifdef CONFIG_FP16
929 #include <zephyr/dsp/basicmath_f16.h>
930 #endif /* CONFIG_FP16 */
931 
932 #endif /* INCLUDE_ZEPHYR_DSP_BASICMATH_H_ */
933