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 | #include "kleidicv/kleidicv.h" | ||
6 | #include "kleidicv/sve2.h" | ||
7 | |||
8 | namespace kleidicv::sme { | ||
9 | |||
10 | template <typename ScalarType, typename VectorType, | ||
11 | std::enable_if_t<std::is_signed<ScalarType>::value, bool> = true> | ||
12 | 1146 | VectorType vector_path_impl(svbool_t pg, VectorType src_a, | |
13 | VectorType src_b) KLEIDICV_STREAMING { | ||
14 | // Results of SABD may be outside the signed range so use two | ||
15 | // saturating instructions instead. | ||
16 | 1146 | return svqabs_x(pg, svqsub_m(pg, src_a, src_b)); | |
17 | } | ||
18 | |||
19 | template <typename ScalarType, typename VectorType, | ||
20 | std::enable_if_t<std::is_unsigned<ScalarType>::value, bool> = true> | ||
21 | 489 | VectorType vector_path_impl(svbool_t pg, VectorType src_a, | |
22 | VectorType src_b) KLEIDICV_STREAMING { | ||
23 | 489 | return svabd_m(pg, src_a, src_b); | |
24 | } | ||
25 | |||
26 | template <typename ScalarType> | ||
27 | class SaturatingAbsDiff final : public UnrollTwice { | ||
28 | public: | ||
29 | using ContextType = Context; | ||
30 | using VecTraits = KLEIDICV_TARGET_NAMESPACE::VecTraits<ScalarType>; | ||
31 | using VectorType = typename VecTraits::VectorType; | ||
32 | |||
33 | 1635 | VectorType vector_path(ContextType ctx, VectorType src_a, | |
34 | VectorType src_b) KLEIDICV_STREAMING { | ||
35 | 1635 | return vector_path_impl<ScalarType>(ctx.predicate(), src_a, src_b); | |
36 | } | ||
37 | }; // end of class SaturatingAbsDiff<ScalarType> | ||
38 | |||
39 | template <typename T> | ||
40 | 359 | KLEIDICV_LOCALLY_STREAMING kleidicv_error_t saturating_absdiff( | |
41 | const T *src_a, size_t src_a_stride, const T *src_b, size_t src_b_stride, | ||
42 | T *dst, size_t dst_stride, size_t width, 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 | apply_operation_by_rows(operation, rect, src_a_rows, src_b_rows, dst_rows); | |
54 | 325 | return KLEIDICV_OK; | |
55 | 359 | } | |
56 | |||
57 | #define KLEIDICV_INSTANTIATE_TEMPLATE(type) \ | ||
58 | template KLEIDICV_TARGET_FN_ATTRS kleidicv_error_t saturating_absdiff<type>( \ | ||
59 | const type *src_a, size_t src_a_stride, const type *src_b, \ | ||
60 | size_t src_b_stride, type *dst, size_t dst_stride, size_t width, \ | ||
61 | size_t height) | ||
62 | |||
63 | KLEIDICV_INSTANTIATE_TEMPLATE(uint8_t); | ||
64 | KLEIDICV_INSTANTIATE_TEMPLATE(int8_t); | ||
65 | KLEIDICV_INSTANTIATE_TEMPLATE(uint16_t); | ||
66 | KLEIDICV_INSTANTIATE_TEMPLATE(int16_t); | ||
67 | KLEIDICV_INSTANTIATE_TEMPLATE(int32_t); | ||
68 | |||
69 | } // namespace kleidicv::sme | ||
70 |