arm_xor_u16.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_xor_u16.c
  4. * Description: uint16_t bitwise exclusive OR
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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 "dsp/basic_math_functions.h"
  29. /**
  30. @ingroup groupMath
  31. */
  32. /**
  33. @defgroup Xor Vector bitwise exclusive OR
  34. Compute the logical bitwise XOR.
  35. There are separate functions for uint32_t, uint16_t, and uint8_t data types.
  36. */
  37. /**
  38. @addtogroup Xor
  39. @{
  40. */
  41. /**
  42. @brief Compute the logical bitwise XOR 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. */
  48. void arm_xor_u16(
  49. const uint16_t * pSrcA,
  50. const uint16_t * pSrcB,
  51. uint16_t * pDst,
  52. uint32_t blockSize)
  53. {
  54. uint32_t blkCnt; /* Loop counter */
  55. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  56. uint16x8_t vecSrcA, vecSrcB;
  57. /* Compute 8 outputs at a time */
  58. blkCnt = blockSize >> 3;
  59. while (blkCnt > 0U)
  60. {
  61. vecSrcA = vld1q(pSrcA);
  62. vecSrcB = vld1q(pSrcB);
  63. vst1q(pDst, veorq_u16(vecSrcA, vecSrcB) );
  64. pSrcA += 8;
  65. pSrcB += 8;
  66. pDst += 8;
  67. /* Decrement the loop counter */
  68. blkCnt--;
  69. }
  70. /* Tail */
  71. blkCnt = blockSize & 7;
  72. if (blkCnt > 0U)
  73. {
  74. mve_pred16_t p0 = vctp16q(blkCnt);
  75. vecSrcA = vld1q(pSrcA);
  76. vecSrcB = vld1q(pSrcB);
  77. vstrhq_p(pDst, veorq_u16(vecSrcA, vecSrcB), p0);
  78. }
  79. #else
  80. #if defined(ARM_MATH_NEON) && !defined(ARM_MATH_AUTOVECTORIZE)
  81. uint16x8_t vecA, vecB;
  82. /* Compute 8 outputs at a time */
  83. blkCnt = blockSize >> 3U;
  84. while (blkCnt > 0U)
  85. {
  86. vecA = vld1q_u16(pSrcA);
  87. vecB = vld1q_u16(pSrcB);
  88. vst1q_u16(pDst, veorq_u16(vecA, vecB) );
  89. pSrcA += 8;
  90. pSrcB += 8;
  91. pDst += 8;
  92. /* Decrement the loop counter */
  93. blkCnt--;
  94. }
  95. /* Tail */
  96. blkCnt = blockSize & 7;
  97. #else
  98. /* Initialize blkCnt with number of samples */
  99. blkCnt = blockSize;
  100. #endif
  101. while (blkCnt > 0U)
  102. {
  103. *pDst++ = (*pSrcA++)^(*pSrcB++);
  104. /* Decrement the loop counter */
  105. blkCnt--;
  106. }
  107. #endif /* if defined(ARM_MATH_MVEI) */
  108. }
  109. /**
  110. @} end of Xor group
  111. */