52#ifndef INCLUDED_volk_32f_index_max_32u_a_H
53#define INCLUDED_volk_32f_index_max_32u_a_H
63volk_32f_index_max_32u_a_sse4_1(uint32_t* target,
const float* src0, uint32_t num_points)
67 const uint32_t quarterPoints = num_points / 4;
69 float* inputPtr = (
float*)src0;
71 __m128 indexIncrementValues = _mm_set1_ps(4);
72 __m128 currentIndexes = _mm_set_ps(-1, -2, -3, -4);
76 __m128 maxValues = _mm_set1_ps(max);
77 __m128 maxValuesIndex = _mm_setzero_ps();
78 __m128 compareResults;
84 for (; number < quarterPoints; number++) {
86 currentValues = _mm_load_ps(inputPtr);
88 currentIndexes = _mm_add_ps(currentIndexes, indexIncrementValues);
90 compareResults = _mm_cmpgt_ps(currentValues, maxValues);
93 _mm_blendv_ps(maxValuesIndex, currentIndexes, compareResults);
94 maxValues = _mm_blendv_ps(maxValues, currentValues, compareResults);
98 _mm_store_ps(maxValuesBuffer, maxValues);
99 _mm_store_ps(maxIndexesBuffer, maxValuesIndex);
101 for (number = 0; number < 4; number++) {
102 if (maxValuesBuffer[number] > max) {
103 index = maxIndexesBuffer[number];
104 max = maxValuesBuffer[number];
105 }
else if (maxValuesBuffer[number] == max) {
106 if (index > maxIndexesBuffer[number])
107 index = maxIndexesBuffer[number];
111 number = quarterPoints * 4;
112 for (; number < num_points; number++) {
113 if (src0[number] > max) {
118 target[0] = (uint32_t)index;
127#include <xmmintrin.h>
132 if (num_points > 0) {
134 const uint32_t quarterPoints = num_points / 4;
136 float* inputPtr = (
float*)src0;
138 __m128 indexIncrementValues = _mm_set1_ps(4);
139 __m128 currentIndexes = _mm_set_ps(-1, -2, -3, -4);
143 __m128 maxValues = _mm_set1_ps(max);
144 __m128 maxValuesIndex = _mm_setzero_ps();
145 __m128 compareResults;
146 __m128 currentValues;
151 for (; number < quarterPoints; number++) {
153 currentValues = _mm_load_ps(inputPtr);
155 currentIndexes = _mm_add_ps(currentIndexes, indexIncrementValues);
157 compareResults = _mm_cmpgt_ps(currentValues, maxValues);
159 maxValuesIndex = _mm_or_ps(_mm_and_ps(compareResults, currentIndexes),
160 _mm_andnot_ps(compareResults, maxValuesIndex));
162 maxValues = _mm_or_ps(_mm_and_ps(compareResults, currentValues),
163 _mm_andnot_ps(compareResults, maxValues));
167 _mm_store_ps(maxValuesBuffer, maxValues);
168 _mm_store_ps(maxIndexesBuffer, maxValuesIndex);
170 for (number = 0; number < 4; number++) {
171 if (maxValuesBuffer[number] > max) {
172 index = maxIndexesBuffer[number];
173 max = maxValuesBuffer[number];
174 }
else if (maxValuesBuffer[number] == max) {
175 if (index > maxIndexesBuffer[number])
176 index = maxIndexesBuffer[number];
180 number = quarterPoints * 4;
181 for (; number < num_points; number++) {
182 if (src0[number] > max) {
187 target[0] = (uint32_t)index;
195#include <immintrin.h>
200 if (num_points > 0) {
202 const uint32_t quarterPoints = num_points / 8;
204 float* inputPtr = (
float*)src0;
206 __m256 indexIncrementValues = _mm256_set1_ps(8);
207 __m256 currentIndexes = _mm256_set_ps(-1, -2, -3, -4, -5, -6, -7, -8);
211 __m256 maxValues = _mm256_set1_ps(max);
212 __m256 maxValuesIndex = _mm256_setzero_ps();
213 __m256 compareResults;
214 __m256 currentValues;
219 for (; number < quarterPoints; number++) {
220 currentValues = _mm256_load_ps(inputPtr);
222 currentIndexes = _mm256_add_ps(currentIndexes, indexIncrementValues);
223 compareResults = _mm256_cmp_ps(currentValues, maxValues, _CMP_GT_OS);
225 _mm256_blendv_ps(maxValuesIndex, currentIndexes, compareResults);
226 maxValues = _mm256_blendv_ps(maxValues, currentValues, compareResults);
230 _mm256_store_ps(maxValuesBuffer, maxValues);
231 _mm256_store_ps(maxIndexesBuffer, maxValuesIndex);
233 for (number = 0; number < 8; number++) {
234 if (maxValuesBuffer[number] > max) {
235 index = maxIndexesBuffer[number];
236 max = maxValuesBuffer[number];
237 }
else if (maxValuesBuffer[number] == max) {
238 if (index > maxIndexesBuffer[number])
239 index = maxIndexesBuffer[number];
243 number = quarterPoints * 8;
244 for (; number < num_points; number++) {
245 if (src0[number] > max) {
250 target[0] = (uint32_t)index;
263 if (num_points > 0) {
265 const uint32_t quarterPoints = num_points / 4;
267 float* inputPtr = (
float*)src0;
268 float32x4_t indexIncrementValues = vdupq_n_f32(4);
270 float currentIndexes_float[4] = { -4.0f, -3.0f, -2.0f, -1.0f };
271 float32x4_t currentIndexes = vld1q_f32(currentIndexes_float);
275 float32x4_t maxValues = vdupq_n_f32(max);
276 uint32x4_t maxValuesIndex = vmovq_n_u32(0);
277 uint32x4_t compareResults;
278 uint32x4_t currentIndexes_u;
279 float32x4_t currentValues;
284 for (; number < quarterPoints; number++) {
285 currentValues = vld1q_f32(inputPtr);
287 currentIndexes = vaddq_f32(currentIndexes, indexIncrementValues);
288 currentIndexes_u = vcvtq_u32_f32(currentIndexes);
289 compareResults = vcleq_f32(currentValues, maxValues);
290 maxValuesIndex = vorrq_u32(vandq_u32(compareResults, maxValuesIndex),
291 vbicq_u32(currentIndexes_u, compareResults));
292 maxValues = vmaxq_f32(currentValues, maxValues);
296 vst1q_f32(maxValuesBuffer, maxValues);
297 vst1q_f32(maxIndexesBuffer, vcvtq_f32_u32(maxValuesIndex));
298 for (number = 0; number < 4; number++) {
299 if (maxValuesBuffer[number] > max) {
300 index = maxIndexesBuffer[number];
301 max = maxValuesBuffer[number];
302 }
else if (maxValuesBuffer[number] == max) {
303 if (index > maxIndexesBuffer[number])
304 index = maxIndexesBuffer[number];
308 number = quarterPoints * 4;
309 for (; number < num_points; number++) {
310 if (src0[number] > max) {
315 target[0] = (uint32_t)index;
327volk_32f_index_max_32u_neonv8(uint32_t* target,
const float* src0, uint32_t num_points)
332 const uint32_t quarter_points = num_points / 4;
333 const float* inputPtr = src0;
336 uint32x4_t vec_indices = { 0, 1, 2, 3 };
337 const uint32x4_t vec_incr = vdupq_n_u32(4);
339 float32x4_t vec_max = vdupq_n_f32(-FLT_MAX);
340 uint32x4_t vec_max_idx = vdupq_n_u32(0);
342 for (uint32_t i = 0; i < quarter_points; i++) {
343 float32x4_t vec_val = vld1q_f32(inputPtr);
347 uint32x4_t gt_mask = vcgtq_f32(vec_val, vec_max);
348 vec_max_idx = vbslq_u32(gt_mask, vec_indices, vec_max_idx);
351 vec_max = vmaxq_f32(vec_val, vec_max);
353 vec_indices = vaddq_u32(vec_indices, vec_incr);
357 float max_val = vmaxvq_f32(vec_max);
360 uint32x4_t max_mask = vceqq_f32(vec_max, vdupq_n_f32(max_val));
361 uint32x4_t idx_masked = vbslq_u32(max_mask, vec_max_idx, vdupq_n_u32(UINT32_MAX));
362 uint32_t result_idx = vminvq_u32(idx_masked);
365 for (uint32_t i = quarter_points * 4; i < num_points; i++) {
366 if (src0[i] > max_val) {
372 *target = result_idx;
378#ifdef LV_HAVE_GENERIC
383 if (num_points > 0) {
389 for (; i < num_points; ++i) {
401#ifdef LV_HAVE_AVX512F
402#include <immintrin.h>
405volk_32f_index_max_32u_a_avx512f(uint32_t* target,
const float* src0, uint32_t num_points)
407 if (num_points > 0) {
409 const uint32_t sixteenthPoints = num_points / 16;
411 const float* inputPtr = src0;
413 __m512 indexIncrementValues = _mm512_set1_ps(16);
414 __m512 currentIndexes = _mm512_set_ps(
415 -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16);
419 __m512 maxValues = _mm512_set1_ps(max);
420 __m512 maxValuesIndex = _mm512_setzero_ps();
421 __mmask16 compareResults;
422 __m512 currentValues;
427 for (; number < sixteenthPoints; number++) {
428 currentValues = _mm512_load_ps(inputPtr);
430 currentIndexes = _mm512_add_ps(currentIndexes, indexIncrementValues);
431 compareResults = _mm512_cmp_ps_mask(currentValues, maxValues, _CMP_GT_OS);
433 _mm512_mask_blend_ps(compareResults, maxValuesIndex, currentIndexes);
434 maxValues = _mm512_mask_blend_ps(compareResults, maxValues, currentValues);
438 _mm512_store_ps(maxValuesBuffer, maxValues);
439 _mm512_store_ps(maxIndexesBuffer, maxValuesIndex);
441 for (number = 0; number < 16; number++) {
442 if (maxValuesBuffer[number] > max) {
443 index = maxIndexesBuffer[number];
444 max = maxValuesBuffer[number];
445 }
else if (maxValuesBuffer[number] == max) {
446 if (index > maxIndexesBuffer[number])
447 index = maxIndexesBuffer[number];
451 number = sixteenthPoints * 16;
452 for (; number < num_points; number++) {
453 if (src0[number] > max) {
458 target[0] = (uint32_t)index;
467#ifndef INCLUDED_volk_32f_index_max_32u_u_H
468#define INCLUDED_volk_32f_index_max_32u_u_H
476#include <immintrin.h>
481 if (num_points > 0) {
483 const uint32_t quarterPoints = num_points / 8;
485 float* inputPtr = (
float*)src0;
487 __m256 indexIncrementValues = _mm256_set1_ps(8);
488 __m256 currentIndexes = _mm256_set_ps(-1, -2, -3, -4, -5, -6, -7, -8);
492 __m256 maxValues = _mm256_set1_ps(max);
493 __m256 maxValuesIndex = _mm256_setzero_ps();
494 __m256 compareResults;
495 __m256 currentValues;
500 for (; number < quarterPoints; number++) {
501 currentValues = _mm256_loadu_ps(inputPtr);
503 currentIndexes = _mm256_add_ps(currentIndexes, indexIncrementValues);
504 compareResults = _mm256_cmp_ps(currentValues, maxValues, _CMP_GT_OS);
506 _mm256_blendv_ps(maxValuesIndex, currentIndexes, compareResults);
507 maxValues = _mm256_blendv_ps(maxValues, currentValues, compareResults);
511 _mm256_store_ps(maxValuesBuffer, maxValues);
512 _mm256_store_ps(maxIndexesBuffer, maxValuesIndex);
514 for (number = 0; number < 8; number++) {
515 if (maxValuesBuffer[number] > max) {
516 index = maxIndexesBuffer[number];
517 max = maxValuesBuffer[number];
518 }
else if (maxValuesBuffer[number] == max) {
519 if (index > maxIndexesBuffer[number])
520 index = maxIndexesBuffer[number];
524 number = quarterPoints * 8;
525 for (; number < num_points; number++) {
526 if (src0[number] > max) {
531 target[0] = (uint32_t)index;
539#include <smmintrin.h>
542volk_32f_index_max_32u_u_sse4_1(uint32_t* target,
const float* src0, uint32_t num_points)
544 if (num_points > 0) {
546 const uint32_t quarterPoints = num_points / 4;
548 float* inputPtr = (
float*)src0;
550 __m128 indexIncrementValues = _mm_set1_ps(4);
551 __m128 currentIndexes = _mm_set_ps(-1, -2, -3, -4);
555 __m128 maxValues = _mm_set1_ps(max);
556 __m128 maxValuesIndex = _mm_setzero_ps();
557 __m128 compareResults;
558 __m128 currentValues;
563 for (; number < quarterPoints; number++) {
564 currentValues = _mm_loadu_ps(inputPtr);
566 currentIndexes = _mm_add_ps(currentIndexes, indexIncrementValues);
567 compareResults = _mm_cmpgt_ps(currentValues, maxValues);
569 _mm_blendv_ps(maxValuesIndex, currentIndexes, compareResults);
570 maxValues = _mm_blendv_ps(maxValues, currentValues, compareResults);
574 _mm_store_ps(maxValuesBuffer, maxValues);
575 _mm_store_ps(maxIndexesBuffer, maxValuesIndex);
577 for (number = 0; number < 4; number++) {
578 if (maxValuesBuffer[number] > max) {
579 index = maxIndexesBuffer[number];
580 max = maxValuesBuffer[number];
581 }
else if (maxValuesBuffer[number] == max) {
582 if (index > maxIndexesBuffer[number])
583 index = maxIndexesBuffer[number];
587 number = quarterPoints * 4;
588 for (; number < num_points; number++) {
589 if (src0[number] > max) {
594 target[0] = (uint32_t)index;
601#include <xmmintrin.h>
606 if (num_points > 0) {
608 const uint32_t quarterPoints = num_points / 4;
610 float* inputPtr = (
float*)src0;
612 __m128 indexIncrementValues = _mm_set1_ps(4);
613 __m128 currentIndexes = _mm_set_ps(-1, -2, -3, -4);
617 __m128 maxValues = _mm_set1_ps(max);
618 __m128 maxValuesIndex = _mm_setzero_ps();
619 __m128 compareResults;
620 __m128 currentValues;
625 for (; number < quarterPoints; number++) {
626 currentValues = _mm_loadu_ps(inputPtr);
628 currentIndexes = _mm_add_ps(currentIndexes, indexIncrementValues);
629 compareResults = _mm_cmpgt_ps(currentValues, maxValues);
630 maxValuesIndex = _mm_or_ps(_mm_and_ps(compareResults, currentIndexes),
631 _mm_andnot_ps(compareResults, maxValuesIndex));
632 maxValues = _mm_or_ps(_mm_and_ps(compareResults, currentValues),
633 _mm_andnot_ps(compareResults, maxValues));
637 _mm_store_ps(maxValuesBuffer, maxValues);
638 _mm_store_ps(maxIndexesBuffer, maxValuesIndex);
640 for (number = 0; number < 4; number++) {
641 if (maxValuesBuffer[number] > max) {
642 index = maxIndexesBuffer[number];
643 max = maxValuesBuffer[number];
644 }
else if (maxValuesBuffer[number] == max) {
645 if (index > maxIndexesBuffer[number])
646 index = maxIndexesBuffer[number];
650 number = quarterPoints * 4;
651 for (; number < num_points; number++) {
652 if (src0[number] > max) {
657 target[0] = (uint32_t)index;
663#ifdef LV_HAVE_AVX512F
664#include <immintrin.h>
667volk_32f_index_max_32u_u_avx512f(uint32_t* target,
const float* src0, uint32_t num_points)
669 if (num_points > 0) {
671 const uint32_t sixteenthPoints = num_points / 16;
673 const float* inputPtr = src0;
675 __m512 indexIncrementValues = _mm512_set1_ps(16);
676 __m512 currentIndexes = _mm512_set_ps(
677 -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16);
681 __m512 maxValues = _mm512_set1_ps(max);
682 __m512 maxValuesIndex = _mm512_setzero_ps();
683 __mmask16 compareResults;
684 __m512 currentValues;
689 for (; number < sixteenthPoints; number++) {
690 currentValues = _mm512_loadu_ps(inputPtr);
692 currentIndexes = _mm512_add_ps(currentIndexes, indexIncrementValues);
693 compareResults = _mm512_cmp_ps_mask(currentValues, maxValues, _CMP_GT_OS);
695 _mm512_mask_blend_ps(compareResults, maxValuesIndex, currentIndexes);
696 maxValues = _mm512_mask_blend_ps(compareResults, maxValues, currentValues);
700 _mm512_store_ps(maxValuesBuffer, maxValues);
701 _mm512_store_ps(maxIndexesBuffer, maxValuesIndex);
703 for (number = 0; number < 16; number++) {
704 if (maxValuesBuffer[number] > max) {
705 index = maxIndexesBuffer[number];
706 max = maxValuesBuffer[number];
707 }
else if (maxValuesBuffer[number] == max) {
708 if (index > maxIndexesBuffer[number])
709 index = maxIndexesBuffer[number];
713 number = sixteenthPoints * 16;
714 for (; number < num_points; number++) {
715 if (src0[number] > max) {
720 target[0] = (uint32_t)index;
728#include <riscv_vector.h>
731volk_32f_index_max_32u_rvv(uint32_t* target,
const float* src0, uint32_t num_points)
733 vfloat32m4_t vmax = __riscv_vfmv_v_f_f32m4(-FLT_MAX, __riscv_vsetvlmax_e32m4());
734 vuint32m4_t vmaxi = __riscv_vmv_v_x_u32m4(0, __riscv_vsetvlmax_e32m4());
735 vuint32m4_t vidx = __riscv_vid_v_u32m4(__riscv_vsetvlmax_e32m4());
736 size_t n = num_points;
737 for (
size_t vl; n > 0; n -= vl, src0 += vl) {
738 vl = __riscv_vsetvl_e32m4(n);
739 vfloat32m4_t v = __riscv_vle32_v_f32m4(src0, vl);
740 vbool8_t m = __riscv_vmfgt(v, vmax, vl);
741 vmax = __riscv_vfmax_tu(vmax, vmax, v, vl);
742 vmaxi = __riscv_vmerge_tu(vmaxi, vmaxi, vidx, m, vl);
743 vidx = __riscv_vadd(vidx, vl, __riscv_vsetvlmax_e32m4());
745 size_t vl = __riscv_vsetvlmax_e32m4();
746 float max = __riscv_vfmv_f(__riscv_vfredmax(
RISCV_SHRINK4(vfmax, f, 32, vmax),
747 __riscv_vfmv_v_f_f32m1(-FLT_MAX, 1),
748 __riscv_vsetvlmax_e32m1()));
750 vbool8_t m = __riscv_vmfeq(vmax, max, vl);
751 vuint32m4_t idx_masked =
752 __riscv_vmerge(__riscv_vmv_v_x_u32m4(UINT32_MAX, vl), vmaxi, m, vl);
754 *target = __riscv_vmv_x(__riscv_vredminu(
RISCV_SHRINK4(vminu, u, 32, idx_masked),
755 __riscv_vmv_v_x_u32m1(UINT32_MAX, 1),
756 __riscv_vsetvlmax_e32m1()));