blob: 288d45d979310ab4f670dc334b890adb84ab935b [file] [log] [blame]
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +00001/*
Michalis Spyrou168d6a82022-05-03 17:15:42 +01002 * Copyright (c) 2020-2022 Arm Limited.
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_SVESYMM_H
25#define ARM_COMPUTE_SVESYMM_H
26
27#include "arm_compute/core/utils/quantization/AsymmHelpers.h"
28
Michalis Spyrou20fca522021-06-07 14:23:57 +010029#if defined(ARM_COMPUTE_ENABLE_SVE2)
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +000030#include "src/core/NEON/SVEMath.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010031
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +000032#include <arm_sve.h>
33
34namespace arm_compute
35{
36/** Dequantize an sve vector holding 16-bit quantized values.
37 *
38 * @param[in] pg Predicate value.
39 * @param[in] qv Input values to be dequantized.
40 * @param[in] scale Quantization scale
41 *
42 * @return Dequantized values in an sve vector
43 */
44inline svfloat32x2_t svdequantize_qsymm16_z(svbool_t pg, const svint16_t &qv, float scale)
45{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010046 const auto vscale = svdup_n_f32(scale);
47 const svfloat32x2_t vdequantized_input =
48 svcreate2_f32(svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlb_s32(qv)), vscale),
49 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlt_s32(qv)), vscale));
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +000050 return vdequantized_input;
51}
52
53/** Quantize an sve vector holding 8 floating point values.
54 *
55 * @param[in] pg Predicate value.
56 * @param[in] qv Input values to be quantized.
57 * @param[in] scale Quantization scale
58 *
59 * @return An sve vector holding the quantized values
60 */
61inline svint16_t svquantize_qsymm16_z(svbool_t pg, const svfloat32x2_t qv, float scale)
62{
63 const svfloat32_t vinvscale = svdup_n_f32(1.f / scale);
64
65 const auto rf_0 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget2_f32(qv, 0), vinvscale));
66 const auto rf_1 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget2_f32(qv, 1), vinvscale));
67 const auto pa = svqxtnt_s32(svqxtnb_s32(rf_0), rf_1);
68
69 return pa;
70}
71
72/** Dequantize an sve vector holding 16 16-bit quantized values.
73 *
74 * @param[in] pg Predicate value.
75 * @param[in] qv Input values to be dequantized.
76 * @param[in] qi Quantization information to be used in the computation.
77 *
78 * @return Dequantized values in an sve vector
79 */
80inline svfloat32x4_t svdequantize_z(svbool_t pg, const svint16x2_t qv, const UniformQuantizationInfo &qi)
81{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082 const float scale = qi.scale;
83 const auto vscale = svdup_n_f32(scale);
84 const svfloat32x4_t vdequantized_input =
85 svcreate4_f32(svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlb_s32(svget2_s16(qv, 0))), vscale),
86 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlt_s32(svget2_s16(qv, 0))), vscale),
87 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlb_s32(svget2_s16(qv, 1))), vscale),
88 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlt_s32(svget2_s16(qv, 1))), vscale));
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +000089 return vdequantized_input;
90}
91
92/** Quantize an sve vector holding 16 floating point values.
93 *
94 * @param[in] pg Predicate value.
95 * @param[in] qv Input values to be quantized.
96 * @param[in] qi Quantization information to be used in the computation.
97 *
98 * @return An sve vector holding the quantized values
99 */
100inline svint16x2_t svquantize_qsymm16_z(svbool_t pg, const svfloat32x4_t qv, const UniformQuantizationInfo &qi)
101{
102 const float scale = qi.scale;
103 ARM_COMPUTE_ERROR_ON(scale == 0.f);
104 const auto vinvscale = svdup_n_f32(1.f / scale);
105 const auto rf_0 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget4_f32(qv, 0), vinvscale));
106 const auto rf_1 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget4_f32(qv, 1), vinvscale));
107 const auto rf_2 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget4_f32(qv, 2), vinvscale));
108 const auto rf_3 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget4_f32(qv, 3), vinvscale));
109
110 const auto pa = svqxtnt_s32(svqxtnb_s32(rf_0), rf_1);
111 const auto pb = svqxtnt_s32(svqxtnb_s32(rf_2), rf_3);
112
113 return svcreate2_s16(pa, pb);
114}
115
116} // namespace arm_compute
Michalis Spyrou20fca522021-06-07 14:23:57 +0100117#endif /* defined(ARM_COMPUTE_ENABLE_SVE2) */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100118#endif // ARM_COMPUTE_NESYMM_H