| 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 <type_traits> | ||
| 6 | |||
| 7 | #include "kleidicv/kleidicv.h" | ||
| 8 | #include "kleidicv/neon.h" | ||
| 9 | |||
| 10 | namespace kleidicv::neon { | ||
| 11 | |||
| 12 | template <typename ScalarType> | ||
| 13 | class SaturatingAbsDiff final : public UnrollTwice { | ||
| 14 | public: | ||
| 15 | using VecTraits = neon::VecTraits<ScalarType>; | ||
| 16 | using VectorType = typename VecTraits::VectorType; | ||
| 17 | |||
| 18 | 4688 | VectorType vector_path(VectorType src_a, VectorType src_b) { | |
| 19 | if constexpr (std::numeric_limits<ScalarType>::is_signed) { | ||
| 20 | // Results of VABD may be outside the signed range so use two | ||
| 21 | // saturating instructions instead. | ||
| 22 | 3310 | return vqabsq(vqsubq(src_a, src_b)); | |
| 23 | } | ||
| 24 | 1378 | return vabdq(src_a, src_b); | |
| 25 | } | ||
| 26 | |||
| 27 | 1806 | ScalarType scalar_path(ScalarType src_a, ScalarType src_b) { | |
| 28 | using UnsignedScalarType = std::make_unsigned_t<ScalarType>; | ||
| 29 | // Calculate unsigned difference and then apply saturating cast. | ||
| 30 | 1806 | UnsignedScalarType u_src_a = static_cast<UnsignedScalarType>(src_a); | |
| 31 | 1806 | UnsignedScalarType u_src_b = static_cast<UnsignedScalarType>(src_b); | |
| 32 | 3612 | UnsignedScalarType difference = | |
| 33 |
10/10✓ Branch 0 taken 196 times.
✓ Branch 1 taken 370 times.
✓ Branch 2 taken 199 times.
✓ Branch 3 taken 479 times.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 120 times.
✓ Branch 6 taken 80 times.
✓ Branch 7 taken 166 times.
✓ Branch 8 taken 48 times.
✓ Branch 9 taken 70 times.
|
1806 | src_a > src_b ? u_src_a - u_src_b : u_src_b - u_src_a; |
| 34 | 3612 | return saturating_cast<UnsignedScalarType, ScalarType>(difference); | |
| 35 | 1806 | } | |
| 36 | }; // end of class SaturatingAbsDiff<ScalarType> | ||
| 37 | |||
| 38 | template <typename T> | ||
| 39 | 359 | kleidicv_error_t saturating_absdiff(const T *src_a, size_t src_a_stride, | |
| 40 | const T *src_b, size_t src_b_stride, T *dst, | ||
| 41 | size_t dst_stride, size_t width, | ||
| 42 | size_t height) { | ||
| 43 |
20/20✓ Branch 0 taken 1 times.
✓ Branch 1 taken 69 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 69 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 69 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 69 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 71 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 71 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 71 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 71 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 71 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 71 times.
|
359 | CHECK_POINTER_AND_STRIDE(src_a, src_a_stride, height); |
| 44 |
20/20✓ Branch 0 taken 1 times.
✓ Branch 1 taken 68 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 68 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 68 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 68 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 69 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 69 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 69 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 69 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 69 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 69 times.
|
351 | CHECK_POINTER_AND_STRIDE(src_b, src_b_stride, height); |
| 45 |
20/20✓ Branch 0 taken 1 times.
✓ Branch 1 taken 67 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 67 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 67 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 67 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 67 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 67 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 67 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 67 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 67 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 67 times.
|
343 | CHECK_POINTER_AND_STRIDE(dst, dst_stride, height); |
| 46 |
30/30✓ Branch 0 taken 1 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 65 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 65 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 66 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 65 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 65 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 66 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 65 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 65 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 66 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 65 times.
✓ Branch 22 taken 2 times.
✓ Branch 23 taken 65 times.
✓ Branch 24 taken 1 times.
✓ Branch 25 taken 66 times.
✓ Branch 26 taken 1 times.
✓ Branch 27 taken 65 times.
✓ Branch 28 taken 2 times.
✓ Branch 29 taken 65 times.
|
335 | CHECK_IMAGE_SIZE(width, height); |
| 47 | |||
| 48 | 325 | SaturatingAbsDiff<T> operation; | |
| 49 | 325 | Rectangle rect{width, height}; | |
| 50 | 325 | Rows<const T> src_a_rows{src_a, src_a_stride}; | |
| 51 | 325 | Rows<const T> src_b_rows{src_b, src_b_stride}; | |
| 52 | 325 | Rows<T> dst_rows{dst, dst_stride}; | |
| 53 | 325 | neon::apply_operation_by_rows(operation, rect, src_a_rows, src_b_rows, | |
| 54 | dst_rows); | ||
| 55 | 325 | return KLEIDICV_OK; | |
| 56 | 359 | } | |
| 57 | |||
| 58 | #define KLEIDICV_INSTANTIATE_TEMPLATE(type) \ | ||
| 59 | template KLEIDICV_TARGET_FN_ATTRS kleidicv_error_t saturating_absdiff<type>( \ | ||
| 60 | const type *src_a, size_t src_a_stride, const type *src_b, \ | ||
| 61 | size_t src_b_stride, type *dst, size_t dst_stride, size_t width, \ | ||
| 62 | size_t height) | ||
| 63 | |||
| 64 | KLEIDICV_INSTANTIATE_TEMPLATE(uint8_t); | ||
| 65 | KLEIDICV_INSTANTIATE_TEMPLATE(int8_t); | ||
| 66 | KLEIDICV_INSTANTIATE_TEMPLATE(uint16_t); | ||
| 67 | KLEIDICV_INSTANTIATE_TEMPLATE(int16_t); | ||
| 68 | KLEIDICV_INSTANTIATE_TEMPLATE(int32_t); | ||
| 69 | |||
| 70 | } // namespace kleidicv::neon | ||
| 71 |