arm_xor_u8.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_xor_u8.c
  4. * Description: uint8_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. @addtogroup Xor
  34. @{
  35. */
  36. /**
  37. @brief Compute the logical bitwise XOR of two fixed-point vectors.
  38. @param[in] pSrcA points to input vector A
  39. @param[in] pSrcB points to input vector B
  40. @param[out] pDst points to output vector
  41. @param[in] blockSize number of samples in each vector
  42. */
  43. void arm_xor_u8(
  44. const uint8_t * pSrcA,
  45. const uint8_t * pSrcB,
  46. uint8_t * pDst,
  47. uint32_t blockSize)
  48. {
  49. uint32_t blkCnt; /* Loop counter */
  50. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  51. uint8x16_t vecSrcA, vecSrcB;
  52. /* Compute 16 outputs at a time */
  53. blkCnt = blockSize >> 4;
  54. while (blkCnt > 0U)
  55. {
  56. vecSrcA = vld1q(pSrcA);
  57. vecSrcB = vld1q(pSrcB);
  58. vst1q(pDst, veorq_u8(vecSrcA, vecSrcB) );
  59. pSrcA += 16;
  60. pSrcB += 16;
  61. pDst += 16;
  62. /* Decrement the loop counter */
  63. blkCnt--;
  64. }
  65. /* Tail */
  66. blkCnt = blockSize & 0xF;
  67. if (blkCnt > 0U)
  68. {
  69. mve_pred16_t p0 = vctp8q(blkCnt);
  70. vecSrcA = vld1q(pSrcA);
  71. vecSrcB = vld1q(pSrcB);
  72. vstrbq_p(pDst, veorq_u8(vecSrcA, vecSrcB), p0);
  73. }
  74. #else
  75. #if defined(ARM_MATH_NEON) && !defined(ARM_MATH_AUTOVECTORIZE)
  76. uint8x16_t vecA, vecB;
  77. /* Compute 16 outputs at a time */
  78. blkCnt = blockSize >> 4U;
  79. while (blkCnt > 0U)
  80. {
  81. vecA = vld1q_u8(pSrcA);
  82. vecB = vld1q_u8(pSrcB);
  83. vst1q_u8(pDst, veorq_u8(vecA, vecB) );
  84. pSrcA += 16;
  85. pSrcB += 16;
  86. pDst += 16;
  87. /* Decrement the loop counter */
  88. blkCnt--;
  89. }
  90. /* Tail */
  91. blkCnt = blockSize & 0xF;
  92. #else
  93. /* Initialize blkCnt with number of samples */
  94. blkCnt = blockSize;
  95. #endif
  96. while (blkCnt > 0U)
  97. {
  98. *pDst++ = (*pSrcA++)^(*pSrcB++);
  99. /* Decrement the loop counter */
  100. blkCnt--;
  101. }
  102. #endif /* if defined(ARM_MATH_MVEI) */
  103. }
  104. /**
  105. @} end of Xor group
  106. */