Line | Branch | Exec | Source |
---|---|---|---|
1 | // SPDX-FileCopyrightText: 2024 - 2025 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
2 | // | ||
3 | // SPDX-License-Identifier: Apache-2.0 | ||
4 | |||
5 | #ifndef KLEIDICV_SCALE_SC_H | ||
6 | #define KLEIDICV_SCALE_SC_H | ||
7 | |||
8 | #include "kleidicv/kleidicv.h" | ||
9 | #include "kleidicv/sve2.h" | ||
10 | |||
11 | namespace KLEIDICV_TARGET_NAMESPACE { | ||
12 | |||
13 | class AddFloat final : public UnrollTwice { | ||
14 | public: | ||
15 | using ContextType = Context; | ||
16 | using VecTraits = KLEIDICV_TARGET_NAMESPACE::VecTraits<float>; | ||
17 | using VectorType = typename VecTraits::VectorType; | ||
18 | |||
19 | 12 | explicit AddFloat(const svfloat32_t &svshift) KLEIDICV_STREAMING | |
20 | 12 | : svshift_{svshift} {} | |
21 | |||
22 | // NOLINTBEGIN(readability-make-member-function-const) | ||
23 | 6334 | VectorType vector_path(ContextType ctx, VectorType src) KLEIDICV_STREAMING { | |
24 | 6334 | return svadd_x(ctx.predicate(), src, svshift_); | |
25 | } | ||
26 | // NOLINTEND(readability-make-member-function-const) | ||
27 | |||
28 | private: | ||
29 | const svfloat32_t &svshift_; | ||
30 | }; // end of class AddFloat | ||
31 | |||
32 | class ScaleFloat final : public UnrollTwice { | ||
33 | public: | ||
34 | using ContextType = Context; | ||
35 | using VecTraits = KLEIDICV_TARGET_NAMESPACE::VecTraits<float>; | ||
36 | using VectorType = typename VecTraits::VectorType; | ||
37 | |||
38 | 202 | ScaleFloat(const svfloat32_t &svscale, | |
39 | const svfloat32_t &svshift) KLEIDICV_STREAMING | ||
40 | 202 | : svscale_{svscale}, | |
41 | 202 | svshift_{svshift} {} | |
42 | |||
43 | // NOLINTBEGIN(readability-make-member-function-const) | ||
44 | 59146 | VectorType vector_path(ContextType ctx, VectorType src) KLEIDICV_STREAMING { | |
45 | 59146 | return svmla_x(ctx.predicate(), svshift_, src, svscale_); | |
46 | } | ||
47 | // NOLINTEND(readability-make-member-function-const) | ||
48 | |||
49 | private: | ||
50 | const svfloat32_t &svscale_, &svshift_; | ||
51 | }; // end of class ScaleFloat | ||
52 | |||
53 | template <typename T> | ||
54 | kleidicv_error_t scale_sc(const T *src, size_t src_stride, T *dst, | ||
55 | size_t dst_stride, size_t width, size_t height, | ||
56 | float scale, float shift) KLEIDICV_STREAMING; | ||
57 | |||
58 | // Specialization for float | ||
59 | template <> | ||
60 | 226 | kleidicv_error_t scale_sc(const float *src, size_t src_stride, float *dst, | |
61 | size_t dst_stride, size_t width, size_t height, | ||
62 | float scale, float shift) KLEIDICV_STREAMING { | ||
63 |
4/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 222 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 222 times.
|
226 | CHECK_POINTER_AND_STRIDE(src, src_stride, height); |
64 |
4/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 218 times.
|
222 | CHECK_POINTER_AND_STRIDE(dst, dst_stride, height); |
65 |
6/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 216 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 214 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 214 times.
|
218 | CHECK_IMAGE_SIZE(width, height); |
66 | |||
67 | 214 | Rectangle rect{width, height}; | |
68 | 214 | Rows<const float> src_rows{src, src_stride}; | |
69 | 214 | Rows<float> dst_rows{dst, dst_stride}; | |
70 | 214 | svfloat32_t svscale = svdup_f32(scale); | |
71 | 214 | svfloat32_t svshift = svdup_f32(shift); | |
72 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 202 times.
|
214 | if (scale == 1.0) { |
73 | 12 | AddFloat operation(svshift); | |
74 | 12 | apply_operation_by_rows(operation, rect, src_rows, dst_rows); | |
75 | 12 | } else { | |
76 | 202 | ScaleFloat operation(svscale, svshift); | |
77 | 202 | apply_operation_by_rows(operation, rect, src_rows, dst_rows); | |
78 | 202 | } | |
79 | 214 | return KLEIDICV_OK; | |
80 | 226 | } | |
81 | |||
82 | } // namespace KLEIDICV_TARGET_NAMESPACE | ||
83 | |||
84 | #endif // KLEIDICV_SCALE_SC_H | ||
85 |