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