blob: da304c63294bb6f5b139dea87b3fa4be68329995 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22#ifndef __ARM_COMPUTE_FIXEDPOINT_H__
23#define __ARM_COMPUTE_FIXEDPOINT_H__
24
25#include <cstdint>
26
27namespace arm_compute
28{
29using qint8_t = int8_t; /**< 8 bit fixed point scalar value */
30using qint16_t = int16_t; /**< 16 bit fixed point scalar value */
31using qint32_t = int32_t; /**< 32 bit fixed point scalar value */
32
33/** 8 bit fixed point scalar saturating shift left
34 *
35 * @param[in] a First 8 bit fixed point input
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010036 * @param[in] shift Shift amount (positive only values)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037 *
38 * @return The result of the 8 bit fixed point shift. The result is saturated in case of overflow
39 */
40qint8_t sqshl_qs8(qint8_t a, int shift);
41
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010042/** 16 bit fixed point scalar saturating shift left
43 *
44 * @param[in] a First 16 bit fixed point input
45 * @param[in] shift Shift amount (positive only values)
46 *
47 * @return The result of the 16 bit fixed point shift. The result is saturated in case of overflow
48 */
49qint16_t sqshl_qs16(qint16_t a, int shift);
50
Anthony Barbier6ff3b192017-09-04 18:44:23 +010051/** 8 bit fixed point scalar absolute value
52 *
53 * @param[in] a 8 bit fixed point input
54 *
55 * @return The result of the 8 bit fixed point absolute value
56 */
57qint8_t sabs_qs8(qint8_t a);
58
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010059/** 16 bit fixed point scalar absolute value
60 *
61 * @param[in] a 16 bit fixed point input
62 *
63 * @return The result of the 16 bit fixed point absolute value
64 */
65qint16_t sabs_qs16(qint16_t a);
66
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067/** 8 bit fixed point scalar add
68 *
69 * @param[in] a First 8 bit fixed point input
70 * @param[in] b Second 8 bit fixed point input
71 *
72 * @return The result of the 8 bit fixed point addition
73 */
74qint8_t sadd_qs8(qint8_t a, qint8_t b);
75
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010076/** 16 bit fixed point scalar add
77 *
78 * @param[in] a First 16 bit fixed point input
79 * @param[in] b Second 16 bit fixed point input
80 *
81 * @return The result of the 16 bit fixed point addition
82 */
83qint16_t sadd_qs16(qint16_t a, qint16_t b);
84
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085/** 8 bit fixed point scalar saturating add
86 *
87 * @param[in] a First 8 bit fixed point input
88 * @param[in] b Second 8 bit fixed point input
89 *
90 * @return The result of the 8 bit fixed point addition. The result is saturated in case of overflow
91 */
92qint8_t sqadd_qs8(qint8_t a, qint8_t b);
93
94/** 16 bit fixed point scalar saturating add
95 *
96 * @param[in] a First 16 bit fixed point input
97 * @param[in] b Second 16 bit fixed point input
98 *
99 * @return The result of the 16 bit fixed point addition. The result is saturated in case of overflow
100 */
101qint16_t sqadd_qs16(qint16_t a, qint16_t b);
102
103/** 8 bit fixed point scalar subtraction
104 *
105 * @param[in] a First 8 bit fixed point input
106 * @param[in] b Second 8 bit fixed point input
107 *
108 * @return The result of the 8 bit fixed point subtraction
109 */
110qint8_t ssub_qs8(qint8_t a, qint8_t b);
111
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100112/** 16 bit fixed point scalar subtraction
113 *
114 * @param[in] a First 16 bit fixed point input
115 * @param[in] b Second 16 bit fixed point input
116 *
117 * @return The result of the 16 bit fixed point subtraction
118 */
119qint16_t ssub_qs16(qint16_t a, qint16_t b);
120
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100121/** 8 bit fixed point scalar saturating subtraction
122 *
123 * @param[in] a First 8 bit fixed point input
124 * @param[in] b Second 8 bit fixed point input
125 *
126 * @return The result of the 8 bit fixed point subtraction. The result is saturated in case of overflow
127 */
128qint8_t sqsub_qs8(qint8_t a, qint8_t b);
129
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100130/** 16 bit fixed point scalar saturating subtraction
131 *
132 * @param[in] a First 16 bit fixed point input
133 * @param[in] b Second 16 bit fixed point input
134 *
135 * @return The result of the 16 bit fixed point subtraction. The result is saturated in case of overflow
136 */
137qint16_t sqsub_qs16(qint16_t a, qint16_t b);
138
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100139/** 8 bit fixed point scalar multiply
140 *
141 * @param[in] a First 8 bit fixed point input
142 * @param[in] b Second 8 bit fixed point input
143 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
144 *
145 * @return The result of the 8 bit fixed point multiplication.
146 */
147qint8_t smul_qs8(qint8_t a, qint8_t b, int fixed_point_position);
148
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100149/** 16 bit fixed point scalar multiply
150 *
151 * @param[in] a First 16 bit fixed point input
152 * @param[in] b Second 16 bit fixed point input
153 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
154 *
155 * @return The result of the 16 bit fixed point multiplication.
156 */
157qint16_t smul_qs16(qint16_t a, qint16_t b, int fixed_point_position);
158
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100159/** 8 bit fixed point scalar saturating multiply
160 *
161 * @param[in] a First 8 bit fixed point input
162 * @param[in] b Second 8 bit fixed point input
163 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
164 *
165 * @return The result of the 8 bit fixed point multiplication. The result is saturated in case of overflow
166 */
167qint8_t sqmul_qs8(qint8_t a, qint8_t b, int fixed_point_position);
168
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100169/** 16 bit fixed point scalar saturating multiply
170 *
171 * @param[in] a First 16 bit fixed point input
172 * @param[in] b Second 16 bit fixed point input
173 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
174 *
175 * @return The result of the 16 bit fixed point multiplication. The result is saturated in case of overflow
176 */
177qint16_t sqmul_qs16(qint16_t a, qint16_t b, int fixed_point_position);
178
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100179/** 8 bit fixed point scalar multiply long
180 *
181 * @param[in] a First 8 bit fixed point input
182 * @param[in] b Second 8 bit fixed point input
183 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
184 *
185 * @return The result of the 8 bit fixed point multiplication long. The result is saturated in case of overflow
186 */
187qint16_t sqmull_qs8(qint8_t a, qint8_t b, int fixed_point_position);
188
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100189/** 16 bit fixed point scalar multiply long
190 *
191 * @param[in] a First 16 bit fixed point input
192 * @param[in] b Second 16 bit fixed point input
193 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
194 *
195 * @return The result of the 16 bit fixed point multiplication long. The result is saturated in case of overflow
196 */
197qint32_t sqmull_qs16(qint16_t a, qint16_t b, int fixed_point_position);
198
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100199/** 16 bit fixed point scalar saturating multiply
200*
201* @param[in] a First 16 bit fixed point input
202* @param[in] b Second 16 bit fixed point input
203* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
204*
205* @return The result of the 16 bit fixed point multiplication. The result is saturated in case of overflow
206*/
207qint16_t sqmul_qs16(qint16_t a, qint16_t b, int fixed_point_position);
208
209/** 8 bit fixed point scalar inverse square root
210*
211* @param[in] a 8 bit fixed point input
212* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
213*
214* @return The result of the 8 bit fixed point inverse square root.
215*/
216qint8_t sinvsqrt_qs8(qint8_t a, int fixed_point_position);
217
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100218/** 16 bit fixed point scalar inverse square root
219*
220* @param[in] a 16 bit fixed point input
221* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
222*
223* @return The result of the 16 bit fixed point inverse square root.
224*/
225qint16_t sinvsqrt_qs16(qint16_t a, int fixed_point_position);
226
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100227/** 8 bit fixed point scalar division
228*
229* @param[in] a First 8 bit fixed point input
230* @param[in] b Second 8 bit fixed point input
231* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
232*
233* @return The result of the 8 bit fixed point division.
234*/
235qint8_t sdiv_qs8(qint8_t a, qint8_t b, int fixed_point_position);
236
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100237/** 16 bit fixed point scalar division
238*
239* @param[in] a First 16 bit fixed point input
240* @param[in] b Second 16 bit fixed point input
241* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
242*
243* @return The result of the 16 bit fixed point division.
244*/
245qint16_t sdiv_qs16(qint16_t a, qint16_t b, int fixed_point_position);
246
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100247/** 8 bit fixed point scalar exponential
248*
249* @param[in] a 8 bit fixed point input
250* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
251*
252* @return The result of the 8 bit fixed point exponential.
253*/
254qint8_t sexp_qs8(qint8_t a, int fixed_point_position);
255
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100256/** 16 bit fixed point scalar exponential
257*
258* @param[in] a 16 bit fixed point input
259* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
260*
261* @return The result of the 16 bit fixed point exponential.
262*/
263qint16_t sexp_qs16(qint16_t a, int fixed_point_position);
264
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100265/** 8 bit fixed point scalar logarithm
266*
267* @param[in] a 8 bit fixed point input
268* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
269*
270* @return The result of the 8 bit fixed point logarithm.
271*/
272qint8_t slog_qs8(qint8_t a, int fixed_point_position);
273
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100274/** 16 bit fixed point scalar logarithm
275*
276* @param[in] a 16 bit fixed point input
277* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
278*
279* @return The result of the 16 bit fixed point logarithm.
280*/
281qint16_t slog_qs16(qint16_t a, int fixed_point_position);
282
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100283/** Convert an 8 bit fixed point to float
284 *
285 * @param[in] a Input to convert
286 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
287 *
288 * @return The result of the conversion 8 bit fixed point -> float
289 */
290float scvt_f32_qs8(qint8_t a, int fixed_point_position);
291
292/** Convert a float to 8 bit fixed point
293 *
294 * @param[in] a Input to convert
295 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
296 *
297 * @return The result of the conversion float -> 8 bit fixed point
298 */
299qint8_t scvt_qs8_f32(float a, int fixed_point_position);
300
301/** Convert a 16 bit fixed point to float
302 *
303 * @param[in] a Input to convert
304 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
305 *
306 * @return The result of the conversion 16 bit fixed point -> float
307 */
308float scvt_f32_qs16(qint16_t a, int fixed_point_position);
309
310/** Convert a float to 16 bit fixed point
311 *
312 * @param[in] a Input to convert
313 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
314 *
315 * @return The result of the conversion float -> 16 bit fixed point
316 */
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100317qint16_t scvt_qs16_f32(float a, int fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100318
319/** Scalar saturating move and narrow.
320 *
321 * @param[in] a Input to convert to 8 bit fixed point
322 *
323 * @return The narrowing conversion to 8 bit
324 */
325qint8_t sqmovn_qs16(qint16_t a);
326}
327#include "arm_compute/core/FixedPoint.inl"
328#endif /* __ARM_COMPUTE_FIXEDPOINT_H__ */