arm_sorting.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /******************************************************************************
  2. * @file arm_sorting.h
  3. * @brief Private header file for CMSIS DSP Library
  4. * @version V1.7.0
  5. * @date 2019
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2010-2019 Arm Limited or its affiliates. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #ifndef _ARM_SORTING_H_
  25. #define _ARM_SORTING_H_
  26. #include "arm_math.h"
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. * @param[in] S points to an instance of the sorting structure.
  33. * @param[in] pSrc points to the block of input data.
  34. * @param[out] pDst points to the block of output data.
  35. * @param[in] blockSize number of samples to process.
  36. */
  37. void arm_bubble_sort_f32(
  38. const arm_sort_instance_f32 * S,
  39. float32_t * pSrc,
  40. float32_t * pDst,
  41. uint32_t blockSize);
  42. /**
  43. * @param[in] S points to an instance of the sorting structure.
  44. * @param[in] pSrc points to the block of input data.
  45. * @param[out] pDst points to the block of output data.
  46. * @param[in] blockSize number of samples to process.
  47. */
  48. void arm_heap_sort_f32(
  49. const arm_sort_instance_f32 * S,
  50. float32_t * pSrc,
  51. float32_t * pDst,
  52. uint32_t blockSize);
  53. /**
  54. * @param[in] S points to an instance of the sorting structure.
  55. * @param[in] pSrc points to the block of input data.
  56. * @param[out] pDst points to the block of output data.
  57. * @param[in] blockSize number of samples to process.
  58. */
  59. void arm_insertion_sort_f32(
  60. const arm_sort_instance_f32 * S,
  61. float32_t *pSrc,
  62. float32_t* pDst,
  63. uint32_t blockSize);
  64. /**
  65. * @param[in] S points to an instance of the sorting structure.
  66. * @param[in] pSrc points to the block of input data.
  67. * @param[out] pDst points to the block of output data
  68. * @param[in] blockSize number of samples to process.
  69. */
  70. void arm_quick_sort_f32(
  71. const arm_sort_instance_f32 * S,
  72. float32_t * pSrc,
  73. float32_t * pDst,
  74. uint32_t blockSize);
  75. /**
  76. * @param[in] S points to an instance of the sorting structure.
  77. * @param[in] pSrc points to the block of input data.
  78. * @param[out] pDst points to the block of output data
  79. * @param[in] blockSize number of samples to process.
  80. */
  81. void arm_selection_sort_f32(
  82. const arm_sort_instance_f32 * S,
  83. float32_t * pSrc,
  84. float32_t * pDst,
  85. uint32_t blockSize);
  86. /**
  87. * @param[in] S points to an instance of the sorting structure.
  88. * @param[in] pSrc points to the block of input data.
  89. * @param[out] pDst points to the block of output data
  90. * @param[in] blockSize number of samples to process.
  91. */
  92. void arm_bitonic_sort_f32(
  93. const arm_sort_instance_f32 * S,
  94. float32_t * pSrc,
  95. float32_t * pDst,
  96. uint32_t blockSize);
  97. #if defined(ARM_MATH_NEON)
  98. #define vtrn256_128q(a, b) \
  99. do { \
  100. float32x4_t vtrn128_temp = a.val[1]; \
  101. a.val[1] = b.val[0]; \
  102. b.val[0] = vtrn128_temp ; \
  103. } while (0)
  104. #define vtrn128_64q(a, b) \
  105. do { \
  106. float32x2_t ab, cd, ef, gh; \
  107. ab = vget_low_f32(a); \
  108. ef = vget_low_f32(b); \
  109. cd = vget_high_f32(a); \
  110. gh = vget_high_f32(b); \
  111. a = vcombine_f32(ab, ef); \
  112. b = vcombine_f32(cd, gh); \
  113. } while (0)
  114. #define vtrn256_64q(a, b) \
  115. do { \
  116. float32x2_t a_0, a_1, a_2, a_3; \
  117. float32x2_t b_0, b_1, b_2, b_3; \
  118. a_0 = vget_low_f32(a.val[0]); \
  119. a_1 = vget_high_f32(a.val[0]); \
  120. a_2 = vget_low_f32(a.val[1]); \
  121. a_3 = vget_high_f32(a.val[1]); \
  122. b_0 = vget_low_f32(b.val[0]); \
  123. b_1 = vget_high_f32(b.val[0]); \
  124. b_2 = vget_low_f32(b.val[1]); \
  125. b_3 = vget_high_f32(b.val[1]); \
  126. a.val[0] = vcombine_f32(a_0, b_0); \
  127. a.val[1] = vcombine_f32(a_2, b_2); \
  128. b.val[0] = vcombine_f32(a_1, b_1); \
  129. b.val[1] = vcombine_f32(a_3, b_3); \
  130. } while (0)
  131. #define vtrn128_32q(a, b) \
  132. do { \
  133. float32x4x2_t vtrn32_tmp = vtrnq_f32((a), (b)); \
  134. (a) = vtrn32_tmp.val[0]; \
  135. (b) = vtrn32_tmp.val[1]; \
  136. } while (0)
  137. #define vtrn256_32q(a, b) \
  138. do { \
  139. float32x4x2_t vtrn32_tmp_1 = vtrnq_f32((a.val[0]), (b.val[0])); \
  140. float32x4x2_t vtrn32_tmp_2 = vtrnq_f32((a.val[1]), (b.val[1])); \
  141. a.val[0] = vtrn32_tmp_1.val[0]; \
  142. a.val[1] = vtrn32_tmp_2.val[0]; \
  143. b.val[0] = vtrn32_tmp_1.val[1]; \
  144. b.val[1] = vtrn32_tmp_2.val[1]; \
  145. } while (0)
  146. #define vminmaxq(a, b) \
  147. do { \
  148. float32x4_t minmax_tmp = (a); \
  149. (a) = vminq_f32((a), (b)); \
  150. (b) = vmaxq_f32(minmax_tmp, (b)); \
  151. } while (0)
  152. #define vminmax256q(a, b) \
  153. do { \
  154. float32x4x2_t minmax256_tmp = (a); \
  155. a.val[0] = vminq_f32(a.val[0], b.val[0]); \
  156. a.val[1] = vminq_f32(a.val[1], b.val[1]); \
  157. b.val[0] = vmaxq_f32(minmax256_tmp.val[0], b.val[0]); \
  158. b.val[1] = vmaxq_f32(minmax256_tmp.val[1], b.val[1]); \
  159. } while (0)
  160. #define vrev128q_f32(a) \
  161. vcombine_f32(vrev64_f32(vget_high_f32(a)), vrev64_f32(vget_low_f32(a)))
  162. #define vrev256q_f32(a) \
  163. do { \
  164. float32x4_t rev_tmp = vcombine_f32(vrev64_f32(vget_high_f32(a.val[0])), vrev64_f32(vget_low_f32(a.val[0]))); \
  165. a.val[0] = vcombine_f32(vrev64_f32(vget_high_f32(a.val[1])), vrev64_f32(vget_low_f32(a.val[1]))); \
  166. a.val[1] = rev_tmp; \
  167. } while (0)
  168. #define vldrev128q_f32(a, p) \
  169. do { \
  170. a = vld1q_f32(p); \
  171. a = vrev128q_f32(a); \
  172. } while (0)
  173. #endif /* ARM_MATH_NEON */
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif /* _ARM_SORTING_H */