blob: c71d273b67da6667a0052d0a0be36501eee1c755 [file] [log] [blame]
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +00001/*
Michalis Spyrou20fca522021-06-07 14:23:57 +01002 * Copyright (c) 2020-2021 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"
31#include <arm_sve.h>
32
33namespace arm_compute
34{
35/** Dequantize an sve vector holding 16-bit quantized values.
36 *
37 * @param[in] pg Predicate value.
38 * @param[in] qv Input values to be dequantized.
39 * @param[in] scale Quantization scale
40 *
41 * @return Dequantized values in an sve vector
42 */
43inline svfloat32x2_t svdequantize_qsymm16_z(svbool_t pg, const svint16_t &qv, float scale)
44{
45 const auto vscale = svdup_n_f32(scale);
46 const svfloat32x2_t vdequantized_input =
47 {
48 { {
49 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlb_s32(qv)), vscale),
50 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlt_s32(qv)), vscale)
51 }
52 }
53 };
54 return vdequantized_input;
55}
56
57/** Quantize an sve vector holding 8 floating point values.
58 *
59 * @param[in] pg Predicate value.
60 * @param[in] qv Input values to be quantized.
61 * @param[in] scale Quantization scale
62 *
63 * @return An sve vector holding the quantized values
64 */
65inline svint16_t svquantize_qsymm16_z(svbool_t pg, const svfloat32x2_t qv, float scale)
66{
67 const svfloat32_t vinvscale = svdup_n_f32(1.f / scale);
68
69 const auto rf_0 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget2_f32(qv, 0), vinvscale));
70 const auto rf_1 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget2_f32(qv, 1), vinvscale));
71 const auto pa = svqxtnt_s32(svqxtnb_s32(rf_0), rf_1);
72
73 return pa;
74}
75
76/** Dequantize an sve vector holding 16 16-bit quantized values.
77 *
78 * @param[in] pg Predicate value.
79 * @param[in] qv Input values to be dequantized.
80 * @param[in] qi Quantization information to be used in the computation.
81 *
82 * @return Dequantized values in an sve vector
83 */
84inline svfloat32x4_t svdequantize_z(svbool_t pg, const svint16x2_t qv, const UniformQuantizationInfo &qi)
85{
86 const float scale = qi.scale;
87 const auto vscale = svdup_n_f32(scale);
88 const svfloat32x4_t vdequantized_input =
89 {
90 { {
91 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlb_s32(svget2_s16(qv, 0))), vscale),
92 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlt_s32(svget2_s16(qv, 0))), vscale),
93 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlb_s32(svget2_s16(qv, 1))), vscale),
94 svmul_f32_z(pg, svcvt_f32_s32_z(pg, svmovlt_s32(svget2_s16(qv, 1))), vscale),
95 }
96 }
97 };
98 return vdequantized_input;
99}
100
101/** Quantize an sve vector holding 16 floating point values.
102 *
103 * @param[in] pg Predicate value.
104 * @param[in] qv Input values to be quantized.
105 * @param[in] qi Quantization information to be used in the computation.
106 *
107 * @return An sve vector holding the quantized values
108 */
109inline svint16x2_t svquantize_qsymm16_z(svbool_t pg, const svfloat32x4_t qv, const UniformQuantizationInfo &qi)
110{
111 const float scale = qi.scale;
112 ARM_COMPUTE_ERROR_ON(scale == 0.f);
113 const auto vinvscale = svdup_n_f32(1.f / scale);
114 const auto rf_0 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget4_f32(qv, 0), vinvscale));
115 const auto rf_1 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget4_f32(qv, 1), vinvscale));
116 const auto rf_2 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget4_f32(qv, 2), vinvscale));
117 const auto rf_3 = svcvt_s32_f32_z(pg, svmul_f32_z(pg, svget4_f32(qv, 3), vinvscale));
118
119 const auto pa = svqxtnt_s32(svqxtnb_s32(rf_0), rf_1);
120 const auto pb = svqxtnt_s32(svqxtnb_s32(rf_2), rf_3);
121
122 return svcreate2_s16(pa, pb);
123}
124
125} // namespace arm_compute
Michalis Spyrou20fca522021-06-07 14:23:57 +0100126#endif /* defined(ARM_COMPUTE_ENABLE_SVE2) */
Michalis Spyrouaa51a5b2020-11-22 00:49:42 +0000127#endif // ARM_COMPUTE_NESYMM_H