| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2023 - 2024 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: Apache-2.0 | ||
| 4 | |||
| 5 | #include <limits> | ||
| 6 | |||
| 7 | #include "kleidicv/kleidicv.h" | ||
| 8 | #include "kleidicv/neon.h" | ||
| 9 | |||
| 10 | namespace kleidicv::neon { | ||
| 11 | |||
| 12 | template <typename ScalarType> | ||
| 13 | class MinMax final : public UnrollTwice { | ||
| 14 | public: | ||
| 15 | using VecTraits = neon::VecTraits<ScalarType>; | ||
| 16 | using VectorType = typename VecTraits::VectorType; | ||
| 17 | |||
| 18 | 890 | MinMax() | |
| 19 | 890 | : vmin_(vdupq_n(std::numeric_limits<ScalarType>::max())), | |
| 20 | 890 | vmax_(vdupq_n(std::numeric_limits<ScalarType>::lowest())), | |
| 21 | 890 | min_(std::numeric_limits<ScalarType>::max()), | |
| 22 | 890 | max_(std::numeric_limits<ScalarType>::lowest()) {} | |
| 23 | |||
| 24 | 3696 | void vector_path(VectorType src) { | |
| 25 | 3696 | vmin_ = vminq(vmin_, src); | |
| 26 | 3696 | vmax_ = vmaxq(vmax_, src); | |
| 27 | 3696 | } | |
| 28 | |||
| 29 | 12848 | void scalar_path(ScalarType src) { | |
| 30 | 12848 | min_ = std::min(min_, src); | |
| 31 | 12848 | max_ = std::max(max_, src); | |
| 32 | 12848 | } | |
| 33 | |||
| 34 | 518 | ScalarType get_min() const { | |
| 35 | 518 | return std::min<ScalarType>(min_, vminvq(vmin_)); | |
| 36 | } | ||
| 37 | |||
| 38 | 518 | ScalarType get_max() const { | |
| 39 | 518 | return std::max<ScalarType>(max_, vmaxvq(vmax_)); | |
| 40 | } | ||
| 41 | |||
| 42 | private: | ||
| 43 | VectorType vmin_, vmax_; | ||
| 44 | ScalarType min_, max_; | ||
| 45 | }; // end of class MinMax<T> | ||
| 46 | |||
| 47 | template <typename ScalarType> | ||
| 48 | 1098 | kleidicv_error_t min_max(const ScalarType *src, size_t src_stride, size_t width, | |
| 49 | size_t height, ScalarType *min_value, | ||
| 50 | ScalarType *max_value) { | ||
| 51 |
24/24✓ Branch 0 taken 30 times.
✓ Branch 1 taken 152 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 152 times.
✓ Branch 4 taken 30 times.
✓ Branch 5 taken 152 times.
✓ Branch 6 taken 30 times.
✓ Branch 7 taken 152 times.
✓ Branch 8 taken 31 times.
✓ Branch 9 taken 152 times.
✓ Branch 10 taken 31 times.
✓ Branch 11 taken 152 times.
✓ Branch 12 taken 31 times.
✓ Branch 13 taken 152 times.
✓ Branch 14 taken 31 times.
✓ Branch 15 taken 152 times.
✓ Branch 16 taken 31 times.
✓ Branch 17 taken 152 times.
✓ Branch 18 taken 31 times.
✓ Branch 19 taken 152 times.
✓ Branch 20 taken 31 times.
✓ Branch 21 taken 154 times.
✓ Branch 22 taken 31 times.
✓ Branch 23 taken 154 times.
|
1098 | CHECK_POINTER_AND_STRIDE(src, src_stride, height); |
| 52 |
36/36✓ Branch 0 taken 1 times.
✓ Branch 1 taken 151 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 150 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 150 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 151 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 150 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 150 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 151 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 150 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 150 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 151 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 150 times.
✓ Branch 22 taken 2 times.
✓ Branch 23 taken 150 times.
✓ Branch 24 taken 1 times.
✓ Branch 25 taken 151 times.
✓ Branch 26 taken 1 times.
✓ Branch 27 taken 150 times.
✓ Branch 28 taken 2 times.
✓ Branch 29 taken 150 times.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 153 times.
✓ Branch 32 taken 1 times.
✓ Branch 33 taken 152 times.
✓ Branch 34 taken 2 times.
✓ Branch 35 taken 152 times.
|
914 | CHECK_IMAGE_SIZE(width, height); |
| 53 | |||
| 54 |
24/24✓ Branch 0 taken 1 times.
✓ Branch 1 taken 149 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 148 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 149 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 148 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 149 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 148 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 149 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 148 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 149 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 148 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 151 times.
✓ Branch 22 taken 2 times.
✓ Branch 23 taken 150 times.
|
902 | if (KLEIDICV_UNLIKELY(width == 0 || height == 0)) { |
| 55 | 12 | return KLEIDICV_ERROR_RANGE; | |
| 56 | } | ||
| 57 | |||
| 58 | 890 | Rectangle rect{width, height}; | |
| 59 | 890 | Rows<const ScalarType> src_rows{src, src_stride}; | |
| 60 | 890 | MinMax<ScalarType> operation; | |
| 61 | 890 | apply_operation_by_rows(operation, rect, src_rows); | |
| 62 |
12/12✓ Branch 0 taken 62 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 86 times.
✓ Branch 4 taken 62 times.
✓ Branch 5 taken 86 times.
✓ Branch 6 taken 62 times.
✓ Branch 7 taken 86 times.
✓ Branch 8 taken 62 times.
✓ Branch 9 taken 86 times.
✓ Branch 10 taken 62 times.
✓ Branch 11 taken 88 times.
|
890 | if (min_value) { |
| 63 | 518 | *min_value = operation.get_min(); | |
| 64 | 518 | } | |
| 65 |
12/12✓ Branch 0 taken 62 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 86 times.
✓ Branch 4 taken 62 times.
✓ Branch 5 taken 86 times.
✓ Branch 6 taken 62 times.
✓ Branch 7 taken 86 times.
✓ Branch 8 taken 62 times.
✓ Branch 9 taken 86 times.
✓ Branch 10 taken 62 times.
✓ Branch 11 taken 88 times.
|
890 | if (max_value) { |
| 66 | 518 | *max_value = operation.get_max(); | |
| 67 | 518 | } | |
| 68 | 890 | return KLEIDICV_OK; | |
| 69 | 1098 | } | |
| 70 | |||
| 71 | #define KLEIDICV_INSTANTIATE_TEMPLATE(type) \ | ||
| 72 | template KLEIDICV_TARGET_FN_ATTRS kleidicv_error_t min_max<type>( \ | ||
| 73 | const type *src, size_t src_stride, size_t width, size_t height, \ | ||
| 74 | type *min_value, type *max_value) | ||
| 75 | |||
| 76 | KLEIDICV_INSTANTIATE_TEMPLATE(int8_t); | ||
| 77 | KLEIDICV_INSTANTIATE_TEMPLATE(uint8_t); | ||
| 78 | KLEIDICV_INSTANTIATE_TEMPLATE(int16_t); | ||
| 79 | KLEIDICV_INSTANTIATE_TEMPLATE(uint16_t); | ||
| 80 | KLEIDICV_INSTANTIATE_TEMPLATE(int32_t); | ||
| 81 | KLEIDICV_INSTANTIATE_TEMPLATE(float); | ||
| 82 | |||
| 83 | } // namespace kleidicv::neon | ||
| 84 |