KleidiCV Coverage Report


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

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2023 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_NEON_H
6 #define KLEIDICV_SEPARABLE_FILTER_5X5_NEON_H
7
8 #include "kleidicv/neon.h"
9 #include "kleidicv/workspace/border_5x5.h"
10
11 namespace KLEIDICV_TARGET_NAMESPACE {
12
13 // Template for drivers of separable NxM filters.
14 template <typename FilterType, const size_t S>
15 class SeparableFilter;
16
17 // Driver for a separable 5x5 filter.
18 template <typename FilterType>
19 class SeparableFilter<FilterType, 5UL> {
20 public:
21 using SourceType = typename FilterType::SourceType;
22 using BufferType = typename FilterType::BufferType;
23 using DestinationType = typename FilterType::DestinationType;
24 using SourceVecTraits = typename neon::VecTraits<SourceType>;
25 using SourceVectorType = typename SourceVecTraits::VectorType;
26 using BufferVecTraits = typename neon::VecTraits<BufferType>;
27 using BufferVectorType = typename BufferVecTraits::VectorType;
28 using BorderInfoType =
29 typename ::KLEIDICV_TARGET_NAMESPACE::FixedBorderInfo5x5<SourceType>;
30 using BorderType = FixedBorderType;
31 using BorderOffsets = typename BorderInfoType::Offsets;
32
33 208 explicit SeparableFilter(FilterType filter) : filter_{filter} {}
34
35 static constexpr size_t margin = 2UL;
36
37 2063 void process_vertical(size_t width, Rows<const SourceType> src_rows,
38 Rows<BufferType> dst_rows,
39 BorderOffsets border_offsets) const {
40 4126 LoopUnroll2<TryToAvoidTailLoop> loop{width * src_rows.channels(),
41 2063 SourceVecTraits::num_lanes()};
42
43 3584 loop.unroll_once([&](size_t index) {
44 1521 SourceVectorType src[5];
45 1521 src[0] = vld1q(&src_rows.at(border_offsets.c0())[index]);
46 1521 src[1] = vld1q(&src_rows.at(border_offsets.c1())[index]);
47 1521 src[2] = vld1q(&src_rows.at(border_offsets.c2())[index]);
48 1521 src[3] = vld1q(&src_rows.at(border_offsets.c3())[index]);
49 1521 src[4] = vld1q(&src_rows.at(border_offsets.c4())[index]);
50 1521 filter_.vertical_vector_path(src, &dst_rows[index]);
51 1521 });
52
53 12269 loop.tail([&](size_t index) {
54 10206 SourceType src[5];
55 10206 src[0] = src_rows.at(border_offsets.c0())[index];
56 10206 src[1] = src_rows.at(border_offsets.c1())[index];
57 10206 src[2] = src_rows.at(border_offsets.c2())[index];
58 10206 src[3] = src_rows.at(border_offsets.c3())[index];
59 10206 src[4] = src_rows.at(border_offsets.c4())[index];
60 10206 filter_.vertical_scalar_path(src, &dst_rows[index]);
61 10206 });
62 2063 }
63
64 2063 void process_horizontal(size_t width, Rows<const BufferType> src_rows,
65 Rows<DestinationType> dst_rows,
66 BorderOffsets border_offsets) const {
67 4126 LoopUnroll2<TryToAvoidTailLoop> loop{width * src_rows.channels(),
68 2063 BufferVecTraits::num_lanes()};
69
70 2926 loop.unroll_twice([&](size_t index) {
71 863 auto src_0 = &src_rows.at(0, border_offsets.c0())[index];
72 863 auto src_1 = &src_rows.at(0, border_offsets.c1())[index];
73 863 auto src_2 = &src_rows.at(0, border_offsets.c2())[index];
74 863 auto src_3 = &src_rows.at(0, border_offsets.c3())[index];
75 863 auto src_4 = &src_rows.at(0, border_offsets.c4())[index];
76
77 863 BufferVectorType src_a[5], src_b[5];
78 863 src_a[0] = vld1q(&src_0[0]);
79 863 src_b[0] = vld1q(&src_0[BufferVecTraits::num_lanes()]);
80 863 src_a[1] = vld1q(&src_1[0]);
81 863 src_b[1] = vld1q(&src_1[BufferVecTraits::num_lanes()]);
82 863 src_a[2] = vld1q(&src_2[0]);
83 863 src_b[2] = vld1q(&src_2[BufferVecTraits::num_lanes()]);
84 863 src_a[3] = vld1q(&src_3[0]);
85 863 src_b[3] = vld1q(&src_3[BufferVecTraits::num_lanes()]);
86 863 src_a[4] = vld1q(&src_4[0]);
87 863 src_b[4] = vld1q(&src_4[BufferVecTraits::num_lanes()]);
88
89 863 filter_.horizontal_vector_path(src_a, &dst_rows[index]);
90 1726 filter_.horizontal_vector_path(
91 863 src_b, &dst_rows[index + BufferVecTraits::num_lanes()]);
92 863 });
93
94 2769 loop.unroll_once([&](size_t index) {
95 706 BufferVectorType src[5];
96 706 src[0] = vld1q(&src_rows.at(0, border_offsets.c0())[index]);
97 706 src[1] = vld1q(&src_rows.at(0, border_offsets.c1())[index]);
98 706 src[2] = vld1q(&src_rows.at(0, border_offsets.c2())[index]);
99 706 src[3] = vld1q(&src_rows.at(0, border_offsets.c3())[index]);
100 706 src[4] = vld1q(&src_rows.at(0, border_offsets.c4())[index]);
101 706 filter_.horizontal_vector_path(src, &dst_rows[index]);
102 706 });
103
104 3121 loop.tail([&](size_t index) {
105 1058 process_horizontal_scalar(src_rows, dst_rows, border_offsets, index);
106 1058 });
107 2063 }
108
109 8252 void process_horizontal_borders(Rows<const BufferType> src_rows,
110 Rows<DestinationType> dst_rows,
111 BorderOffsets border_offsets) const {
112
4/4
✓ Branch 0 taken 5256 times.
✓ Branch 1 taken 5640 times.
✓ Branch 2 taken 2996 times.
✓ Branch 3 taken 3380 times.
17272 for (size_t index = 0; index < src_rows.channels(); ++index) {
113 9020 disable_loop_vectorization();
114 9020 process_horizontal_scalar(src_rows, dst_rows, border_offsets, index);
115 9020 }
116 8252 }
117
118 private:
119 10078 void process_horizontal_scalar(Rows<const BufferType> src_rows,
120 Rows<DestinationType> dst_rows,
121 BorderOffsets border_offsets,
122 size_t index) const {
123 10078 BufferType src[5];
124 10078 src[0] = src_rows.at(0, border_offsets.c0())[index];
125 10078 src[1] = src_rows.at(0, border_offsets.c1())[index];
126 10078 src[2] = src_rows.at(0, border_offsets.c2())[index];
127 10078 src[3] = src_rows.at(0, border_offsets.c3())[index];
128 10078 src[4] = src_rows.at(0, border_offsets.c4())[index];
129 10078 filter_.horizontal_scalar_path(src, &dst_rows[index]);
130 10078 }
131
132 FilterType filter_;
133 }; // end of class SeparableFilter<FilterType, 5UL>
134
135 // Shorthand for 5x5 separable filters driver type.
136 template <class FilterType>
137 using SeparableFilter5x5 = SeparableFilter<FilterType, 5UL>;
138
139 } // namespace KLEIDICV_TARGET_NAMESPACE
140
141 #endif // KLEIDICV_SEPARABLE_FILTER_5X5_NEON_H
142