KleidiCV Coverage Report


Directory: ./
File: kleidicv/include/kleidicv/filters/separable_filter_5x5_sc.h
Date: 2026-03-05 15:57:40
Exec Total Coverage
Lines: 97 97 100.0%
Functions: 104 104 100.0%
Branches: 4 4 100.0%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2023 - 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 #ifndef KLEIDICV_SEPARABLE_FILTER_5X5_SC_H
6 #define KLEIDICV_SEPARABLE_FILTER_5X5_SC_H
7
8 #include "kleidicv/sve2.h"
9 #include "kleidicv/workspace/border_5x5.h"
10
11 // It is used by SVE2 and SME, the actual namespace will reflect it.
12 namespace KLEIDICV_TARGET_NAMESPACE {
13
14 // Template for drivers of separable NxM filters.
15 template <typename FilterType, const size_t S>
16 class SeparableFilter;
17
18 // Driver for a separable 5x5 filter.
19 template <typename FilterType>
20 class SeparableFilter<FilterType, 5UL> {
21 public:
22 using SourceType = typename FilterType::SourceType;
23 using BufferType = typename FilterType::BufferType;
24 using DestinationType = typename FilterType::DestinationType;
25 using SourceVecTraits =
26 typename ::KLEIDICV_TARGET_NAMESPACE::VecTraits<SourceType>;
27 using SourceVectorType = typename SourceVecTraits::VectorType;
28 using BufferVecTraits =
29 typename ::KLEIDICV_TARGET_NAMESPACE::VecTraits<BufferType>;
30 using BufferVectorType = typename BufferVecTraits::VectorType;
31 using BorderInfoType =
32 typename ::KLEIDICV_TARGET_NAMESPACE::FixedBorderInfo5x5<SourceType>;
33 using BorderType = FixedBorderType;
34 using BorderOffsets = typename BorderInfoType::Offsets;
35
36 624 explicit SeparableFilter(FilterType filter) KLEIDICV_STREAMING
37 624 : filter_{filter} {}
38
39 static constexpr size_t margin = 2UL;
40
41 6189 void process_vertical(size_t width, Rows<const SourceType> src_rows,
42 Rows<BufferType> dst_rows,
43 BorderOffsets border_offsets) const KLEIDICV_STREAMING {
44 6189 LoopUnroll2 loop{width * src_rows.channels(), SourceVecTraits::num_lanes()};
45
46 7855 loop.unroll_once([&](size_t index) KLEIDICV_STREAMING {
47 1666 svbool_t pg_all = SourceVecTraits::svptrue();
48 1666 vertical_vector_path(pg_all, src_rows, dst_rows, border_offsets, index);
49 1666 });
50
51 12294 loop.remaining([&](size_t index, size_t length) KLEIDICV_STREAMING {
52 6105 svbool_t pg = SourceVecTraits::svwhilelt(index, length);
53 6105 vertical_vector_path(pg, src_rows, dst_rows, border_offsets, index);
54 6105 });
55 6189 }
56
57 6189 void process_horizontal(size_t width, Rows<const BufferType> src_rows,
58 Rows<DestinationType> dst_rows,
59 BorderOffsets border_offsets) const
60 KLEIDICV_STREAMING {
61 6189 svbool_t pg_all = BufferVecTraits::svptrue();
62 6189 LoopUnroll2 loop{width * src_rows.channels(), BufferVecTraits::num_lanes()};
63
64 7508 loop.unroll_twice([&](size_t index) KLEIDICV_STREAMING {
65 2638 horizontal_vector_path_2x(pg_all, src_rows, dst_rows, border_offsets,
66 1319 index);
67 1319 });
68
69 7044 loop.unroll_once([&](size_t index) KLEIDICV_STREAMING {
70 855 horizontal_vector_path(pg_all, src_rows, dst_rows, border_offsets, index);
71 855 });
72
73 9652 loop.remaining([&](size_t index, size_t length) KLEIDICV_STREAMING {
74 3463 svbool_t pg = BufferVecTraits::svwhilelt(index, length);
75 3463 horizontal_vector_path(pg, src_rows, dst_rows, border_offsets, index);
76 3463 });
77 6189 }
78
79 // Processing of horizontal borders is always scalar because border offsets
80 // change for each and every element in the border.
81 24756 void process_horizontal_borders(
82 Rows<const BufferType> src_rows, Rows<DestinationType> dst_rows,
83 BorderOffsets border_offsets) const KLEIDICV_STREAMING {
84
4/4
✓ Branch 0 taken 15768 times.
✓ Branch 1 taken 16920 times.
✓ Branch 2 taken 8988 times.
✓ Branch 3 taken 10140 times.
51816 for (size_t index = 0; index < src_rows.channels(); ++index) {
85 27060 disable_loop_vectorization();
86 27060 process_horizontal_border(src_rows, dst_rows, border_offsets, index);
87 27060 }
88 24756 }
89
90 private:
91 7771 void vertical_vector_path(svbool_t pg, Rows<const SourceType> src_rows,
92 Rows<BufferType> dst_rows,
93 BorderOffsets border_offsets,
94 size_t index) const KLEIDICV_STREAMING {
95 15542 SourceVectorType src_0 =
96 7771 svld1(pg, &src_rows.at(border_offsets.c0())[index]);
97 15542 SourceVectorType src_1 =
98 7771 svld1(pg, &src_rows.at(border_offsets.c1())[index]);
99 15542 SourceVectorType src_2 =
100 7771 svld1(pg, &src_rows.at(border_offsets.c2())[index]);
101 15542 SourceVectorType src_3 =
102 7771 svld1(pg, &src_rows.at(border_offsets.c3())[index]);
103 15542 SourceVectorType src_4 =
104 7771 svld1(pg, &src_rows.at(border_offsets.c4())[index]);
105 15542 std::reference_wrapper<SourceVectorType> sources[5] = {src_0, src_1, src_2,
106 15542 src_3, src_4};
107 7771 filter_.vertical_vector_path(pg, sources, &dst_rows[index]);
108 7771 }
109
110 1319 void horizontal_vector_path_2x(svbool_t pg, Rows<const BufferType> src_rows,
111 Rows<DestinationType> dst_rows,
112 BorderOffsets border_offsets,
113 size_t index) const KLEIDICV_STREAMING {
114 1319 auto src_0 = &src_rows.at(0, border_offsets.c0())[index];
115 1319 auto src_1 = &src_rows.at(0, border_offsets.c1())[index];
116 1319 auto src_2 = &src_rows.at(0, border_offsets.c2())[index];
117 1319 auto src_3 = &src_rows.at(0, border_offsets.c3())[index];
118 1319 auto src_4 = &src_rows.at(0, border_offsets.c4())[index];
119
120 1319 BufferVectorType src_0_0 = svld1(pg, &src_0[0]);
121 1319 BufferVectorType src_1_0 = svld1_vnum(pg, &src_0[0], 1);
122 1319 BufferVectorType src_0_1 = svld1(pg, &src_1[0]);
123 1319 BufferVectorType src_1_1 = svld1_vnum(pg, &src_1[0], 1);
124 1319 BufferVectorType src_0_2 = svld1(pg, &src_2[0]);
125 1319 BufferVectorType src_1_2 = svld1_vnum(pg, &src_2[0], 1);
126 1319 BufferVectorType src_0_3 = svld1(pg, &src_3[0]);
127 1319 BufferVectorType src_1_3 = svld1_vnum(pg, &src_3[0], 1);
128 1319 BufferVectorType src_0_4 = svld1(pg, &src_4[0]);
129 1319 BufferVectorType src_1_4 = svld1_vnum(pg, &src_4[0], 1);
130 6595 std::reference_wrapper<BufferVectorType> sources_0[5] = {
131 6595 src_0_0, src_0_1, src_0_2, src_0_3, src_0_4};
132 1319 filter_.horizontal_vector_path(pg, sources_0, &dst_rows[index]);
133 6595 std::reference_wrapper<BufferVectorType> sources_1[5] = {
134 6595 src_1_0, src_1_1, src_1_2, src_1_3, src_1_4};
135 2406 filter_.horizontal_vector_path(
136 1319 pg, sources_1, &dst_rows[index + BufferVecTraits::num_lanes()]);
137 1319 }
138
139 4318 void horizontal_vector_path(svbool_t pg, Rows<const BufferType> src_rows,
140 Rows<DestinationType> dst_rows,
141 BorderOffsets border_offsets,
142 size_t index) const KLEIDICV_STREAMING {
143 8636 BufferVectorType src_0 =
144 4318 svld1(pg, &src_rows.at(0, border_offsets.c0())[index]);
145 8636 BufferVectorType src_1 =
146 4318 svld1(pg, &src_rows.at(0, border_offsets.c1())[index]);
147 8636 BufferVectorType src_2 =
148 4318 svld1(pg, &src_rows.at(0, border_offsets.c2())[index]);
149 8636 BufferVectorType src_3 =
150 4318 svld1(pg, &src_rows.at(0, border_offsets.c3())[index]);
151 8636 BufferVectorType src_4 =
152 4318 svld1(pg, &src_rows.at(0, border_offsets.c4())[index]);
153 8636 std::reference_wrapper<BufferVectorType> sources[5] = {src_0, src_1, src_2,
154 8636 src_3, src_4};
155 4318 filter_.horizontal_vector_path(pg, sources, &dst_rows[index]);
156 4318 }
157
158 27060 void process_horizontal_border(Rows<const BufferType> src_rows,
159 Rows<DestinationType> dst_rows,
160 BorderOffsets border_offsets,
161 size_t index) const KLEIDICV_STREAMING {
162 27060 BufferType src[5];
163 27060 src[0] = src_rows.at(0, border_offsets.c0())[index];
164 27060 src[1] = src_rows.at(0, border_offsets.c1())[index];
165 27060 src[2] = src_rows.at(0, border_offsets.c2())[index];
166 27060 src[3] = src_rows.at(0, border_offsets.c3())[index];
167 27060 src[4] = src_rows.at(0, border_offsets.c4())[index];
168 27060 filter_.horizontal_scalar_path(src, &dst_rows[index]);
169 27060 }
170
171 FilterType filter_;
172 }; // end of class SeparableFilter<FilterType, 5UL>
173
174 // Shorthand for 5x5 separable filters driver type.
175 template <class FilterType>
176 using SeparableFilter5x5 = SeparableFilter<FilterType, 5UL>;
177
178 } // namespace KLEIDICV_TARGET_NAMESPACE
179
180 #endif // KLEIDICV_SEPARABLE_FILTER_5X5_SC_H
181