KleidiCV Coverage Report


Directory: ./
File: kleidicv/include/kleidicv/workspace/border_3x3.h
Date: 2025-09-25 14:13:34
Exec Total Coverage
Lines: 28 28 100.0%
Functions: 210 210 100.0%
Branches: 70 84 83.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_3X3_H
6 #define KLEIDICV_WORKSPACE_BORDER_3X3_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 3x3 filters.
18 template <typename T>
19 class FixedBorderInfo<T, 3UL> final {
20 public:
21 // Simple object holding read-only constant offsets.
22 class Offsets final {
23 public:
24 Offsets() = default;
25
26 85728 Offsets(ptrdiff_t o0, ptrdiff_t o1, ptrdiff_t o2) : offsets_{o0, o1, o2} {}
27
28 333078 ptrdiff_t c0() const { return offsets_[0]; }
29 333078 ptrdiff_t c1() const { return offsets_[1]; }
30 420594 ptrdiff_t c2() const { return offsets_[2]; }
31
32 private:
33 ptrdiff_t offsets_[3];
34 };
35
36 8388 FixedBorderInfo(size_t height, FixedBorderType border_type)
37 8388 : height_(height), border_type_(border_type) {}
38
39 // Returns offsets without the influence of any border.
40 41676 Offsets offsets_without_border() const { return get(-1, 0, 1); }
41
42 // Returns offsets for columns affected by left border.
43 22026 Offsets offsets_with_left_border(size_t /* column_index */) const
44 KLEIDICV_STREAMING {
45
21/28
✓ Branch 0 taken 12804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 234 times.
✓ Branch 3 taken 252 times.
✓ Branch 4 taken 1704 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 120 times.
✓ Branch 7 taken 120 times.
✓ Branch 8 taken 1704 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 120 times.
✓ Branch 11 taken 120 times.
✓ Branch 12 taken 1704 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 120 times.
✓ Branch 15 taken 120 times.
✓ Branch 16 taken 240 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 120 times.
✓ Branch 19 taken 120 times.
✓ Branch 20 taken 240 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 120 times.
✓ Branch 23 taken 120 times.
✓ Branch 24 taken 1704 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 120 times.
✓ Branch 27 taken 120 times.
22026 switch (border_type_) {
46 case FixedBorderType::REPLICATE:
47 case FixedBorderType::REFLECT:
48 20100 return get(0, 0, 1);
49 break;
50
51 case FixedBorderType::WRAP:
52 954 return get(height_ - 1, 0, 1);
53 break;
54
55 case FixedBorderType::REVERSE:
56 972 return get(1, 0, 1);
57 break;
58 }
59 // Unreachable. Compiler should emit a warning-as-error if any cases are
60 // uncovered above.
61 return Offsets{}; // GCOVR_EXCL_LINE
62 22026 }
63
64 // Returns offsets for columns affected by right border.
65 22026 Offsets offsets_with_right_border(size_t /* column_index */) const
66 KLEIDICV_STREAMING {
67
21/28
✓ Branch 0 taken 12804 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 234 times.
✓ Branch 3 taken 252 times.
✓ Branch 4 taken 1704 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 120 times.
✓ Branch 7 taken 120 times.
✓ Branch 8 taken 1704 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 120 times.
✓ Branch 11 taken 120 times.
✓ Branch 12 taken 1704 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 120 times.
✓ Branch 15 taken 120 times.
✓ Branch 16 taken 240 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 120 times.
✓ Branch 19 taken 120 times.
✓ Branch 20 taken 240 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 120 times.
✓ Branch 23 taken 120 times.
✓ Branch 24 taken 1704 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 120 times.
✓ Branch 27 taken 120 times.
22026 switch (border_type_) {
68 case FixedBorderType::REPLICATE:
69 case FixedBorderType::REFLECT:
70 20100 return get(-1, 0, 0);
71 break;
72
73 case FixedBorderType::WRAP:
74 954 return get(-1, 0, 1 - height_);
75 break;
76
77 case FixedBorderType::REVERSE:
78 972 return get(-1, 0, -1);
79 break;
80 }
81 // Unreachable. Compiler should emit a warning-as-error if any cases are
82 // uncovered above.
83 return Offsets{}; // GCOVR_EXCL_LINE
84 22026 }
85
86 // Returns offsets for rows or columns affected by any border.
87 26544 Offsets offsets_with_border(size_t row_or_column_index) const
88 KLEIDICV_STREAMING {
89
14/14
✓ Branch 0 taken 11862 times.
✓ Branch 1 taken 810 times.
✓ Branch 2 taken 2952 times.
✓ Branch 3 taken 276 times.
✓ Branch 4 taken 2952 times.
✓ Branch 5 taken 276 times.
✓ Branch 6 taken 2952 times.
✓ Branch 7 taken 276 times.
✓ Branch 8 taken 288 times.
✓ Branch 9 taken 192 times.
✓ Branch 10 taken 288 times.
✓ Branch 11 taken 192 times.
✓ Branch 12 taken 2952 times.
✓ Branch 13 taken 276 times.
26544 if (row_or_column_index == 0U) {
90 // Rows and columns have the same offsets.
91 2298 return offsets_with_left_border(row_or_column_index);
92 }
93
14/14
✓ Branch 0 taken 810 times.
✓ Branch 1 taken 11052 times.
✓ Branch 2 taken 276 times.
✓ Branch 3 taken 2676 times.
✓ Branch 4 taken 276 times.
✓ Branch 5 taken 2676 times.
✓ Branch 6 taken 276 times.
✓ Branch 7 taken 2676 times.
✓ Branch 8 taken 192 times.
✓ Branch 9 taken 96 times.
✓ Branch 10 taken 192 times.
✓ Branch 11 taken 96 times.
✓ Branch 12 taken 276 times.
✓ Branch 13 taken 2676 times.
24246 if (row_or_column_index == (height_ - 1U)) {
94 // Rows and columns have the same offsets.
95 2298 return offsets_with_right_border(row_or_column_index);
96 }
97 21948 return offsets_without_border();
98 26544 }
99
100 private:
101 // Takes care of static signed to unsigned casts.
102 85728 Offsets get(ptrdiff_t o0, ptrdiff_t o1, ptrdiff_t o2) const {
103 85728 return Offsets{o0, o1, o2};
104 }
105
106 size_t height_;
107 FixedBorderType border_type_;
108 }; // end of class FixedBorderInfo<T, 3UL>
109
110 // Shorthand for 3x3 filter border type.
111 template <typename T>
112 using FixedBorderInfo3x3 = FixedBorderInfo<T, 3UL>;
113
114 } // namespace KLEIDICV_TARGET_NAMESPACE
115
116 #endif // KLEIDICV_WORKSPACE_BORDER_3X3_H
117