KleidiCV Coverage Report


Directory: ./
File: kleidicv/include/kleidicv/filters/separable_filter_7x7_sc.h
Date: 2025-09-25 14:13:34
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 100 explicit SeparableFilter(FilterType filter) KLEIDICV_STREAMING
37 100 : filter_{filter} {}
38
39 static constexpr size_t margin = 3UL;
40
41 616 void process_vertical(size_t width, Rows<const SourceType> src_rows,
42 Rows<BufferType> dst_rows,
43 BorderOffsets border_offsets) const KLEIDICV_STREAMING {
44 616 LoopUnroll2 loop{width * src_rows.channels(), SourceVecTraits::num_lanes()};
45
46 976 loop.unroll_once([&](size_t index) KLEIDICV_STREAMING {
47 360 svbool_t pg_all = SourceVecTraits::svptrue();
48 360 vertical_vector_path(pg_all, src_rows, dst_rows, border_offsets, index);
49 360 });
50
51 1232 loop.remaining([&](size_t index, size_t length) KLEIDICV_STREAMING {
52 616 svbool_t pg = SourceVecTraits::svwhilelt(index, length);
53 616 vertical_vector_path(pg, src_rows, dst_rows, border_offsets, index);
54 616 });
55 616 }
56
57 616 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 616 svbool_t pg_all = BufferVecTraits::svptrue();
62 616 LoopUnroll2 loop{width * src_rows.channels(), BufferVecTraits::num_lanes()};
63
64 712 loop.unroll_twice([&](size_t index) KLEIDICV_STREAMING {
65 192 horizontal_vector_path_2x(pg_all, src_rows, dst_rows, border_offsets,
66 96 index);
67 96 });
68
69 784 loop.unroll_once([&](size_t index) KLEIDICV_STREAMING {
70 168 horizontal_vector_path(pg_all, src_rows, dst_rows, border_offsets, index);
71 168 });
72
73 1016 loop.remaining([&](size_t index, size_t length) KLEIDICV_STREAMING {
74 400 svbool_t pg = BufferVecTraits::svwhilelt(index, length);
75 400 horizontal_vector_path(pg, src_rows, dst_rows, border_offsets, index);
76 400 });
77 616 }
78
79 // Processing of horizontal borders is always scalar because border offsets
80 // change for each and every element in the border.
81 3696 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 2424 times.
✓ Branch 1 taken 3288 times.
✓ Branch 2 taken 1272 times.
✓ Branch 3 taken 2136 times.
9120 for (size_t index = 0; index < src_rows.channels(); ++index) {
85 5424 disable_loop_vectorization();
86 5424 process_horizontal_border(src_rows, dst_rows, border_offsets, index);
87 5424 }
88 3696 }
89
90 private:
91 976 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 1952 SourceVectorType src_0 =
96 976 svld1(pg, &src_rows.at(border_offsets.c0())[index]);
97 1952 SourceVectorType src_1 =
98 976 svld1(pg, &src_rows.at(border_offsets.c1())[index]);
99 1952 SourceVectorType src_2 =
100 976 svld1(pg, &src_rows.at(border_offsets.c2())[index]);
101 1952 SourceVectorType src_3 =
102 976 svld1(pg, &src_rows.at(border_offsets.c3())[index]);
103 1952 SourceVectorType src_4 =
104 976 svld1(pg, &src_rows.at(border_offsets.c4())[index]);
105 1952 SourceVectorType src_5 =
106 976 svld1(pg, &src_rows.at(border_offsets.c5())[index]);
107 1952 SourceVectorType src_6 =
108 976 svld1(pg, &src_rows.at(border_offsets.c6())[index]);
109 6832 std::reference_wrapper<SourceVectorType> sources[7] = {
110 6832 src_0, src_1, src_2, src_3, src_4, src_5, src_6};
111 976 filter_.vertical_vector_path(pg, sources, &dst_rows[index]);
112 976 }
113
114 96 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 96 auto src_0 = &src_rows.at(0, border_offsets.c0())[index];
119 96 auto src_1 = &src_rows.at(0, border_offsets.c1())[index];
120 96 auto src_2 = &src_rows.at(0, border_offsets.c2())[index];
121 96 auto src_3 = &src_rows.at(0, border_offsets.c3())[index];
122 96 auto src_4 = &src_rows.at(0, border_offsets.c4())[index];
123 96 auto src_5 = &src_rows.at(0, border_offsets.c5())[index];
124 96 auto src_6 = &src_rows.at(0, border_offsets.c6())[index];
125
126 96 BufferVectorType src_0_0 = svld1(pg, &src_0[0]);
127 96 BufferVectorType src_1_0 = svld1_vnum(pg, &src_0[0], 1);
128 96 BufferVectorType src_0_1 = svld1(pg, &src_1[0]);
129 96 BufferVectorType src_1_1 = svld1_vnum(pg, &src_1[0], 1);
130 96 BufferVectorType src_0_2 = svld1(pg, &src_2[0]);
131 96 BufferVectorType src_1_2 = svld1_vnum(pg, &src_2[0], 1);
132 96 BufferVectorType src_0_3 = svld1(pg, &src_3[0]);
133 96 BufferVectorType src_1_3 = svld1_vnum(pg, &src_3[0], 1);
134 96 BufferVectorType src_0_4 = svld1(pg, &src_4[0]);
135 96 BufferVectorType src_1_4 = svld1_vnum(pg, &src_4[0], 1);
136 96 BufferVectorType src_0_5 = svld1(pg, &src_5[0]);
137 96 BufferVectorType src_1_5 = svld1_vnum(pg, &src_5[0], 1);
138 96 BufferVectorType src_0_6 = svld1(pg, &src_6[0]);
139 96 BufferVectorType src_1_6 = svld1_vnum(pg, &src_6[0], 1);
140 672 std::reference_wrapper<BufferVectorType> sources_0[7] = {
141 672 src_0_0, src_0_1, src_0_2, src_0_3, src_0_4, src_0_5, src_0_6};
142 96 filter_.horizontal_vector_path(pg, sources_0, &dst_rows[index]);
143 672 std::reference_wrapper<BufferVectorType> sources_1[7] = {
144 672 src_1_0, src_1_1, src_1_2, src_1_3, src_1_4, src_1_5, src_1_6};
145 144 filter_.horizontal_vector_path(
146 96 pg, sources_1, &dst_rows[index + BufferVecTraits::num_lanes()]);
147 96 }
148
149 568 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 1136 BufferVectorType src_0 =
154 568 svld1(pg, &src_rows.at(0, border_offsets.c0())[index]);
155 1136 BufferVectorType src_1 =
156 568 svld1(pg, &src_rows.at(0, border_offsets.c1())[index]);
157 1136 BufferVectorType src_2 =
158 568 svld1(pg, &src_rows.at(0, border_offsets.c2())[index]);
159 1136 BufferVectorType src_3 =
160 568 svld1(pg, &src_rows.at(0, border_offsets.c3())[index]);
161 1136 BufferVectorType src_4 =
162 568 svld1(pg, &src_rows.at(0, border_offsets.c4())[index]);
163 1136 BufferVectorType src_5 =
164 568 svld1(pg, &src_rows.at(0, border_offsets.c5())[index]);
165 1136 BufferVectorType src_6 =
166 568 svld1(pg, &src_rows.at(0, border_offsets.c6())[index]);
167
168 3976 std::reference_wrapper<BufferVectorType> sources[7] = {
169 3976 src_0, src_1, src_2, src_3, src_4, src_5, src_6};
170 568 filter_.horizontal_vector_path(pg, sources, &dst_rows[index]);
171 568 }
172
173 5424 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 5424 BufferType src[7];
178 5424 src[0] = src_rows.at(0, border_offsets.c0())[index];
179 5424 src[1] = src_rows.at(0, border_offsets.c1())[index];
180 5424 src[2] = src_rows.at(0, border_offsets.c2())[index];
181 5424 src[3] = src_rows.at(0, border_offsets.c3())[index];
182 5424 src[4] = src_rows.at(0, border_offsets.c4())[index];
183 5424 src[5] = src_rows.at(0, border_offsets.c5())[index];
184 5424 src[6] = src_rows.at(0, border_offsets.c6())[index];
185 5424 filter_.horizontal_scalar_path(src, &dst_rows[index]);
186 5424 }
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