KleidiCV Coverage Report


Directory: ./
File: kleidicv/src/arithmetics/multiply_sc.h
Date: 2025-11-25 17:23:32
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 45 45 100.0%
Branches: 90 90 100.0%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 #ifndef MULTIPLY_SC_H
6 #define MULTIPLY_SC_H
7
8 #include "kleidicv/sve2.h"
9
10 namespace KLEIDICV_TARGET_NAMESPACE {
11
12 template <typename ScalarType>
13 class SaturatingMultiply final : public UnrollTwice {
14 public:
15 using ContextType = Context;
16 using VecTraits = KLEIDICV_TARGET_NAMESPACE::VecTraits<ScalarType>;
17 using VectorType = typename VecTraits::VectorType;
18
19 975 explicit SaturatingMultiply(double scale = 1.0) : scale_{scale} {};
20
21 8110 VectorType vector_path(ContextType ctx, VectorType src_a,
22 VectorType src_b) KLEIDICV_STREAMING {
23 8110 VectorType result;
24 (void)ctx;
25
26 // multiply-widen even-indexed elements
27 8110 auto bottom_part = svmullb(src_a, src_b);
28 // multiply-widen odd-indexed elements
29 8110 auto top_part = svmullt(src_a, src_b);
30 // saturating-narrow even-indexed
31 8110 auto narrow_bottom = svqxtnb(bottom_part);
32 // saturaning-narrow odd-indexed and merge with even-indexed
33 8110 result = svqxtnt(narrow_bottom, top_part);
34
35 /* TODO: figure out the way to multiply by double or some
36 fixed supported scale.
37 */
38
39 16220 return result;
40 8110 }
41
42 private:
43 double scale_;
44 };
45
46 template <typename T>
47 1077 kleidicv_error_t saturating_multiply_sc(const T *src_a, size_t src_a_stride,
48 const T *src_b, size_t src_b_stride,
49 T *dst, size_t dst_stride, size_t width,
50 size_t height,
51 double scale) KLEIDICV_STREAMING {
52
20/20
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 207 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 207 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 207 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 207 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 213 times.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 213 times.
✓ Branch 12 taken 6 times.
✓ Branch 13 taken 213 times.
✓ Branch 14 taken 6 times.
✓ Branch 15 taken 213 times.
✓ Branch 16 taken 6 times.
✓ Branch 17 taken 213 times.
✓ Branch 18 taken 6 times.
✓ Branch 19 taken 213 times.
1077 CHECK_POINTER_AND_STRIDE(src_a, src_a_stride, height);
53
20/20
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 204 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 204 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 204 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 204 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 207 times.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 207 times.
✓ Branch 12 taken 6 times.
✓ Branch 13 taken 207 times.
✓ Branch 14 taken 6 times.
✓ Branch 15 taken 207 times.
✓ Branch 16 taken 6 times.
✓ Branch 17 taken 207 times.
✓ Branch 18 taken 6 times.
✓ Branch 19 taken 207 times.
1053 CHECK_POINTER_AND_STRIDE(src_b, src_b_stride, height);
54
20/20
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 201 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 201 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 201 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 201 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 201 times.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 201 times.
✓ Branch 12 taken 6 times.
✓ Branch 13 taken 201 times.
✓ Branch 14 taken 6 times.
✓ Branch 15 taken 201 times.
✓ Branch 16 taken 6 times.
✓ Branch 17 taken 201 times.
✓ Branch 18 taken 6 times.
✓ Branch 19 taken 201 times.
1029 CHECK_POINTER_AND_STRIDE(dst, dst_stride, height);
55
30/30
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 198 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 195 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 195 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 198 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 195 times.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 195 times.
✓ Branch 12 taken 3 times.
✓ Branch 13 taken 198 times.
✓ Branch 14 taken 3 times.
✓ Branch 15 taken 195 times.
✓ Branch 16 taken 6 times.
✓ Branch 17 taken 195 times.
✓ Branch 18 taken 3 times.
✓ Branch 19 taken 198 times.
✓ Branch 20 taken 3 times.
✓ Branch 21 taken 195 times.
✓ Branch 22 taken 6 times.
✓ Branch 23 taken 195 times.
✓ Branch 24 taken 3 times.
✓ Branch 25 taken 198 times.
✓ Branch 26 taken 3 times.
✓ Branch 27 taken 195 times.
✓ Branch 28 taken 6 times.
✓ Branch 29 taken 195 times.
1005 CHECK_IMAGE_SIZE(width, height);
56
57 (void)scale; // TODO: figure out the way to process the scale.
58 975 SaturatingMultiply<T> operation;
59 975 Rectangle rect{width, height};
60 975 Rows<const T> src_a_rows{src_a, src_a_stride};
61 975 Rows<const T> src_b_rows{src_b, src_b_stride};
62 975 Rows<T> dst_rows{dst, dst_stride};
63 975 apply_operation_by_rows(operation, rect, src_a_rows, src_b_rows, dst_rows);
64 975 return KLEIDICV_OK;
65 1077 }
66
67 } // namespace KLEIDICV_TARGET_NAMESPACE
68
69 #endif // MULTIPLY_SC_H
70