| 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_WORKSPACE_BORDER_7X7_H | ||
| 6 | #define KLEIDICV_WORKSPACE_BORDER_7X7_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 7x7 filters. | ||
| 18 | template <typename T> | ||
| 19 | class FixedBorderInfo<T, 7UL> 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 | 145536 | Offsets(ptrdiff_t o0, ptrdiff_t o1, ptrdiff_t o2, ptrdiff_t o3, | |
| 29 | ptrdiff_t o4, ptrdiff_t o5, ptrdiff_t o6) | ||
| 30 | 145536 | : offsets_{o0, o1, o2, o3, o4, o5, o6} {} | |
| 31 | |||
| 32 | 3457052 | ptrdiff_t c0() const { return offsets_[0]; } | |
| 33 | 3457052 | ptrdiff_t c1() const { return offsets_[1]; } | |
| 34 | 3457052 | ptrdiff_t c2() const { return offsets_[2]; } | |
| 35 | 3457052 | ptrdiff_t c3() const { return offsets_[3]; } | |
| 36 | 3457052 | ptrdiff_t c4() const { return offsets_[4]; } | |
| 37 | 3457052 | ptrdiff_t c5() const { return offsets_[5]; } | |
| 38 | 3457052 | ptrdiff_t c6() const { return offsets_[6]; } | |
| 39 | |||
| 40 | private: | ||
| 41 | ptrdiff_t offsets_[7]; | ||
| 42 | }; | ||
| 43 | |||
| 44 | 4336 | FixedBorderInfo(size_t height, FixedBorderType border_type) | |
| 45 | 4336 | : height_(height), border_type_(border_type) {} | |
| 46 | |||
| 47 | // Returns offsets without the influence of any border. | ||
| 48 | 23664 | Offsets offsets_without_border() const KLEIDICV_STREAMING { | |
| 49 | 23664 | return get(-3, -2, -1, 0, 1, 2, 3); | |
| 50 | } | ||
| 51 | |||
| 52 | // Returns offsets for columns affected by left border. | ||
| 53 | 60936 | Offsets offsets_with_left_border(size_t column_index) const | |
| 54 | KLEIDICV_STREAMING { | ||
| 55 |
28/35✗ Branch 0 not taken.
✓ Branch 1 taken 2472 times.
✓ Branch 2 taken 2472 times.
✓ Branch 3 taken 2472 times.
✓ Branch 4 taken 2640 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5520 times.
✓ Branch 7 taken 1440 times.
✓ Branch 8 taken 1440 times.
✓ Branch 9 taken 1440 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 5520 times.
✓ Branch 12 taken 1440 times.
✓ Branch 13 taken 1440 times.
✓ Branch 14 taken 1440 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5520 times.
✓ Branch 17 taken 1440 times.
✓ Branch 18 taken 1440 times.
✓ Branch 19 taken 1440 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1440 times.
✓ Branch 22 taken 1440 times.
✓ Branch 23 taken 1440 times.
✓ Branch 24 taken 1440 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 1440 times.
✓ Branch 27 taken 1440 times.
✓ Branch 28 taken 1440 times.
✓ Branch 29 taken 1440 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 5520 times.
✓ Branch 32 taken 1440 times.
✓ Branch 33 taken 1440 times.
✓ Branch 34 taken 1440 times.
|
60936 | switch (border_type_) { |
| 56 | case FixedBorderType::REPLICATE: | ||
| 57 |
14/14✓ Branch 0 taken 1648 times.
✓ Branch 1 taken 824 times.
✓ Branch 2 taken 3680 times.
✓ Branch 3 taken 1840 times.
✓ Branch 4 taken 3680 times.
✓ Branch 5 taken 1840 times.
✓ Branch 6 taken 3680 times.
✓ Branch 7 taken 1840 times.
✓ Branch 8 taken 960 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 960 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 3680 times.
✓ Branch 13 taken 1840 times.
|
27432 | if (column_index == 0) { |
| 58 | 9144 | return get(0, 0, 0, 0, 1, 2, 3); | |
| 59 |
14/14✓ Branch 0 taken 824 times.
✓ Branch 1 taken 824 times.
✓ Branch 2 taken 1840 times.
✓ Branch 3 taken 1840 times.
✓ Branch 4 taken 1840 times.
✓ Branch 5 taken 1840 times.
✓ Branch 6 taken 1840 times.
✓ Branch 7 taken 1840 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 1840 times.
✓ Branch 13 taken 1840 times.
|
18288 | } else if (column_index == 1) { |
| 60 | 9144 | return get(-1, -1, -1, 0, 1, 2, 3); | |
| 61 | } else { | ||
| 62 | 9144 | return get(-2, -2, -1, 0, 1, 2, 3); | |
| 63 | } | ||
| 64 | break; | ||
| 65 | |||
| 66 | case FixedBorderType::REFLECT: | ||
| 67 |
14/14✓ Branch 0 taken 1648 times.
✓ Branch 1 taken 824 times.
✓ Branch 2 taken 960 times.
✓ Branch 3 taken 480 times.
✓ Branch 4 taken 960 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 960 times.
✓ Branch 7 taken 480 times.
✓ Branch 8 taken 960 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 960 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 960 times.
✓ Branch 13 taken 480 times.
|
11112 | if (column_index == 0) { |
| 68 | 3704 | return get(2, 1, 0, 0, 1, 2, 3); | |
| 69 |
14/14✓ Branch 0 taken 824 times.
✓ Branch 1 taken 824 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 480 times.
✓ Branch 4 taken 480 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 480 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 480 times.
✓ Branch 13 taken 480 times.
|
7408 | } else if (column_index == 1) { |
| 70 | 3704 | return get(0, -1, -1, 0, 1, 2, 3); | |
| 71 | } else { | ||
| 72 | 3704 | return get(-2, -2, -1, 0, 1, 2, 3); | |
| 73 | } | ||
| 74 | break; | ||
| 75 | |||
| 76 | case FixedBorderType::WRAP: | ||
| 77 |
14/14✓ Branch 0 taken 1648 times.
✓ Branch 1 taken 824 times.
✓ Branch 2 taken 960 times.
✓ Branch 3 taken 480 times.
✓ Branch 4 taken 960 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 960 times.
✓ Branch 7 taken 480 times.
✓ Branch 8 taken 960 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 960 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 960 times.
✓ Branch 13 taken 480 times.
|
11112 | if (column_index == 0) { |
| 78 | 3704 | return get(height_ - 3, height_ - 2, height_ - 1, 0, 1, 2, 3); | |
| 79 |
14/14✓ Branch 0 taken 824 times.
✓ Branch 1 taken 824 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 480 times.
✓ Branch 4 taken 480 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 480 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 480 times.
✓ Branch 13 taken 480 times.
|
7408 | } else if (column_index == 1) { |
| 80 | 3704 | return get(height_ - 3, height_ - 2, -1, 0, 1, 2, 3); | |
| 81 | } else { | ||
| 82 | 3704 | return get(height_ - 3, -2, -1, 0, 1, 2, 3); | |
| 83 | } | ||
| 84 | break; | ||
| 85 | |||
| 86 | case FixedBorderType::REVERSE: | ||
| 87 |
14/14✓ Branch 0 taken 1760 times.
✓ Branch 1 taken 880 times.
✓ Branch 2 taken 960 times.
✓ Branch 3 taken 480 times.
✓ Branch 4 taken 960 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 960 times.
✓ Branch 7 taken 480 times.
✓ Branch 8 taken 960 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 960 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 960 times.
✓ Branch 13 taken 480 times.
|
11280 | if (column_index == 0) { |
| 88 | 3760 | return get(3, 2, 1, 0, 1, 2, 3); | |
| 89 |
14/14✓ Branch 0 taken 880 times.
✓ Branch 1 taken 880 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 480 times.
✓ Branch 4 taken 480 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 480 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 480 times.
✓ Branch 13 taken 480 times.
|
7520 | } else if (column_index == 1) { |
| 90 | 3760 | return get(1, 0, -1, 0, 1, 2, 3); | |
| 91 | } else { | ||
| 92 | 3760 | return get(-1, -2, -1, 0, 1, 2, 3); | |
| 93 | } | ||
| 94 | break; | ||
| 95 | } | ||
| 96 | // Unreachable. Compiler should emit a warning-as-error if any cases are | ||
| 97 | // uncovered above. | ||
| 98 | − | return Offsets{}; // GCOVR_EXCL_LINE | |
| 99 | 60936 | } | |
| 100 | |||
| 101 | // Returns offsets for columns affected by right border. | ||
| 102 | 60936 | Offsets offsets_with_right_border(size_t column_index) const | |
| 103 | KLEIDICV_STREAMING { | ||
| 104 |
28/35✗ Branch 0 not taken.
✓ Branch 1 taken 2472 times.
✓ Branch 2 taken 2472 times.
✓ Branch 3 taken 2472 times.
✓ Branch 4 taken 2640 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5520 times.
✓ Branch 7 taken 1440 times.
✓ Branch 8 taken 1440 times.
✓ Branch 9 taken 1440 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 5520 times.
✓ Branch 12 taken 1440 times.
✓ Branch 13 taken 1440 times.
✓ Branch 14 taken 1440 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5520 times.
✓ Branch 17 taken 1440 times.
✓ Branch 18 taken 1440 times.
✓ Branch 19 taken 1440 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1440 times.
✓ Branch 22 taken 1440 times.
✓ Branch 23 taken 1440 times.
✓ Branch 24 taken 1440 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 1440 times.
✓ Branch 27 taken 1440 times.
✓ Branch 28 taken 1440 times.
✓ Branch 29 taken 1440 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 5520 times.
✓ Branch 32 taken 1440 times.
✓ Branch 33 taken 1440 times.
✓ Branch 34 taken 1440 times.
|
60936 | switch (border_type_) { |
| 105 | case FixedBorderType::REPLICATE: | ||
| 106 |
14/14✓ Branch 0 taken 824 times.
✓ Branch 1 taken 1648 times.
✓ Branch 2 taken 1840 times.
✓ Branch 3 taken 3680 times.
✓ Branch 4 taken 1840 times.
✓ Branch 5 taken 3680 times.
✓ Branch 6 taken 1840 times.
✓ Branch 7 taken 3680 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 960 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 960 times.
✓ Branch 12 taken 1840 times.
✓ Branch 13 taken 3680 times.
|
27432 | if (column_index == (height_ - 3)) { |
| 107 | 9144 | return get(-3, -2, -1, 0, 1, 2, 2); | |
| 108 |
14/14✓ Branch 0 taken 824 times.
✓ Branch 1 taken 824 times.
✓ Branch 2 taken 1840 times.
✓ Branch 3 taken 1840 times.
✓ Branch 4 taken 1840 times.
✓ Branch 5 taken 1840 times.
✓ Branch 6 taken 1840 times.
✓ Branch 7 taken 1840 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 1840 times.
✓ Branch 13 taken 1840 times.
|
18288 | } else if (column_index == (height_ - 2)) { |
| 109 | 9144 | return get(-3, -2, -1, 0, 1, 1, 1); | |
| 110 | } else { | ||
| 111 | 9144 | return get(-3, -2, -1, 0, 0, 0, 0); | |
| 112 | } | ||
| 113 | break; | ||
| 114 | |||
| 115 | case FixedBorderType::REFLECT: | ||
| 116 |
14/14✓ Branch 0 taken 824 times.
✓ Branch 1 taken 1648 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 960 times.
✓ Branch 4 taken 480 times.
✓ Branch 5 taken 960 times.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 960 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 960 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 960 times.
✓ Branch 12 taken 480 times.
✓ Branch 13 taken 960 times.
|
11112 | if (column_index == (height_ - 3)) { |
| 117 | 3704 | return get(-3, -2, -1, 0, 1, 2, 2); | |
| 118 |
14/14✓ Branch 0 taken 824 times.
✓ Branch 1 taken 824 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 480 times.
✓ Branch 4 taken 480 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 480 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 480 times.
✓ Branch 13 taken 480 times.
|
7408 | } else if (column_index == (height_ - 2)) { |
| 119 | 3704 | return get(-3, -2, -1, 0, 1, 1, 0); | |
| 120 | } else { | ||
| 121 | 3704 | return get(-3, -2, -1, 0, 0, -1, -2); | |
| 122 | } | ||
| 123 | break; | ||
| 124 | |||
| 125 | case FixedBorderType::WRAP: | ||
| 126 |
14/14✓ Branch 0 taken 824 times.
✓ Branch 1 taken 1648 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 960 times.
✓ Branch 4 taken 480 times.
✓ Branch 5 taken 960 times.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 960 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 960 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 960 times.
✓ Branch 12 taken 480 times.
✓ Branch 13 taken 960 times.
|
11112 | if (column_index == (height_ - 3)) { |
| 127 | 3704 | return get(-3, -2, -1, 0, 1, 2, 3 - height_); | |
| 128 |
14/14✓ Branch 0 taken 824 times.
✓ Branch 1 taken 824 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 480 times.
✓ Branch 4 taken 480 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 480 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 480 times.
✓ Branch 13 taken 480 times.
|
7408 | } else if (column_index == (height_ - 2)) { |
| 129 | 3704 | return get(-3, -2, -1, 0, 1, 2 - height_, 3 - height_); | |
| 130 | } else { | ||
| 131 | 3704 | return get(-3, -2, -1, 0, 1 - height_, 2 - height_, 3 - height_); | |
| 132 | } | ||
| 133 | break; | ||
| 134 | |||
| 135 | case FixedBorderType::REVERSE: | ||
| 136 |
14/14✓ Branch 0 taken 880 times.
✓ Branch 1 taken 1760 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 960 times.
✓ Branch 4 taken 480 times.
✓ Branch 5 taken 960 times.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 960 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 960 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 960 times.
✓ Branch 12 taken 480 times.
✓ Branch 13 taken 960 times.
|
11280 | if (column_index == (height_ - 3)) { |
| 137 | 3760 | return get(-3, -2, -1, 0, 1, 2, 1); | |
| 138 |
14/14✓ Branch 0 taken 880 times.
✓ Branch 1 taken 880 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 480 times.
✓ Branch 4 taken 480 times.
✓ Branch 5 taken 480 times.
✓ Branch 6 taken 480 times.
✓ Branch 7 taken 480 times.
✓ Branch 8 taken 480 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 480 times.
✓ Branch 11 taken 480 times.
✓ Branch 12 taken 480 times.
✓ Branch 13 taken 480 times.
|
7520 | } else if (column_index == (height_ - 2)) { |
| 139 | 3760 | return get(-3, -2, -1, 0, 1, 0, -1); | |
| 140 | } else { | ||
| 141 | 3760 | return get(-3, -2, -1, 0, -1, -2, -3); | |
| 142 | } | ||
| 143 | break; | ||
| 144 | } | ||
| 145 | // Unreachable. Compiler should emit a warning-as-error if any cases are | ||
| 146 | // uncovered above. | ||
| 147 | − | return Offsets{}; // GCOVR_EXCL_LINE | |
| 148 | 60936 | } | |
| 149 | |||
| 150 | // Returns offsets for rows or columns affected by any border. | ||
| 151 | 18192 | Offsets offsets_with_border(size_t row_or_column_index) const | |
| 152 | KLEIDICV_STREAMING { | ||
| 153 |
14/14✓ Branch 0 taken 1368 times.
✓ Branch 1 taken 1528 times.
✓ Branch 2 taken 864 times.
✓ Branch 3 taken 2128 times.
✓ Branch 4 taken 864 times.
✓ Branch 5 taken 2128 times.
✓ Branch 6 taken 864 times.
✓ Branch 7 taken 2128 times.
✓ Branch 8 taken 768 times.
✓ Branch 9 taken 896 times.
✓ Branch 10 taken 768 times.
✓ Branch 11 taken 896 times.
✓ Branch 12 taken 864 times.
✓ Branch 13 taken 2128 times.
|
18192 | if (row_or_column_index <= 2U) { |
| 154 | // Rows and columns have the same offsets. | ||
| 155 | 6360 | return offsets_with_left_border(row_or_column_index); | |
| 156 | } | ||
| 157 |
14/14✓ Branch 0 taken 1368 times.
✓ Branch 1 taken 160 times.
✓ Branch 2 taken 864 times.
✓ Branch 3 taken 1264 times.
✓ Branch 4 taken 864 times.
✓ Branch 5 taken 1264 times.
✓ Branch 6 taken 864 times.
✓ Branch 7 taken 1264 times.
✓ Branch 8 taken 768 times.
✓ Branch 9 taken 128 times.
✓ Branch 10 taken 768 times.
✓ Branch 11 taken 128 times.
✓ Branch 12 taken 864 times.
✓ Branch 13 taken 1264 times.
|
11832 | if (row_or_column_index >= (height_ - 3U)) { |
| 158 | // Rows and columns have the same offsets. | ||
| 159 | 6360 | return offsets_with_right_border(row_or_column_index); | |
| 160 | } | ||
| 161 | 5472 | return offsets_without_border(); | |
| 162 | 18192 | } | |
| 163 | |||
| 164 | private: | ||
| 165 | // Takes care of static signed to unsigned casts. | ||
| 166 | 145536 | Offsets get(ptrdiff_t o0, ptrdiff_t o1, ptrdiff_t o2, ptrdiff_t o3, | |
| 167 | ptrdiff_t o4, ptrdiff_t o5, | ||
| 168 | ptrdiff_t o6) const KLEIDICV_STREAMING { | ||
| 169 | 145536 | return Offsets{o0, o1, o2, o3, o4, o5, o6}; | |
| 170 | } | ||
| 171 | |||
| 172 | size_t height_; | ||
| 173 | FixedBorderType border_type_; | ||
| 174 | }; // end of class FixedBorderInfo<T, 7UL> | ||
| 175 | |||
| 176 | // Shorthand for 7x7 filter border type. | ||
| 177 | template <typename T> | ||
| 178 | using FixedBorderInfo7x7 = FixedBorderInfo<T, 7UL>; | ||
| 179 | |||
| 180 | } // namespace KLEIDICV_TARGET_NAMESPACE | ||
| 181 | |||
| 182 | #endif // KLEIDICV_WORKSPACE_BORDER_7X7_H | ||
| 183 |