| 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 SaturatingSub final : public UnrollTwice { | ||
| 14 | public: | ||
| 15 | using VecTraits = neon::VecTraits<ScalarType>; | ||
| 16 | using VectorType = typename VecTraits::VectorType; | ||
| 17 | |||
| 18 | 14664 | VectorType vector_path(VectorType src_a, VectorType src_b) { | |
| 19 | 14664 | return vqsubq(src_a, src_b); | |
| 20 | } | ||
| 21 | |||
| 22 | 4728 | ScalarType scalar_path(ScalarType src_a, ScalarType src_b) { | |
| 23 |
8/8✓ Branch 0 taken 1523 times.
✓ Branch 1 taken 229 times.
✓ Branch 2 taken 680 times.
✓ Branch 3 taken 96 times.
✓ Branch 4 taken 274 times.
✓ Branch 5 taken 62 times.
✓ Branch 6 taken 80 times.
✓ Branch 7 taken 44 times.
|
2988 | if (std::numeric_limits<ScalarType>::is_signed && src_b < 0) { |
| 24 | 431 | ScalarType result; | |
| 25 |
8/8✓ Branch 0 taken 55 times.
✓ Branch 1 taken 174 times.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 62 times.
✓ Branch 4 taken 26 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 22 times.
✓ Branch 7 taken 22 times.
|
431 | return __builtin_sub_overflow(src_a, src_b, &result) |
| 26 | 137 | ? std::numeric_limits<ScalarType>::max() | |
| 27 | 294 | : result; | |
| 28 | 431 | } | |
| 29 | |||
| 30 | 4297 | ScalarType result; | |
| 31 |
16/16✓ Branch 0 taken 76 times.
✓ Branch 1 taken 1447 times.
✓ Branch 2 taken 234 times.
✓ Branch 3 taken 810 times.
✓ Branch 4 taken 42 times.
✓ Branch 5 taken 638 times.
✓ Branch 6 taken 68 times.
✓ Branch 7 taken 352 times.
✓ Branch 8 taken 32 times.
✓ Branch 9 taken 242 times.
✓ Branch 10 taken 36 times.
✓ Branch 11 taken 168 times.
✓ Branch 12 taken 30 times.
✓ Branch 13 taken 50 times.
✓ Branch 14 taken 18 times.
✓ Branch 15 taken 54 times.
|
4297 | return __builtin_sub_overflow(src_a, src_b, &result) |
| 32 | 536 | ? std::numeric_limits<ScalarType>::lowest() | |
| 33 | 3761 | : result; | |
| 34 | 4728 | } | |
| 35 | }; // end of class SaturatingSub<ScalarType> | ||
| 36 | |||
| 37 | template <typename T> | ||
| 38 | 642 | kleidicv_error_t saturating_sub(const T *src_a, size_t src_a_stride, | |
| 39 | const T *src_b, size_t src_b_stride, T *dst, | ||
| 40 | size_t dst_stride, size_t width, | ||
| 41 | size_t height) { | ||
| 42 |
32/32✓ Branch 0 taken 1 times.
✓ Branch 1 taken 77 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 77 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 77 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 77 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 79 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 79 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 79 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 79 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 79 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 79 times.
✓ Branch 20 taken 2 times.
✓ Branch 21 taken 79 times.
✓ Branch 22 taken 2 times.
✓ Branch 23 taken 79 times.
✓ Branch 24 taken 2 times.
✓ Branch 25 taken 79 times.
✓ Branch 26 taken 2 times.
✓ Branch 27 taken 79 times.
✓ Branch 28 taken 2 times.
✓ Branch 29 taken 79 times.
✓ Branch 30 taken 2 times.
✓ Branch 31 taken 79 times.
|
642 | CHECK_POINTER_AND_STRIDE(src_a, src_a_stride, height); |
| 43 |
32/32✓ Branch 0 taken 1 times.
✓ Branch 1 taken 76 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 76 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 76 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 76 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 77 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 77 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 77 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 77 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 77 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 77 times.
✓ Branch 20 taken 2 times.
✓ Branch 21 taken 77 times.
✓ Branch 22 taken 2 times.
✓ Branch 23 taken 77 times.
✓ Branch 24 taken 2 times.
✓ Branch 25 taken 77 times.
✓ Branch 26 taken 2 times.
✓ Branch 27 taken 77 times.
✓ Branch 28 taken 2 times.
✓ Branch 29 taken 77 times.
✓ Branch 30 taken 2 times.
✓ Branch 31 taken 77 times.
|
628 | CHECK_POINTER_AND_STRIDE(src_b, src_b_stride, height); |
| 44 |
32/32✓ Branch 0 taken 1 times.
✓ Branch 1 taken 75 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 75 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 75 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 75 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 75 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 75 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 75 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 75 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 75 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 75 times.
✓ Branch 20 taken 2 times.
✓ Branch 21 taken 75 times.
✓ Branch 22 taken 2 times.
✓ Branch 23 taken 75 times.
✓ Branch 24 taken 2 times.
✓ Branch 25 taken 75 times.
✓ Branch 26 taken 2 times.
✓ Branch 27 taken 75 times.
✓ Branch 28 taken 2 times.
✓ Branch 29 taken 75 times.
✓ Branch 30 taken 2 times.
✓ Branch 31 taken 75 times.
|
614 | CHECK_POINTER_AND_STRIDE(dst, dst_stride, height); |
| 45 |
48/48✓ Branch 0 taken 1 times.
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 73 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 73 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 74 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 73 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 73 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 74 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 73 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 73 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 74 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 73 times.
✓ Branch 22 taken 2 times.
✓ Branch 23 taken 73 times.
✓ Branch 24 taken 1 times.
✓ Branch 25 taken 74 times.
✓ Branch 26 taken 1 times.
✓ Branch 27 taken 73 times.
✓ Branch 28 taken 2 times.
✓ Branch 29 taken 73 times.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 74 times.
✓ Branch 32 taken 1 times.
✓ Branch 33 taken 73 times.
✓ Branch 34 taken 2 times.
✓ Branch 35 taken 73 times.
✓ Branch 36 taken 1 times.
✓ Branch 37 taken 74 times.
✓ Branch 38 taken 1 times.
✓ Branch 39 taken 73 times.
✓ Branch 40 taken 2 times.
✓ Branch 41 taken 73 times.
✓ Branch 42 taken 1 times.
✓ Branch 43 taken 74 times.
✓ Branch 44 taken 1 times.
✓ Branch 45 taken 73 times.
✓ Branch 46 taken 2 times.
✓ Branch 47 taken 73 times.
|
600 | CHECK_IMAGE_SIZE(width, height); |
| 46 | |||
| 47 | 584 | SaturatingSub<T> operation; | |
| 48 | 584 | Rectangle rect{width, height}; | |
| 49 | 584 | Rows<const T> src_a_rows{src_a, src_a_stride}; | |
| 50 | 584 | Rows<const T> src_b_rows{src_b, src_b_stride}; | |
| 51 | 584 | Rows<T> dst_rows{dst, dst_stride}; | |
| 52 | 584 | apply_operation_by_rows(operation, rect, src_a_rows, src_b_rows, dst_rows); | |
| 53 | 584 | return KLEIDICV_OK; | |
| 54 | 642 | } | |
| 55 | |||
| 56 | #define KLEIDICV_INSTANTIATE_TEMPLATE(type) \ | ||
| 57 | template KLEIDICV_TARGET_FN_ATTRS kleidicv_error_t saturating_sub<type>( \ | ||
| 58 | const type *src_a, size_t src_a_stride, const type *src_b, \ | ||
| 59 | size_t src_b_stride, type *dst, size_t dst_stride, size_t width, \ | ||
| 60 | size_t height) | ||
| 61 | |||
| 62 | KLEIDICV_INSTANTIATE_TEMPLATE(int8_t); | ||
| 63 | KLEIDICV_INSTANTIATE_TEMPLATE(uint8_t); | ||
| 64 | KLEIDICV_INSTANTIATE_TEMPLATE(int16_t); | ||
| 65 | KLEIDICV_INSTANTIATE_TEMPLATE(uint16_t); | ||
| 66 | KLEIDICV_INSTANTIATE_TEMPLATE(int32_t); | ||
| 67 | KLEIDICV_INSTANTIATE_TEMPLATE(uint32_t); | ||
| 68 | KLEIDICV_INSTANTIATE_TEMPLATE(int64_t); | ||
| 69 | KLEIDICV_INSTANTIATE_TEMPLATE(uint64_t); | ||
| 70 | |||
| 71 | } // namespace kleidicv::neon | ||
| 72 |