| 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 | 115072 | Offsets(ptrdiff_t o0, ptrdiff_t o1, ptrdiff_t o2) : offsets_{o0, o1, o2} {} | |
| 27 | |||
| 28 | 419148 | ptrdiff_t c0() const { return offsets_[0]; } | |
| 29 | 419148 | ptrdiff_t c1() const { return offsets_[1]; } | |
| 30 | 529656 | ptrdiff_t c2() const { return offsets_[2]; } | |
| 31 | |||
| 32 | private: | ||
| 33 | ptrdiff_t offsets_[3]; | ||
| 34 | }; | ||
| 35 | |||
| 36 | 11184 | FixedBorderInfo(size_t height, FixedBorderType border_type) | |
| 37 | 11184 | : height_(height), border_type_(border_type) {} | |
| 38 | |||
| 39 | // Returns offsets without the influence of any border. | ||
| 40 | 55952 | Offsets offsets_without_border() const { return get(-1, 0, 1); } | |
| 41 | |||
| 42 | // Returns offsets for columns affected by left border. | ||
| 43 | 29560 | Offsets offsets_with_left_border(size_t /* column_index */) const | |
| 44 | KLEIDICV_STREAMING { | ||
| 45 |
21/28✓ Branch 0 taken 17264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 336 times.
✓ Branch 4 taken 2272 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 160 times.
✓ Branch 7 taken 160 times.
✓ Branch 8 taken 2272 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 160 times.
✓ Branch 11 taken 160 times.
✓ Branch 12 taken 2272 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 160 times.
✓ Branch 15 taken 160 times.
✓ Branch 16 taken 320 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 160 times.
✓ Branch 19 taken 160 times.
✓ Branch 20 taken 320 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 160 times.
✓ Branch 23 taken 160 times.
✓ Branch 24 taken 2272 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 160 times.
✓ Branch 27 taken 160 times.
|
29560 | switch (border_type_) { |
| 46 | case FixedBorderType::REPLICATE: | ||
| 47 | case FixedBorderType::REFLECT: | ||
| 48 | 26992 | return get(0, 0, 1); | |
| 49 | break; | ||
| 50 | |||
| 51 | case FixedBorderType::WRAP: | ||
| 52 | 1272 | return get(height_ - 1, 0, 1); | |
| 53 | break; | ||
| 54 | |||
| 55 | case FixedBorderType::REVERSE: | ||
| 56 | 1296 | 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 | 29560 | } | |
| 63 | |||
| 64 | // Returns offsets for columns affected by right border. | ||
| 65 | 29560 | Offsets offsets_with_right_border(size_t /* column_index */) const | |
| 66 | KLEIDICV_STREAMING { | ||
| 67 |
21/28✓ Branch 0 taken 17264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 336 times.
✓ Branch 4 taken 2272 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 160 times.
✓ Branch 7 taken 160 times.
✓ Branch 8 taken 2272 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 160 times.
✓ Branch 11 taken 160 times.
✓ Branch 12 taken 2272 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 160 times.
✓ Branch 15 taken 160 times.
✓ Branch 16 taken 320 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 160 times.
✓ Branch 19 taken 160 times.
✓ Branch 20 taken 320 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 160 times.
✓ Branch 23 taken 160 times.
✓ Branch 24 taken 2272 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 160 times.
✓ Branch 27 taken 160 times.
|
29560 | switch (border_type_) { |
| 68 | case FixedBorderType::REPLICATE: | ||
| 69 | case FixedBorderType::REFLECT: | ||
| 70 | 26992 | return get(-1, 0, 0); | |
| 71 | break; | ||
| 72 | |||
| 73 | case FixedBorderType::WRAP: | ||
| 74 | 1272 | return get(-1, 0, 1 - height_); | |
| 75 | break; | ||
| 76 | |||
| 77 | case FixedBorderType::REVERSE: | ||
| 78 | 1296 | 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 | 29560 | } | |
| 85 | |||
| 86 | // Returns offsets for rows or columns affected by any border. | ||
| 87 | 35584 | Offsets offsets_with_border(size_t row_or_column_index) const | |
| 88 | KLEIDICV_STREAMING { | ||
| 89 |
14/14✓ Branch 0 taken 16008 times.
✓ Branch 1 taken 1080 times.
✓ Branch 2 taken 3936 times.
✓ Branch 3 taken 368 times.
✓ Branch 4 taken 3936 times.
✓ Branch 5 taken 368 times.
✓ Branch 6 taken 3936 times.
✓ Branch 7 taken 368 times.
✓ Branch 8 taken 384 times.
✓ Branch 9 taken 256 times.
✓ Branch 10 taken 384 times.
✓ Branch 11 taken 256 times.
✓ Branch 12 taken 3936 times.
✓ Branch 13 taken 368 times.
|
35584 | if (row_or_column_index == 0U) { |
| 90 | // Rows and columns have the same offsets. | ||
| 91 | 3064 | return offsets_with_left_border(row_or_column_index); | |
| 92 | } | ||
| 93 |
14/14✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 14928 times.
✓ Branch 2 taken 368 times.
✓ Branch 3 taken 3568 times.
✓ Branch 4 taken 368 times.
✓ Branch 5 taken 3568 times.
✓ Branch 6 taken 368 times.
✓ Branch 7 taken 3568 times.
✓ Branch 8 taken 256 times.
✓ Branch 9 taken 128 times.
✓ Branch 10 taken 256 times.
✓ Branch 11 taken 128 times.
✓ Branch 12 taken 368 times.
✓ Branch 13 taken 3568 times.
|
32520 | if (row_or_column_index == (height_ - 1U)) { |
| 94 | // Rows and columns have the same offsets. | ||
| 95 | 3064 | return offsets_with_right_border(row_or_column_index); | |
| 96 | } | ||
| 97 | 29456 | return offsets_without_border(); | |
| 98 | 35584 | } | |
| 99 | |||
| 100 | private: | ||
| 101 | // Takes care of static signed to unsigned casts. | ||
| 102 | 115072 | Offsets get(ptrdiff_t o0, ptrdiff_t o1, ptrdiff_t o2) const { | |
| 103 | 115072 | 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 |