basic_math_functions.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /******************************************************************************
  2. * @file basic_math_functions.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.9.0
  5. * @date 20. July 2020
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #ifndef _BASIC_MATH_FUNCTIONS_H_
  25. #define _BASIC_MATH_FUNCTIONS_H_
  26. #include "arm_math_types.h"
  27. #include "arm_math_memory.h"
  28. #include "dsp/none.h"
  29. #include "dsp/utils.h"
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. /**
  35. * @defgroup groupMath Basic Math Functions
  36. */
  37. /**
  38. * @brief Q7 vector multiplication.
  39. * @param[in] pSrcA points to the first input vector
  40. * @param[in] pSrcB points to the second input vector
  41. * @param[out] pDst points to the output vector
  42. * @param[in] blockSize number of samples in each vector
  43. */
  44. void arm_mult_q7(
  45. const q7_t * pSrcA,
  46. const q7_t * pSrcB,
  47. q7_t * pDst,
  48. uint32_t blockSize);
  49. /**
  50. * @brief Q15 vector multiplication.
  51. * @param[in] pSrcA points to the first input vector
  52. * @param[in] pSrcB points to the second input vector
  53. * @param[out] pDst points to the output vector
  54. * @param[in] blockSize number of samples in each vector
  55. */
  56. void arm_mult_q15(
  57. const q15_t * pSrcA,
  58. const q15_t * pSrcB,
  59. q15_t * pDst,
  60. uint32_t blockSize);
  61. /**
  62. * @brief Q31 vector multiplication.
  63. * @param[in] pSrcA points to the first input vector
  64. * @param[in] pSrcB points to the second input vector
  65. * @param[out] pDst points to the output vector
  66. * @param[in] blockSize number of samples in each vector
  67. */
  68. void arm_mult_q31(
  69. const q31_t * pSrcA,
  70. const q31_t * pSrcB,
  71. q31_t * pDst,
  72. uint32_t blockSize);
  73. /**
  74. * @brief Floating-point vector multiplication.
  75. * @param[in] pSrcA points to the first input vector
  76. * @param[in] pSrcB points to the second input vector
  77. * @param[out] pDst points to the output vector
  78. * @param[in] blockSize number of samples in each vector
  79. */
  80. void arm_mult_f32(
  81. const float32_t * pSrcA,
  82. const float32_t * pSrcB,
  83. float32_t * pDst,
  84. uint32_t blockSize);
  85. /**
  86. * @brief Floating-point vector addition.
  87. * @param[in] pSrcA points to the first input vector
  88. * @param[in] pSrcB points to the second input vector
  89. * @param[out] pDst points to the output vector
  90. * @param[in] blockSize number of samples in each vector
  91. */
  92. void arm_add_f32(
  93. const float32_t * pSrcA,
  94. const float32_t * pSrcB,
  95. float32_t * pDst,
  96. uint32_t blockSize);
  97. /**
  98. * @brief Q7 vector addition.
  99. * @param[in] pSrcA points to the first input vector
  100. * @param[in] pSrcB points to the second input vector
  101. * @param[out] pDst points to the output vector
  102. * @param[in] blockSize number of samples in each vector
  103. */
  104. void arm_add_q7(
  105. const q7_t * pSrcA,
  106. const q7_t * pSrcB,
  107. q7_t * pDst,
  108. uint32_t blockSize);
  109. /**
  110. * @brief Q15 vector addition.
  111. * @param[in] pSrcA points to the first input vector
  112. * @param[in] pSrcB points to the second input vector
  113. * @param[out] pDst points to the output vector
  114. * @param[in] blockSize number of samples in each vector
  115. */
  116. void arm_add_q15(
  117. const q15_t * pSrcA,
  118. const q15_t * pSrcB,
  119. q15_t * pDst,
  120. uint32_t blockSize);
  121. /**
  122. * @brief Q31 vector addition.
  123. * @param[in] pSrcA points to the first input vector
  124. * @param[in] pSrcB points to the second input vector
  125. * @param[out] pDst points to the output vector
  126. * @param[in] blockSize number of samples in each vector
  127. */
  128. void arm_add_q31(
  129. const q31_t * pSrcA,
  130. const q31_t * pSrcB,
  131. q31_t * pDst,
  132. uint32_t blockSize);
  133. /**
  134. * @brief Floating-point vector subtraction.
  135. * @param[in] pSrcA points to the first input vector
  136. * @param[in] pSrcB points to the second input vector
  137. * @param[out] pDst points to the output vector
  138. * @param[in] blockSize number of samples in each vector
  139. */
  140. void arm_sub_f32(
  141. const float32_t * pSrcA,
  142. const float32_t * pSrcB,
  143. float32_t * pDst,
  144. uint32_t blockSize);
  145. /**
  146. * @brief Q7 vector subtraction.
  147. * @param[in] pSrcA points to the first input vector
  148. * @param[in] pSrcB points to the second input vector
  149. * @param[out] pDst points to the output vector
  150. * @param[in] blockSize number of samples in each vector
  151. */
  152. void arm_sub_q7(
  153. const q7_t * pSrcA,
  154. const q7_t * pSrcB,
  155. q7_t * pDst,
  156. uint32_t blockSize);
  157. /**
  158. * @brief Q15 vector subtraction.
  159. * @param[in] pSrcA points to the first input vector
  160. * @param[in] pSrcB points to the second input vector
  161. * @param[out] pDst points to the output vector
  162. * @param[in] blockSize number of samples in each vector
  163. */
  164. void arm_sub_q15(
  165. const q15_t * pSrcA,
  166. const q15_t * pSrcB,
  167. q15_t * pDst,
  168. uint32_t blockSize);
  169. /**
  170. * @brief Q31 vector subtraction.
  171. * @param[in] pSrcA points to the first input vector
  172. * @param[in] pSrcB points to the second input vector
  173. * @param[out] pDst points to the output vector
  174. * @param[in] blockSize number of samples in each vector
  175. */
  176. void arm_sub_q31(
  177. const q31_t * pSrcA,
  178. const q31_t * pSrcB,
  179. q31_t * pDst,
  180. uint32_t blockSize);
  181. /**
  182. * @brief Multiplies a floating-point vector by a scalar.
  183. * @param[in] pSrc points to the input vector
  184. * @param[in] scale scale factor to be applied
  185. * @param[out] pDst points to the output vector
  186. * @param[in] blockSize number of samples in the vector
  187. */
  188. void arm_scale_f32(
  189. const float32_t * pSrc,
  190. float32_t scale,
  191. float32_t * pDst,
  192. uint32_t blockSize);
  193. /**
  194. * @brief Multiplies a Q7 vector by a scalar.
  195. * @param[in] pSrc points to the input vector
  196. * @param[in] scaleFract fractional portion of the scale value
  197. * @param[in] shift number of bits to shift the result by
  198. * @param[out] pDst points to the output vector
  199. * @param[in] blockSize number of samples in the vector
  200. */
  201. void arm_scale_q7(
  202. const q7_t * pSrc,
  203. q7_t scaleFract,
  204. int8_t shift,
  205. q7_t * pDst,
  206. uint32_t blockSize);
  207. /**
  208. * @brief Multiplies a Q15 vector by a scalar.
  209. * @param[in] pSrc points to the input vector
  210. * @param[in] scaleFract fractional portion of the scale value
  211. * @param[in] shift number of bits to shift the result by
  212. * @param[out] pDst points to the output vector
  213. * @param[in] blockSize number of samples in the vector
  214. */
  215. void arm_scale_q15(
  216. const q15_t * pSrc,
  217. q15_t scaleFract,
  218. int8_t shift,
  219. q15_t * pDst,
  220. uint32_t blockSize);
  221. /**
  222. * @brief Multiplies a Q31 vector by a scalar.
  223. * @param[in] pSrc points to the input vector
  224. * @param[in] scaleFract fractional portion of the scale value
  225. * @param[in] shift number of bits to shift the result by
  226. * @param[out] pDst points to the output vector
  227. * @param[in] blockSize number of samples in the vector
  228. */
  229. void arm_scale_q31(
  230. const q31_t * pSrc,
  231. q31_t scaleFract,
  232. int8_t shift,
  233. q31_t * pDst,
  234. uint32_t blockSize);
  235. /**
  236. * @brief Q7 vector absolute value.
  237. * @param[in] pSrc points to the input buffer
  238. * @param[out] pDst points to the output buffer
  239. * @param[in] blockSize number of samples in each vector
  240. */
  241. void arm_abs_q7(
  242. const q7_t * pSrc,
  243. q7_t * pDst,
  244. uint32_t blockSize);
  245. /**
  246. * @brief Floating-point vector absolute value.
  247. * @param[in] pSrc points to the input buffer
  248. * @param[out] pDst points to the output buffer
  249. * @param[in] blockSize number of samples in each vector
  250. */
  251. void arm_abs_f32(
  252. const float32_t * pSrc,
  253. float32_t * pDst,
  254. uint32_t blockSize);
  255. /**
  256. * @brief Q15 vector absolute value.
  257. * @param[in] pSrc points to the input buffer
  258. * @param[out] pDst points to the output buffer
  259. * @param[in] blockSize number of samples in each vector
  260. */
  261. void arm_abs_q15(
  262. const q15_t * pSrc,
  263. q15_t * pDst,
  264. uint32_t blockSize);
  265. /**
  266. * @brief Q31 vector absolute value.
  267. * @param[in] pSrc points to the input buffer
  268. * @param[out] pDst points to the output buffer
  269. * @param[in] blockSize number of samples in each vector
  270. */
  271. void arm_abs_q31(
  272. const q31_t * pSrc,
  273. q31_t * pDst,
  274. uint32_t blockSize);
  275. /**
  276. * @brief Dot product of floating-point vectors.
  277. * @param[in] pSrcA points to the first input vector
  278. * @param[in] pSrcB points to the second input vector
  279. * @param[in] blockSize number of samples in each vector
  280. * @param[out] result output result returned here
  281. */
  282. void arm_dot_prod_f32(
  283. const float32_t * pSrcA,
  284. const float32_t * pSrcB,
  285. uint32_t blockSize,
  286. float32_t * result);
  287. /**
  288. * @brief Dot product of Q7 vectors.
  289. * @param[in] pSrcA points to the first input vector
  290. * @param[in] pSrcB points to the second input vector
  291. * @param[in] blockSize number of samples in each vector
  292. * @param[out] result output result returned here
  293. */
  294. void arm_dot_prod_q7(
  295. const q7_t * pSrcA,
  296. const q7_t * pSrcB,
  297. uint32_t blockSize,
  298. q31_t * result);
  299. /**
  300. * @brief Dot product of Q15 vectors.
  301. * @param[in] pSrcA points to the first input vector
  302. * @param[in] pSrcB points to the second input vector
  303. * @param[in] blockSize number of samples in each vector
  304. * @param[out] result output result returned here
  305. */
  306. void arm_dot_prod_q15(
  307. const q15_t * pSrcA,
  308. const q15_t * pSrcB,
  309. uint32_t blockSize,
  310. q63_t * result);
  311. /**
  312. * @brief Dot product of Q31 vectors.
  313. * @param[in] pSrcA points to the first input vector
  314. * @param[in] pSrcB points to the second input vector
  315. * @param[in] blockSize number of samples in each vector
  316. * @param[out] result output result returned here
  317. */
  318. void arm_dot_prod_q31(
  319. const q31_t * pSrcA,
  320. const q31_t * pSrcB,
  321. uint32_t blockSize,
  322. q63_t * result);
  323. /**
  324. * @brief Shifts the elements of a Q7 vector a specified number of bits.
  325. * @param[in] pSrc points to the input vector
  326. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  327. * @param[out] pDst points to the output vector
  328. * @param[in] blockSize number of samples in the vector
  329. */
  330. void arm_shift_q7(
  331. const q7_t * pSrc,
  332. int8_t shiftBits,
  333. q7_t * pDst,
  334. uint32_t blockSize);
  335. /**
  336. * @brief Shifts the elements of a Q15 vector a specified number of bits.
  337. * @param[in] pSrc points to the input vector
  338. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  339. * @param[out] pDst points to the output vector
  340. * @param[in] blockSize number of samples in the vector
  341. */
  342. void arm_shift_q15(
  343. const q15_t * pSrc,
  344. int8_t shiftBits,
  345. q15_t * pDst,
  346. uint32_t blockSize);
  347. /**
  348. * @brief Shifts the elements of a Q31 vector a specified number of bits.
  349. * @param[in] pSrc points to the input vector
  350. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  351. * @param[out] pDst points to the output vector
  352. * @param[in] blockSize number of samples in the vector
  353. */
  354. void arm_shift_q31(
  355. const q31_t * pSrc,
  356. int8_t shiftBits,
  357. q31_t * pDst,
  358. uint32_t blockSize);
  359. /**
  360. * @brief Adds a constant offset to a floating-point vector.
  361. * @param[in] pSrc points to the input vector
  362. * @param[in] offset is the offset to be added
  363. * @param[out] pDst points to the output vector
  364. * @param[in] blockSize number of samples in the vector
  365. */
  366. void arm_offset_f32(
  367. const float32_t * pSrc,
  368. float32_t offset,
  369. float32_t * pDst,
  370. uint32_t blockSize);
  371. /**
  372. * @brief Adds a constant offset to a Q7 vector.
  373. * @param[in] pSrc points to the input vector
  374. * @param[in] offset is the offset to be added
  375. * @param[out] pDst points to the output vector
  376. * @param[in] blockSize number of samples in the vector
  377. */
  378. void arm_offset_q7(
  379. const q7_t * pSrc,
  380. q7_t offset,
  381. q7_t * pDst,
  382. uint32_t blockSize);
  383. /**
  384. * @brief Adds a constant offset to a Q15 vector.
  385. * @param[in] pSrc points to the input vector
  386. * @param[in] offset is the offset to be added
  387. * @param[out] pDst points to the output vector
  388. * @param[in] blockSize number of samples in the vector
  389. */
  390. void arm_offset_q15(
  391. const q15_t * pSrc,
  392. q15_t offset,
  393. q15_t * pDst,
  394. uint32_t blockSize);
  395. /**
  396. * @brief Adds a constant offset to a Q31 vector.
  397. * @param[in] pSrc points to the input vector
  398. * @param[in] offset is the offset to be added
  399. * @param[out] pDst points to the output vector
  400. * @param[in] blockSize number of samples in the vector
  401. */
  402. void arm_offset_q31(
  403. const q31_t * pSrc,
  404. q31_t offset,
  405. q31_t * pDst,
  406. uint32_t blockSize);
  407. /**
  408. * @brief Negates the elements of a floating-point vector.
  409. * @param[in] pSrc points to the input vector
  410. * @param[out] pDst points to the output vector
  411. * @param[in] blockSize number of samples in the vector
  412. */
  413. void arm_negate_f32(
  414. const float32_t * pSrc,
  415. float32_t * pDst,
  416. uint32_t blockSize);
  417. /**
  418. * @brief Negates the elements of a Q7 vector.
  419. * @param[in] pSrc points to the input vector
  420. * @param[out] pDst points to the output vector
  421. * @param[in] blockSize number of samples in the vector
  422. */
  423. void arm_negate_q7(
  424. const q7_t * pSrc,
  425. q7_t * pDst,
  426. uint32_t blockSize);
  427. /**
  428. * @brief Negates the elements of a Q15 vector.
  429. * @param[in] pSrc points to the input vector
  430. * @param[out] pDst points to the output vector
  431. * @param[in] blockSize number of samples in the vector
  432. */
  433. void arm_negate_q15(
  434. const q15_t * pSrc,
  435. q15_t * pDst,
  436. uint32_t blockSize);
  437. /**
  438. * @brief Negates the elements of a Q31 vector.
  439. * @param[in] pSrc points to the input vector
  440. * @param[out] pDst points to the output vector
  441. * @param[in] blockSize number of samples in the vector
  442. */
  443. void arm_negate_q31(
  444. const q31_t * pSrc,
  445. q31_t * pDst,
  446. uint32_t blockSize);
  447. /**
  448. * @brief Compute the logical bitwise AND of two fixed-point vectors.
  449. * @param[in] pSrcA points to input vector A
  450. * @param[in] pSrcB points to input vector B
  451. * @param[out] pDst points to output vector
  452. * @param[in] blockSize number of samples in each vector
  453. * @return none
  454. */
  455. void arm_and_u16(
  456. const uint16_t * pSrcA,
  457. const uint16_t * pSrcB,
  458. uint16_t * pDst,
  459. uint32_t blockSize);
  460. /**
  461. * @brief Compute the logical bitwise AND of two fixed-point vectors.
  462. * @param[in] pSrcA points to input vector A
  463. * @param[in] pSrcB points to input vector B
  464. * @param[out] pDst points to output vector
  465. * @param[in] blockSize number of samples in each vector
  466. * @return none
  467. */
  468. void arm_and_u32(
  469. const uint32_t * pSrcA,
  470. const uint32_t * pSrcB,
  471. uint32_t * pDst,
  472. uint32_t blockSize);
  473. /**
  474. * @brief Compute the logical bitwise AND of two fixed-point vectors.
  475. * @param[in] pSrcA points to input vector A
  476. * @param[in] pSrcB points to input vector B
  477. * @param[out] pDst points to output vector
  478. * @param[in] blockSize number of samples in each vector
  479. * @return none
  480. */
  481. void arm_and_u8(
  482. const uint8_t * pSrcA,
  483. const uint8_t * pSrcB,
  484. uint8_t * pDst,
  485. uint32_t blockSize);
  486. /**
  487. * @brief Compute the logical bitwise OR of two fixed-point vectors.
  488. * @param[in] pSrcA points to input vector A
  489. * @param[in] pSrcB points to input vector B
  490. * @param[out] pDst points to output vector
  491. * @param[in] blockSize number of samples in each vector
  492. * @return none
  493. */
  494. void arm_or_u16(
  495. const uint16_t * pSrcA,
  496. const uint16_t * pSrcB,
  497. uint16_t * pDst,
  498. uint32_t blockSize);
  499. /**
  500. * @brief Compute the logical bitwise OR of two fixed-point vectors.
  501. * @param[in] pSrcA points to input vector A
  502. * @param[in] pSrcB points to input vector B
  503. * @param[out] pDst points to output vector
  504. * @param[in] blockSize number of samples in each vector
  505. * @return none
  506. */
  507. void arm_or_u32(
  508. const uint32_t * pSrcA,
  509. const uint32_t * pSrcB,
  510. uint32_t * pDst,
  511. uint32_t blockSize);
  512. /**
  513. * @brief Compute the logical bitwise OR of two fixed-point vectors.
  514. * @param[in] pSrcA points to input vector A
  515. * @param[in] pSrcB points to input vector B
  516. * @param[out] pDst points to output vector
  517. * @param[in] blockSize number of samples in each vector
  518. * @return none
  519. */
  520. void arm_or_u8(
  521. const uint8_t * pSrcA,
  522. const uint8_t * pSrcB,
  523. uint8_t * pDst,
  524. uint32_t blockSize);
  525. /**
  526. * @brief Compute the logical bitwise NOT of a fixed-point vector.
  527. * @param[in] pSrc points to input vector
  528. * @param[out] pDst points to output vector
  529. * @param[in] blockSize number of samples in each vector
  530. * @return none
  531. */
  532. void arm_not_u16(
  533. const uint16_t * pSrc,
  534. uint16_t * pDst,
  535. uint32_t blockSize);
  536. /**
  537. * @brief Compute the logical bitwise NOT of a fixed-point vector.
  538. * @param[in] pSrc points to input vector
  539. * @param[out] pDst points to output vector
  540. * @param[in] blockSize number of samples in each vector
  541. * @return none
  542. */
  543. void arm_not_u32(
  544. const uint32_t * pSrc,
  545. uint32_t * pDst,
  546. uint32_t blockSize);
  547. /**
  548. * @brief Compute the logical bitwise NOT of a fixed-point vector.
  549. * @param[in] pSrc points to input vector
  550. * @param[out] pDst points to output vector
  551. * @param[in] blockSize number of samples in each vector
  552. * @return none
  553. */
  554. void arm_not_u8(
  555. const uint8_t * pSrc,
  556. uint8_t * pDst,
  557. uint32_t blockSize);
  558. /**
  559. * @brief Compute the logical bitwise XOR of two fixed-point vectors.
  560. * @param[in] pSrcA points to input vector A
  561. * @param[in] pSrcB points to input vector B
  562. * @param[out] pDst points to output vector
  563. * @param[in] blockSize number of samples in each vector
  564. * @return none
  565. */
  566. void arm_xor_u16(
  567. const uint16_t * pSrcA,
  568. const uint16_t * pSrcB,
  569. uint16_t * pDst,
  570. uint32_t blockSize);
  571. /**
  572. * @brief Compute the logical bitwise XOR of two fixed-point vectors.
  573. * @param[in] pSrcA points to input vector A
  574. * @param[in] pSrcB points to input vector B
  575. * @param[out] pDst points to output vector
  576. * @param[in] blockSize number of samples in each vector
  577. * @return none
  578. */
  579. void arm_xor_u32(
  580. const uint32_t * pSrcA,
  581. const uint32_t * pSrcB,
  582. uint32_t * pDst,
  583. uint32_t blockSize);
  584. /**
  585. * @brief Compute the logical bitwise XOR of two fixed-point vectors.
  586. * @param[in] pSrcA points to input vector A
  587. * @param[in] pSrcB points to input vector B
  588. * @param[out] pDst points to output vector
  589. * @param[in] blockSize number of samples in each vector
  590. * @return none
  591. */
  592. void arm_xor_u8(
  593. const uint8_t * pSrcA,
  594. const uint8_t * pSrcB,
  595. uint8_t * pDst,
  596. uint32_t blockSize);
  597. #ifdef __cplusplus
  598. }
  599. #endif
  600. #endif /* ifndef _BASIC_MATH_FUNCTIONS_H_ */