arm_and_u16.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_and_u16.c
  4. * Description: uint16_t bitwise AND
  5. *
  6. * $Date: 14 November 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "arm_math.h"
  29. /**
  30. @ingroup groupMath
  31. */
  32. /**
  33. @defgroup And Vector bitwise AND
  34. Compute the logical bitwise AND.
  35. There are separate functions for uint32_t, uint16_t, and uint7_t data types.
  36. */
  37. /**
  38. @addtogroup And
  39. @{
  40. */
  41. /**
  42. @brief Compute the logical bitwise AND of two fixed-point vectors.
  43. @param[in] pSrcA points to input vector A
  44. @param[in] pSrcB points to input vector B
  45. @param[out] pDst points to output vector
  46. @param[in] blockSize number of samples in each vector
  47. @return none
  48. */
  49. void arm_and_u16(
  50. const uint16_t * pSrcA,
  51. const uint16_t * pSrcB,
  52. uint16_t * pDst,
  53. uint32_t blockSize)
  54. {
  55. uint32_t blkCnt; /* Loop counter */
  56. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  57. q15x8_t vecSrcA, vecSrcB;
  58. /* Compute 8 outputs at a time */
  59. blkCnt = blockSize >> 3;
  60. while (blkCnt > 0U)
  61. {
  62. vecSrcA = vld1q(pSrcA);
  63. vecSrcB = vld1q(pSrcB);
  64. vst1q(pDst, vandq_u16(vecSrcA, vecSrcB) );
  65. pSrcA += 8;
  66. pSrcB += 8;
  67. pDst += 8;
  68. /* Decrement the loop counter */
  69. blkCnt--;
  70. }
  71. /* Tail */
  72. blkCnt = blockSize & 7;
  73. if (blkCnt > 0U)
  74. {
  75. mve_pred16_t p0 = vctp16q(blkCnt);
  76. vecSrcA = vld1q(pSrcA);
  77. vecSrcB = vld1q(pSrcB);
  78. vstrhq_p(pDst, vandq_u16(vecSrcA, vecSrcB), p0);
  79. }
  80. #else
  81. #if defined(ARM_MATH_NEON) && !defined(ARM_MATH_AUTOVECTORIZE)
  82. uint16x8_t vecA, vecB;
  83. /* Compute 8 outputs at a time */
  84. blkCnt = blockSize >> 3U;
  85. while (blkCnt > 0U)
  86. {
  87. vecA = vld1q_u16(pSrcA);
  88. vecB = vld1q_u16(pSrcB);
  89. vst1q_u16(pDst, vandq_u16(vecA, vecB) );
  90. pSrcA += 8;
  91. pSrcB += 8;
  92. pDst += 8;
  93. /* Decrement the loop counter */
  94. blkCnt--;
  95. }
  96. /* Tail */
  97. blkCnt = blockSize & 7;
  98. #else
  99. /* Initialize blkCnt with number of samples */
  100. blkCnt = blockSize;
  101. #endif
  102. while (blkCnt > 0U)
  103. {
  104. *pDst++ = (*pSrcA++)&(*pSrcB++);
  105. /* Decrement the loop counter */
  106. blkCnt--;
  107. }
  108. #endif /* if defined(ARM_MATH_MVEI) */
  109. }
  110. /**
  111. @} end of And group
  112. */