arm_elementwise_mul_s16.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2022 Arm Limited or its affiliates.
  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_elementwise_mul_s16
  21. * Description: Element wise multiplication
  22. *
  23. * $Date: 14 Februari 2022
  24. * $Revision: V.1.0.0
  25. *
  26. * Target Processor: Cortex-M cores
  27. *
  28. * -------------------------------------------------------------------- */
  29. #include "arm_nnfunctions.h"
  30. #include "arm_nnsupportfunctions.h"
  31. /**
  32. * @ingroup groupNN
  33. */
  34. /**
  35. * @addtogroup BasicMath
  36. * @{
  37. */
  38. /**
  39. * @brief s16 element wise multiplication of two vectors
  40. *
  41. * @note Refer header file for details.
  42. *
  43. */
  44. arm_status arm_elementwise_mul_s16(const int16_t *input_1_vect,
  45. const int16_t *input_2_vect,
  46. const int32_t input_1_offset,
  47. const int32_t input_2_offset,
  48. int16_t *output,
  49. const int32_t out_offset,
  50. const int32_t out_mult,
  51. const int32_t out_shift,
  52. const int32_t out_activation_min,
  53. const int32_t out_activation_max,
  54. const int32_t block_size)
  55. {
  56. (void)input_1_offset;
  57. (void)input_2_offset;
  58. (void)out_offset;
  59. int32_t loop_count;
  60. int32_t input_1;
  61. int32_t input_2;
  62. int32_t mul_res;
  63. loop_count = block_size;
  64. while (loop_count > 0)
  65. {
  66. /* C = A * B */
  67. input_1 = *input_1_vect++;
  68. input_2 = *input_2_vect++;
  69. mul_res = input_1 * input_2;
  70. mul_res = arm_nn_requantize(mul_res, out_mult, out_shift);
  71. mul_res = MAX(mul_res, out_activation_min);
  72. mul_res = MIN(mul_res, out_activation_max);
  73. *output++ = (int16_t)mul_res;
  74. /* Decrement loop counter */
  75. loop_count--;
  76. }
  77. return ARM_MATH_SUCCESS;
  78. }
  79. /**
  80. * @} end of BasicMath group
  81. */