KleidiCV Coverage Report


Directory: ./
File: kleidicv/include/kleidicv/filters/separable_filter_7x7_sc.h
Date: 2025-11-25 17:23:32
Exec Total Coverage
Lines: 113 113 100.0%
Functions: 52 52 100.0%
Branches: 4 4 100.0%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2024 - 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_7X7_SC_H
6 #define KLEIDICV_SEPARABLE_FILTER_7X7_SC_H
7
8 #include "kleidicv/sve2.h"
9 #include "kleidicv/workspace/border_7x7.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 7x7 filter.
19 template <typename FilterType>
20 class SeparableFilter<FilterType, 7UL> {
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::FixedBorderInfo7x7<SourceType>;
33 using BorderType = FixedBorderType;
34 using BorderOffsets = typename BorderInfoType::Offsets;
35
36 150 explicit SeparableFilter(FilterType filter) KLEIDICV_STREAMING
37 150 : filter_{filter} {}
38
39 static constexpr size_t margin = 3UL;
40
41 924 void process_vertical(size_t width, Rows<const SourceType> src_rows,
42 Rows<BufferType> dst_rows,
43 BorderOffsets border_offsets) const KLEIDICV_STREAMING {
44 924 LoopUnroll2 loop{width * src_rows.channels(), SourceVecTraits::num_lanes()};
45
46 1428 loop.unroll_once([&](size_t index) KLEIDICV_STREAMING {
47 504 svbool_t pg_all = SourceVecTraits::svptrue();
48 504 vertical_vector_path(pg_all, src_rows, dst_rows, border_offsets, index);
49 504 });
50
51 1848 loop.remaining([&](size_t index, size_t length) KLEIDICV_STREAMING {
52 924 svbool_t pg = SourceVecTraits::svwhilelt(index, length);
53 924 vertical_vector_path(pg, src_rows, dst_rows, border_offsets, index);
54 924 });
55 924 }
56
57 924 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 924 svbool_t pg_all = BufferVecTraits::svptrue();
62 924 LoopUnroll2 loop{width * src_rows.channels(), BufferVecTraits::num_lanes()};
63
64 1068 loop.unroll_twice([&](size_t index) KLEIDICV_STREAMING {
65 288 horizontal_vector_path_2x(pg_all, src_rows, dst_rows, border_offsets,
66 144 index);
67 144 });
68
69 1164 loop.unroll_once([&](size_t index) KLEIDICV_STREAMING {
70 240 horizontal_vector_path(pg_all, src_rows, dst_rows, border_offsets, index);
71 240 });
72
73 1524 loop.remaining([&](size_t index, size_t length) KLEIDICV_STREAMING {
74 600 svbool_t pg = BufferVecTraits::svwhilelt(index, length);
75 600 horizontal_vector_path(pg, src_rows, dst_rows, border_offsets, index);
76 600 });
77 924 }
78
79 // Processing of horizontal borders is always scalar because border offsets
80 // change for each and every element in the border.
81 5544 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 3636 times.
✓ Branch 1 taken 4932 times.
✓ Branch 2 taken 1908 times.
✓ Branch 3 taken 3204 times.
13680 for (size_t index = 0; index < src_rows.channels(); ++index) {
85 8136 disable_loop_vectorization();
86 8136 process_horizontal_border(src_rows, dst_rows, border_offsets, index);
87 8136 }
88 5544 }
89
90 private:
91 1428 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 2856 SourceVectorType src_0 =
96 1428 svld1(pg, &src_rows.at(border_offsets.c0())[index]);
97 2856 SourceVectorType src_1 =
98 1428 svld1(pg, &src_rows.at(border_offsets.c1())[index]);
99 2856 SourceVectorType src_2 =
100 1428 svld1(pg, &src_rows.at(border_offsets.c2())[index]);
101 2856 SourceVectorType src_3 =
102 1428 svld1(pg, &src_rows.at(border_offsets.c3())[index]);
103 2856 SourceVectorType src_4 =
104 1428 svld1(pg, &src_rows.at(border_offsets.c4())[index]);
105 2856 SourceVectorType src_5 =
106 1428 svld1(pg, &src_rows.at(border_offsets.c5())[index]);
107 2856 SourceVectorType src_6 =
108 1428 svld1(pg, &src_rows.at(border_offsets.c6())[index]);
109 9996 std::reference_wrapper<SourceVectorType> sources[7] = {
110 9996 src_0, src_1, src_2, src_3, src_4, src_5, src_6};
111 1428 filter_.vertical_vector_path(pg, sources, &dst_rows[index]);
112 1428 }
113
114 144 void horizontal_vector_path_2x(svbool_t pg, Rows<const BufferType> src_rows,
115 Rows<DestinationType> dst_rows,
116 BorderOffsets border_offsets,
117 size_t index) const KLEIDICV_STREAMING {
118 144 auto src_0 = &src_rows.at(0, border_offsets.c0())[index];
119 144 auto src_1 = &src_rows.at(0, border_offsets.c1())[index];
120 144 auto src_2 = &src_rows.at(0, border_offsets.c2())[index];
121 144 auto src_3 = &src_rows.at(0, border_offsets.c3())[index];
122 144 auto src_4 = &src_rows.at(0, border_offsets.c4())[index];
123 144 auto src_5 = &src_rows.at(0, border_offsets.c5())[index];
124 144 auto src_6 = &src_rows.at(0, border_offsets.c6())[index];
125
126 144 BufferVectorType src_0_0 = svld1(pg, &src_0[0]);
127 144 BufferVectorType src_1_0 = svld1_vnum(pg, &src_0[0], 1);
128 144 BufferVectorType src_0_1 = svld1(pg, &src_1[0]);
129 144 BufferVectorType src_1_1 = svld1_vnum(pg, &src_1[0], 1);
130 144 BufferVectorType src_0_2 = svld1(pg, &src_2[0]);
131 144 BufferVectorType src_1_2 = svld1_vnum(pg, &src_2[0], 1);
132 144 BufferVectorType src_0_3 = svld1(pg, &src_3[0]);
133 144 BufferVectorType src_1_3 = svld1_vnum(pg, &src_3[0], 1);
134 144 BufferVectorType src_0_4 = svld1(pg, &src_4[0]);
135 144 BufferVectorType src_1_4 = svld1_vnum(pg, &src_4[0], 1);
136 144 BufferVectorType src_0_5 = svld1(pg, &src_5[0]);
137 144 BufferVectorType src_1_5 = svld1_vnum(pg, &src_5[0], 1);
138 144 BufferVectorType src_0_6 = svld1(pg, &src_6[0]);
139 144 BufferVectorType src_1_6 = svld1_vnum(pg, &src_6[0], 1);
140 1008 std::reference_wrapper<BufferVectorType> sources_0[7] = {
141 1008 src_0_0, src_0_1, src_0_2, src_0_3, src_0_4, src_0_5, src_0_6};
142 144 filter_.horizontal_vector_path(pg, sources_0, &dst_rows[index]);
143 1008 std::reference_wrapper<BufferVectorType> sources_1[7] = {
144 1008 src_1_0, src_1_1, src_1_2, src_1_3, src_1_4, src_1_5, src_1_6};
145 216 filter_.horizontal_vector_path(
146 144 pg, sources_1, &dst_rows[index + BufferVecTraits::num_lanes()]);
147 144 }
148
149 840 void horizontal_vector_path(svbool_t pg, Rows<const BufferType> src_rows,
150 Rows<DestinationType> dst_rows,
151 BorderOffsets border_offsets,
152 size_t index) const KLEIDICV_STREAMING {
153 1680 BufferVectorType src_0 =
154 840 svld1(pg, &src_rows.at(0, border_offsets.c0())[index]);
155 1680 BufferVectorType src_1 =
156 840 svld1(pg, &src_rows.at(0, border_offsets.c1())[index]);
157 1680 BufferVectorType src_2 =
158 840 svld1(pg, &src_rows.at(0, border_offsets.c2())[index]);
159 1680 BufferVectorType src_3 =
160 840 svld1(pg, &src_rows.at(0, border_offsets.c3())[index]);
161 1680 BufferVectorType src_4 =
162 840 svld1(pg, &src_rows.at(0, border_offsets.c4())[index]);
163 1680 BufferVectorType src_5 =
164 840 svld1(pg, &src_rows.at(0, border_offsets.c5())[index]);
165 1680 BufferVectorType src_6 =
166 840 svld1(pg, &src_rows.at(0, border_offsets.c6())[index]);
167
168 5880 std::reference_wrapper<BufferVectorType> sources[7] = {
169 5880 src_0, src_1, src_2, src_3, src_4, src_5, src_6};
170 840 filter_.horizontal_vector_path(pg, sources, &dst_rows[index]);
171 840 }
172
173 8136 void process_horizontal_border(Rows<const BufferType> src_rows,
174 Rows<DestinationType> dst_rows,
175 BorderOffsets border_offsets,
176 size_t index) const KLEIDICV_STREAMING {
177 8136 BufferType src[7];
178 8136 src[0] = src_rows.at(0, border_offsets.c0())[index];
179 8136 src[1] = src_rows.at(0, border_offsets.c1())[index];
180 8136 src[2] = src_rows.at(0, border_offsets.c2())[index];
181 8136 src[3] = src_rows.at(0, border_offsets.c3())[index];
182 8136 src[4] = src_rows.at(0, border_offsets.c4())[index];
183 8136 src[5] = src_rows.at(0, border_offsets.c5())[index];
184 8136 src[6] = src_rows.at(0, border_offsets.c6())[index];
185 8136 filter_.horizontal_scalar_path(src, &dst_rows[index]);
186 8136 }
187
188 FilterType filter_;
189 }; // end of class SeparableFilter<FilterType, 7UL>
190
191 // Shorthand for 7x7 separable filters driver type.
192 template <class FilterType>
193 using SeparableFilter7x7 = SeparableFilter<FilterType, 7UL>;
194
195 } // namespace KLEIDICV_TARGET_NAMESPACE
196
197 #endif // KLEIDICV_SEPARABLE_FILTER_7X7_SC_H
198