KleidiCV Coverage Report


Directory: ./
File: kleidicv/include/kleidicv/workspace/border_5x5.h
Date: 2025-11-25 17:23:32
Exec Total Coverage
Lines: 50 50 100.0%
Functions: 252 252 100.0%
Branches: 196 210 93.3%

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_WORKSPACE_BORDER_5X5_H
6 #define KLEIDICV_WORKSPACE_BORDER_5X5_H
7
8 #include "border_types.h"
9 #include "kleidicv/kleidicv.h"
10
11 namespace KLEIDICV_TARGET_NAMESPACE {
12
13 // Border offsets for fixed-size filters.
14 template <typename T, const size_t S>
15 class FixedBorderInfo;
16
17 // Border offsets for 5x5 filters.
18 template <typename T>
19 class FixedBorderInfo<T, 5UL> final {
20 public:
21 // Simple object holding read-only constant offsets.
22 class Offsets final {
23 public:
24 // NOLINTBEGIN(hicpp-member-init)
25 Offsets() = default;
26 // NOLINTEND(hicpp-member-init)
27
28 173688 Offsets(ptrdiff_t o0, ptrdiff_t o1, ptrdiff_t o2, ptrdiff_t o3,
29 ptrdiff_t o4)
30 173688 : offsets_{o0, o1, o2, o3, o4} {}
31
32 1626264 ptrdiff_t c0() const { return offsets_[0]; }
33 1626264 ptrdiff_t c1() const { return offsets_[1]; }
34 1626264 ptrdiff_t c2() const { return offsets_[2]; }
35 1626264 ptrdiff_t c3() const { return offsets_[3]; }
36 1626264 ptrdiff_t c4() const { return offsets_[4]; }
37
38 private:
39 ptrdiff_t offsets_[5];
40 };
41
42 6472 FixedBorderInfo(size_t height, FixedBorderType border_type)
43 6472 : height_(height), border_type_(border_type) {}
44
45 // Returns offsets without the influence of any border.
46 47064 Offsets offsets_without_border() const KLEIDICV_STREAMING {
47 47064 return get(-2, -1, 0, 1, 2);
48 }
49
50 // Returns offsets for columns affected by left border.
51 63312 Offsets offsets_with_left_border(size_t column_index) const
52 KLEIDICV_STREAMING {
53
28/35
✗ Branch 0 not taken.
✓ Branch 1 taken 11656 times.
✓ Branch 2 taken 1752 times.
✓ Branch 3 taken 1752 times.
✓ Branch 4 taken 1832 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9912 times.
✓ Branch 7 taken 1032 times.
✓ Branch 8 taken 1032 times.
✓ Branch 9 taken 1032 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 9864 times.
✓ Branch 12 taken 1032 times.
✓ Branch 13 taken 1032 times.
✓ Branch 14 taken 1032 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5072 times.
✓ Branch 17 taken 704 times.
✓ Branch 18 taken 704 times.
✓ Branch 19 taken 704 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 880 times.
✓ Branch 22 taken 704 times.
✓ Branch 23 taken 704 times.
✓ Branch 24 taken 704 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 880 times.
✓ Branch 27 taken 704 times.
✓ Branch 28 taken 704 times.
✓ Branch 29 taken 704 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 5072 times.
✓ Branch 32 taken 704 times.
✓ Branch 33 taken 704 times.
✓ Branch 34 taken 704 times.
63312 switch (border_type_) {
54 case FixedBorderType::REPLICATE:
55
14/14
✓ Branch 0 taken 5168 times.
✓ Branch 1 taken 6488 times.
✓ Branch 2 taken 4956 times.
✓ Branch 3 taken 4956 times.
✓ Branch 4 taken 4932 times.
✓ Branch 5 taken 4932 times.
✓ Branch 6 taken 2536 times.
✓ Branch 7 taken 2536 times.
✓ Branch 8 taken 440 times.
✓ Branch 9 taken 440 times.
✓ Branch 10 taken 440 times.
✓ Branch 11 taken 440 times.
✓ Branch 12 taken 2536 times.
✓ Branch 13 taken 2536 times.
43336 if (column_index == 0) {
56 22328 return get(0, 0, 0, 1, 2);
57 } else {
58 21008 return get(-1, -1, 0, 1, 2);
59 }
60 break;
61
62 case FixedBorderType::REFLECT:
63
14/14
✓ Branch 0 taken 764 times.
✓ Branch 1 taken 988 times.
✓ Branch 2 taken 516 times.
✓ Branch 3 taken 516 times.
✓ Branch 4 taken 516 times.
✓ Branch 5 taken 516 times.
✓ Branch 6 taken 352 times.
✓ Branch 7 taken 352 times.
✓ Branch 8 taken 352 times.
✓ Branch 9 taken 352 times.
✓ Branch 10 taken 352 times.
✓ Branch 11 taken 352 times.
✓ Branch 12 taken 352 times.
✓ Branch 13 taken 352 times.
6632 if (column_index == 0) {
64 3428 return get(1, 0, 0, 1, 2);
65 } else {
66 3204 return get(-1, -1, 0, 1, 2);
67 }
68 break;
69
70 case FixedBorderType::WRAP:
71
14/14
✓ Branch 0 taken 764 times.
✓ Branch 1 taken 988 times.
✓ Branch 2 taken 516 times.
✓ Branch 3 taken 516 times.
✓ Branch 4 taken 516 times.
✓ Branch 5 taken 516 times.
✓ Branch 6 taken 352 times.
✓ Branch 7 taken 352 times.
✓ Branch 8 taken 352 times.
✓ Branch 9 taken 352 times.
✓ Branch 10 taken 352 times.
✓ Branch 11 taken 352 times.
✓ Branch 12 taken 352 times.
✓ Branch 13 taken 352 times.
6632 if (column_index == 0) {
72 3428 return get(height_ - 2, height_ - 1, 0, 1, 2);
73 } else {
74 3204 return get(height_ - 2, -1, 0, 1, 2);
75 }
76 break;
77
78 case FixedBorderType::REVERSE:
79
14/14
✓ Branch 0 taken 804 times.
✓ Branch 1 taken 1028 times.
✓ Branch 2 taken 516 times.
✓ Branch 3 taken 516 times.
✓ Branch 4 taken 516 times.
✓ Branch 5 taken 516 times.
✓ Branch 6 taken 352 times.
✓ Branch 7 taken 352 times.
✓ Branch 8 taken 352 times.
✓ Branch 9 taken 352 times.
✓ Branch 10 taken 352 times.
✓ Branch 11 taken 352 times.
✓ Branch 12 taken 352 times.
✓ Branch 13 taken 352 times.
6712 if (column_index == 0) {
80 3468 return get(2, 1, 0, 1, 2);
81 } else {
82 3244 return get(0, -1, 0, 1, 2);
83 }
84 break;
85 }
86 // Unreachable. Compiler should emit a warning-as-error if any cases are
87 // uncovered above.
88 return Offsets{}; // GCOVR_EXCL_LINE
89 63312 }
90
91 // Returns offsets for columns affected by right border.
92 63312 Offsets offsets_with_right_border(size_t column_index) const
93 KLEIDICV_STREAMING {
94
28/35
✗ Branch 0 not taken.
✓ Branch 1 taken 11656 times.
✓ Branch 2 taken 1752 times.
✓ Branch 3 taken 1752 times.
✓ Branch 4 taken 1832 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9912 times.
✓ Branch 7 taken 1032 times.
✓ Branch 8 taken 1032 times.
✓ Branch 9 taken 1032 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 9864 times.
✓ Branch 12 taken 1032 times.
✓ Branch 13 taken 1032 times.
✓ Branch 14 taken 1032 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5072 times.
✓ Branch 17 taken 704 times.
✓ Branch 18 taken 704 times.
✓ Branch 19 taken 704 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 880 times.
✓ Branch 22 taken 704 times.
✓ Branch 23 taken 704 times.
✓ Branch 24 taken 704 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 880 times.
✓ Branch 27 taken 704 times.
✓ Branch 28 taken 704 times.
✓ Branch 29 taken 704 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 5072 times.
✓ Branch 32 taken 704 times.
✓ Branch 33 taken 704 times.
✓ Branch 34 taken 704 times.
63312 switch (border_type_) {
95 case FixedBorderType::REPLICATE:
96
14/14
✓ Branch 0 taken 6424 times.
✓ Branch 1 taken 5232 times.
✓ Branch 2 taken 4956 times.
✓ Branch 3 taken 4956 times.
✓ Branch 4 taken 4932 times.
✓ Branch 5 taken 4932 times.
✓ Branch 6 taken 2536 times.
✓ Branch 7 taken 2536 times.
✓ Branch 8 taken 440 times.
✓ Branch 9 taken 440 times.
✓ Branch 10 taken 440 times.
✓ Branch 11 taken 440 times.
✓ Branch 12 taken 2536 times.
✓ Branch 13 taken 2536 times.
43336 if (column_index == (height_ - 2)) {
97 22264 return get(-2, -1, 0, 1, 1);
98 } else {
99 21072 return get(-2, -1, 0, 0, 0);
100 }
101 break;
102
103 case FixedBorderType::REFLECT:
104
14/14
✓ Branch 0 taken 948 times.
✓ Branch 1 taken 804 times.
✓ Branch 2 taken 516 times.
✓ Branch 3 taken 516 times.
✓ Branch 4 taken 516 times.
✓ Branch 5 taken 516 times.
✓ Branch 6 taken 352 times.
✓ Branch 7 taken 352 times.
✓ Branch 8 taken 352 times.
✓ Branch 9 taken 352 times.
✓ Branch 10 taken 352 times.
✓ Branch 11 taken 352 times.
✓ Branch 12 taken 352 times.
✓ Branch 13 taken 352 times.
6632 if (column_index == (height_ - 2)) {
105 3388 return get(-2, -1, 0, 1, 1);
106 } else {
107 3244 return get(-2, -1, 0, 0, -1);
108 }
109 break;
110
111 case FixedBorderType::WRAP:
112
14/14
✓ Branch 0 taken 948 times.
✓ Branch 1 taken 804 times.
✓ Branch 2 taken 516 times.
✓ Branch 3 taken 516 times.
✓ Branch 4 taken 516 times.
✓ Branch 5 taken 516 times.
✓ Branch 6 taken 352 times.
✓ Branch 7 taken 352 times.
✓ Branch 8 taken 352 times.
✓ Branch 9 taken 352 times.
✓ Branch 10 taken 352 times.
✓ Branch 11 taken 352 times.
✓ Branch 12 taken 352 times.
✓ Branch 13 taken 352 times.
6632 if (column_index == (height_ - 2)) {
113 3388 return get(-2, -1, 0, 1, 2 - height_);
114 } else {
115 3244 return get(-2, -1, 0, 1 - height_, 2 - height_);
116 }
117 break;
118
119 case FixedBorderType::REVERSE:
120
14/14
✓ Branch 0 taken 988 times.
✓ Branch 1 taken 844 times.
✓ Branch 2 taken 516 times.
✓ Branch 3 taken 516 times.
✓ Branch 4 taken 516 times.
✓ Branch 5 taken 516 times.
✓ Branch 6 taken 352 times.
✓ Branch 7 taken 352 times.
✓ Branch 8 taken 352 times.
✓ Branch 9 taken 352 times.
✓ Branch 10 taken 352 times.
✓ Branch 11 taken 352 times.
✓ Branch 12 taken 352 times.
✓ Branch 13 taken 352 times.
6712 if (column_index == (height_ - 2)) {
121 3428 return get(-2, -1, 0, 1, 0);
122 } else {
123 3284 return get(-2, -1, 0, -1, -2);
124 }
125 break;
126 }
127 // Unreachable. Compiler should emit a warning-as-error if any cases are
128 // uncovered above.
129 return Offsets{}; // GCOVR_EXCL_LINE
130 63312 }
131
132 // Returns offsets for rows or columns affected by any border.
133 29560 Offsets offsets_with_border(size_t row_or_column_index) const
134 KLEIDICV_STREAMING {
135
14/14
✓ Branch 0 taken 1604 times.
✓ Branch 1 taken 7008 times.
✓ Branch 2 taken 1048 times.
✓ Branch 3 taken 4932 times.
✓ Branch 4 taken 1040 times.
✓ Branch 5 taken 4920 times.
✓ Branch 6 taken 640 times.
✓ Branch 7 taken 2632 times.
✓ Branch 8 taken 528 times.
✓ Branch 9 taken 704 times.
✓ Branch 10 taken 528 times.
✓ Branch 11 taken 704 times.
✓ Branch 12 taken 640 times.
✓ Branch 13 taken 2632 times.
29560 if (row_or_column_index <= 1U) {
136 // Rows and columns have the same offsets.
137 6028 return offsets_with_left_border(row_or_column_index);
138 }
139
14/14
✓ Branch 0 taken 1604 times.
✓ Branch 1 taken 5404 times.
✓ Branch 2 taken 1048 times.
✓ Branch 3 taken 3884 times.
✓ Branch 4 taken 1040 times.
✓ Branch 5 taken 3880 times.
✓ Branch 6 taken 640 times.
✓ Branch 7 taken 1992 times.
✓ Branch 8 taken 528 times.
✓ Branch 9 taken 176 times.
✓ Branch 10 taken 528 times.
✓ Branch 11 taken 176 times.
✓ Branch 12 taken 640 times.
✓ Branch 13 taken 1992 times.
23532 if (row_or_column_index >= (height_ - 2U)) {
140 // Rows and columns have the same offsets.
141 6028 return offsets_with_right_border(row_or_column_index);
142 }
143 17504 return offsets_without_border();
144 29560 }
145
146 private:
147 // Takes care of static signed to unsigned casts.
148 173688 Offsets get(ptrdiff_t o0, ptrdiff_t o1, ptrdiff_t o2, ptrdiff_t o3,
149 ptrdiff_t o4) const KLEIDICV_STREAMING {
150 173688 return Offsets{o0, o1, o2, o3, o4};
151 }
152
153 size_t height_;
154 FixedBorderType border_type_;
155 }; // end of class FixedBorderInfo<T, 5UL>
156
157 // Shorthand for 5x5 filter border type.
158 template <typename T>
159 using FixedBorderInfo5x5 = FixedBorderInfo<T, 5UL>;
160
161 } // namespace KLEIDICV_TARGET_NAMESPACE
162
163 #endif // KLEIDICV_WORKSPACE_BORDER_5X5_H
164