arm_nn_add_q7.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2010-2018 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_add_q7.c
  21. * Description: Non saturating addition of elements of a q7 vector.
  22. *
  23. * $Date: July 2019
  24. * $Revision: V.1.0.0
  25. *
  26. * Target Processor: Cortex-M cores
  27. *
  28. * -------------------------------------------------------------------- */
  29. #include "arm_math.h"
  30. #include "arm_nnfunctions.h"
  31. /**
  32. * @ingroup groupSupport
  33. */
  34. /**
  35. * @addtogroup NNBasicMath
  36. * @{
  37. */
  38. void arm_nn_add_q7(const q7_t *input, q31_t *output, uint32_t block_size)
  39. {
  40. uint32_t block_count;
  41. q31_t result = 0;
  42. #if defined(ARM_MATH_DSP)
  43. /* Loop unrolling: Compute 4 outputs at a time */
  44. block_count = block_size >> 2U;
  45. while (block_count > 0U)
  46. {
  47. const int32_t mult_q15x2 = (1UL << 16) | 1UL;
  48. q31_t in_q7x4 = arm_nn_read_q7x4_ia(&input);
  49. q31_t temp_q15x2 = __SXTAB16(__SXTB16(in_q7x4), __ROR(in_q7x4, 8));
  50. result = __SMLAD(temp_q15x2, mult_q15x2, result);
  51. /* Decrement loop counter */
  52. block_count--;
  53. }
  54. /* Loop unrolling: Compute remaining outputs */
  55. block_count = block_size & 0x3;
  56. #else
  57. block_count = block_size;
  58. #endif
  59. while (block_count > 0U)
  60. {
  61. /* Add and store result in destination buffer. */
  62. result += *input++;
  63. /* Decrement loop counter */
  64. block_count--;
  65. }
  66. *output = result;
  67. }
  68. /**
  69. * @} end of NNBasicMath group
  70. */