| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2025 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: Apache-2.0 | ||
| 4 | |||
| 5 | #ifndef KLEIDICV_MEDIAN_BLUR_SORTING_NETWORK_5X5_H | ||
| 6 | #define KLEIDICV_MEDIAN_BLUR_SORTING_NETWORK_5X5_H | ||
| 7 | |||
| 8 | #include <algorithm> | ||
| 9 | |||
| 10 | #include "kleidicv/kleidicv.h" | ||
| 11 | #include "kleidicv/traits.h" | ||
| 12 | |||
| 13 | namespace KLEIDICV_TARGET_NAMESPACE { | ||
| 14 | // R. B. Kent and M. S. Pattichis, ''Design of high-speed multiway merge | ||
| 15 | // sorting networks using fast single-stage N-sorters and N-filters,'' *IEEE | ||
| 16 | // Access*, vol. 10, pp. 79565–79581, Jul. 2022, | ||
| 17 | // doi: 10.1109/ACCESS.2022.3193370. The paper is currently available at: | ||
| 18 | // https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9837930 | ||
| 19 | template <class Comparator, typename KernelWindowFunctor, typename T, | ||
| 20 | typename ContextType> | ||
| 21 | 153348 | void sorting_network5x5(KernelWindowFunctor& KernelWindow, T& output_vec, | |
| 22 | ContextType& context) KLEIDICV_STREAMING { | ||
| 23 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 0), KernelWindow(0, 0), context); | |
| 24 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 0), KernelWindow(1, 0), context); | |
| 25 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 0), KernelWindow(0, 0), context); | |
| 26 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 0), KernelWindow(1, 0), context); | |
| 27 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 0), KernelWindow(0, 0), context); | |
| 28 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 0), KernelWindow(2, 0), context); | |
| 29 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 0), KernelWindow(1, 0), context); | |
| 30 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 0), KernelWindow(3, 0), context); | |
| 31 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 0), KernelWindow(2, 0), context); | |
| 32 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 1), KernelWindow(0, 1), context); | |
| 33 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 1), KernelWindow(1, 1), context); | |
| 34 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 1), KernelWindow(0, 1), context); | |
| 35 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 1), KernelWindow(1, 1), context); | |
| 36 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 1), KernelWindow(0, 1), context); | |
| 37 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 1), KernelWindow(2, 1), context); | |
| 38 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 1), KernelWindow(1, 1), context); | |
| 39 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 1), KernelWindow(3, 1), context); | |
| 40 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 1), KernelWindow(2, 1), context); | |
| 41 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 2), KernelWindow(0, 2), context); | |
| 42 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 2), KernelWindow(1, 2), context); | |
| 43 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 2), KernelWindow(0, 2), context); | |
| 44 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 2), KernelWindow(1, 2), context); | |
| 45 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 2), KernelWindow(0, 2), context); | |
| 46 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 2), KernelWindow(2, 2), context); | |
| 47 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 2), KernelWindow(1, 2), context); | |
| 48 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 2), KernelWindow(3, 2), context); | |
| 49 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 2), KernelWindow(2, 2), context); | |
| 50 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 3), KernelWindow(0, 3), context); | |
| 51 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 3), KernelWindow(1, 3), context); | |
| 52 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 3), KernelWindow(0, 3), context); | |
| 53 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 3), KernelWindow(1, 3), context); | |
| 54 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 3), KernelWindow(0, 3), context); | |
| 55 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 3), KernelWindow(2, 3), context); | |
| 56 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 3), KernelWindow(1, 3), context); | |
| 57 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 3), KernelWindow(3, 3), context); | |
| 58 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 3), KernelWindow(2, 3), context); | |
| 59 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 4), KernelWindow(0, 4), context); | |
| 60 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 4), KernelWindow(1, 4), context); | |
| 61 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 4), KernelWindow(0, 4), context); | |
| 62 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 4), KernelWindow(1, 4), context); | |
| 63 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 4), KernelWindow(0, 4), context); | |
| 64 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 4), KernelWindow(2, 4), context); | |
| 65 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 4), KernelWindow(1, 4), context); | |
| 66 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 4), KernelWindow(3, 4), context); | |
| 67 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 4), KernelWindow(2, 4), context); | |
| 68 | // sort row zero for only element 3 and 4 | ||
| 69 | 153348 | Comparator::compare_and_swap(KernelWindow(0, 3), KernelWindow(0, 0), context); | |
| 70 | 153348 | Comparator::compare_and_swap(KernelWindow(0, 4), KernelWindow(0, 1), context); | |
| 71 | 153348 | Comparator::compare_and_swap(KernelWindow(0, 2), KernelWindow(0, 0), context); | |
| 72 | 153348 | Comparator::compare_and_swap(KernelWindow(0, 3), KernelWindow(0, 1), context); | |
| 73 | 153348 | Comparator::min(KernelWindow(0, 1), KernelWindow(0, 0), context); | |
| 74 | 153348 | Comparator::compare_and_swap(KernelWindow(0, 4), KernelWindow(0, 2), context); | |
| 75 | 153348 | Comparator::min(KernelWindow(0, 2), KernelWindow(0, 1), context); | |
| 76 | 153348 | Comparator::compare_and_swap(KernelWindow(0, 4), KernelWindow(0, 3), context); | |
| 77 | 153348 | Comparator::min(KernelWindow(0, 3), KernelWindow(0, 2), context); | |
| 78 | // sort row 1 for only element {2, 3, 4} | ||
| 79 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 3), KernelWindow(1, 0), context); | |
| 80 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 4), KernelWindow(1, 1), context); | |
| 81 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 2), KernelWindow(1, 0), context); | |
| 82 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 3), KernelWindow(1, 1), context); | |
| 83 | 153348 | Comparator::min(KernelWindow(1, 1), KernelWindow(1, 0), context); | |
| 84 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 4), KernelWindow(1, 2), context); | |
| 85 | 153348 | Comparator::min(KernelWindow(1, 2), KernelWindow(1, 1), context); | |
| 86 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 4), KernelWindow(1, 3), context); | |
| 87 | 153348 | Comparator::compare_and_swap(KernelWindow(1, 3), KernelWindow(1, 2), context); | |
| 88 | // sort row 2 {1, 2, 3} | ||
| 89 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 3), KernelWindow(2, 0), context); | |
| 90 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 4), KernelWindow(2, 1), context); | |
| 91 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 2), KernelWindow(2, 0), context); | |
| 92 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 3), KernelWindow(2, 1), context); | |
| 93 | 153348 | Comparator::min(KernelWindow(2, 1), KernelWindow(2, 0), context); | |
| 94 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 4), KernelWindow(2, 2), context); | |
| 95 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 2), KernelWindow(2, 1), context); | |
| 96 | 153348 | Comparator::max(KernelWindow(2, 4), KernelWindow(2, 3), context); | |
| 97 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 3), KernelWindow(2, 2), context); | |
| 98 | // sort row 3 | ||
| 99 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 3), KernelWindow(3, 0), context); | |
| 100 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 4), KernelWindow(3, 1), context); | |
| 101 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 2), KernelWindow(3, 0), context); | |
| 102 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 3), KernelWindow(3, 1), context); | |
| 103 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 1), KernelWindow(3, 0), context); | |
| 104 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 4), KernelWindow(3, 2), context); | |
| 105 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 2), KernelWindow(3, 1), context); | |
| 106 | 153348 | Comparator::max(KernelWindow(3, 4), KernelWindow(3, 3), context); | |
| 107 | 153348 | Comparator::max(KernelWindow(3, 3), KernelWindow(3, 2), context); | |
| 108 | // sort row 4 | ||
| 109 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 3), KernelWindow(4, 0), context); | |
| 110 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 4), KernelWindow(4, 1), context); | |
| 111 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 2), KernelWindow(4, 0), context); | |
| 112 | 153348 | Comparator::max(KernelWindow(4, 3), KernelWindow(4, 1), context); | |
| 113 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 1), KernelWindow(4, 0), context); | |
| 114 | 153348 | Comparator::max(KernelWindow(4, 4), KernelWindow(4, 2), context); | |
| 115 | 153348 | Comparator::max(KernelWindow(4, 2), KernelWindow(4, 1), context); | |
| 116 | // sort dig 0 | ||
| 117 | 153348 | Comparator::min(KernelWindow(2, 1), KernelWindow(0, 3), context); | |
| 118 | 153348 | Comparator::min(KernelWindow(3, 0), KernelWindow(1, 2), context); | |
| 119 | 153348 | Comparator::min(KernelWindow(3, 0), KernelWindow(2, 1), context); | |
| 120 | // sort dig 1 | ||
| 121 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 1), KernelWindow(0, 4), context); | |
| 122 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 0), KernelWindow(1, 3), context); | |
| 123 | 153348 | Comparator::compare_and_swap(KernelWindow(2, 2), KernelWindow(0, 4), context); | |
| 124 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 1), KernelWindow(1, 3), context); | |
| 125 | 153348 | Comparator::min(KernelWindow(1, 3), KernelWindow(0, 4), context); | |
| 126 | 153348 | Comparator::compare_and_swap(KernelWindow(4, 0), KernelWindow(2, 2), context); | |
| 127 | 153348 | Comparator::min(KernelWindow(2, 2), KernelWindow(1, 3), context); | |
| 128 | 153348 | Comparator::max(KernelWindow(4, 0), KernelWindow(3, 1), context); | |
| 129 | 153348 | Comparator::max(KernelWindow(3, 1), KernelWindow(2, 2), context); | |
| 130 | // sort dig 2 | ||
| 131 | 153348 | Comparator::max(KernelWindow(3, 2), KernelWindow(1, 4), context); | |
| 132 | 153348 | Comparator::max(KernelWindow(4, 1), KernelWindow(2, 3), context); | |
| 133 | 153348 | Comparator::max(KernelWindow(2, 3), KernelWindow(1, 4), context); | |
| 134 | 153348 | Comparator::compare_and_swap(KernelWindow(3, 0), KernelWindow(1, 4), context); | |
| 135 | 153348 | Comparator::min(KernelWindow(2, 2), KernelWindow(1, 4), context); | |
| 136 | 153348 | Comparator::max(KernelWindow(3, 0), KernelWindow(2, 2), context); | |
| 137 | 153348 | output_vec = KernelWindow(2, 2); | |
| 138 | 153348 | } | |
| 139 | } // namespace KLEIDICV_TARGET_NAMESPACE | ||
| 140 | |||
| 141 | #endif // KLEIDICV_MEDIAN_BLUR_SORTING_NETWORK_5X5_H | ||
| 142 |