arm_nn_mult_q15.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2010-2021 Arm Limited or its affiliates. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /* ----------------------------------------------------------------------
  19. * Project: CMSIS NN Library
  20. * Title: arm_nn_mult_q15.c
  21. * Description: Q15 vector multiplication with variable output shifts
  22. *
  23. * $Date: 20. July 2021
  24. * $Revision: V.1.1.2
  25. *
  26. * Target Processor: Cortex-M cores
  27. *
  28. * -------------------------------------------------------------------- */
  29. #include "arm_nnsupportfunctions.h"
  30. /**
  31. * @ingroup groupSupport
  32. */
  33. /**
  34. * @addtogroup NNBasicMath
  35. * @{
  36. */
  37. /**
  38. * @brief Q7 vector multiplication with variable output shifts
  39. * @param[in] *pSrcA pointer to the first input vector
  40. * @param[in] *pSrcB pointer to the second input vector
  41. * @param[out] *pDst pointer to the output vector
  42. * @param[in] out_shift amount of right-shift for output
  43. * @param[in] blockSize number of samples in each vector
  44. *
  45. * <b>Scaling and Overflow Behavior:</b>
  46. * \par
  47. * The function uses saturating arithmetic.
  48. * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated.
  49. */
  50. void arm_nn_mult_q15(q15_t *pSrcA, q15_t *pSrcB, q15_t *pDst, const uint16_t out_shift, uint32_t blockSize)
  51. {
  52. uint32_t blkCnt = blockSize; /* loop counters */
  53. while (blkCnt > 0U)
  54. {
  55. /* C = A * B */
  56. /* Multiply the inputs and store the result in the destination buffer */
  57. *pDst++ = (q15_t)__SSAT(((q31_t)((q31_t)(*pSrcA++) * (*pSrcB++) + NN_ROUND(out_shift)) >> out_shift), 16);
  58. /* Decrement the blockSize loop counter */
  59. blkCnt--;
  60. }
  61. }
  62. /**
  63. * @} end of NNBasicMath group
  64. */