arm_elementwise_mul_s16_s8.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
  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_s8.c
  21. * Description: Elementwise multiplication of 16 bit input with 8 bit output
  22. *
  23. * $Date: 8 September 2022
  24. * $Revision: V.1.0.0
  25. *
  26. * Target Processor: Cortex-M cores
  27. *
  28. * -------------------------------------------------------------------- */
  29. #include "arm_nnsupportfunctions.h"
  30. /**
  31. * @ingroup groupSupport
  32. */
  33. /**
  34. * @addtogroup BasicMath
  35. * @{
  36. */
  37. /*
  38. * s16 elementwise multiplication with s8 output
  39. *
  40. * Refer header file for details.
  41. *
  42. */
  43. arm_cmsis_nn_status arm_elementwise_mul_s16_s8(const int16_t *input_1_vect,
  44. const int16_t *input_2_vect,
  45. int8_t *output,
  46. const int32_t out_offset,
  47. const int32_t out_mult,
  48. const int32_t out_shift,
  49. const int32_t block_size)
  50. {
  51. int32_t loop_count = block_size;
  52. while (loop_count > 0)
  53. {
  54. int16_t input_1 = *input_1_vect++;
  55. int16_t input_2 = *input_2_vect++;
  56. int32_t mul_res = input_1 * input_2;
  57. mul_res = arm_nn_requantize(mul_res, out_mult, out_shift) + out_offset;
  58. mul_res = CLAMP(mul_res, NN_Q7_MAX, NN_Q7_MIN);
  59. *output++ = (int8_t)mul_res;
  60. loop_count--;
  61. }
  62. return ARM_CMSIS_NN_SUCCESS;
  63. }
  64. /**
  65. * @} end of BasicMath group
  66. */