blob: 82c2d3347e6bf6f27217d467903d6b8a84ca9e69 [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 */
Georgios Pinitas9247c922017-06-28 18:29:47 +010032using qint64_t = int64_t; /**< 64 bit fixed point scalar value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
34/** 8 bit fixed point scalar saturating shift left
35 *
36 * @param[in] a First 8 bit fixed point input
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010037 * @param[in] shift Shift amount (positive only values)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038 *
39 * @return The result of the 8 bit fixed point shift. The result is saturated in case of overflow
40 */
41qint8_t sqshl_qs8(qint8_t a, int shift);
42
Michalis Spyroubbd9fb92017-06-22 12:57:51 +010043/** 8 bit fixed point scalar shift right
44 *
45 * @param[in] a First 8 bit fixed point input
46 * @param[in] shift Shift amount (positive only values)
47 *
48 * @return The result of the 8 bit fixed point shift
49 */
50qint8_t sshr_qs8(qint8_t a, int shift);
51
52/** 16 bit fixed point scalar shift right
53 *
54 * @param[in] a First 16 bit fixed point input
55 * @param[in] shift Shift amount (positive only values)
56 *
57 * @return The result of the 16 bit fixed point shift
58 */
59qint16_t sshr_qs16(qint16_t a, int shift);
60
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010061/** 16 bit fixed point scalar saturating shift left
62 *
63 * @param[in] a First 16 bit fixed point input
64 * @param[in] shift Shift amount (positive only values)
65 *
66 * @return The result of the 16 bit fixed point shift. The result is saturated in case of overflow
67 */
68qint16_t sqshl_qs16(qint16_t a, int shift);
69
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070/** 8 bit fixed point scalar absolute value
71 *
72 * @param[in] a 8 bit fixed point input
73 *
74 * @return The result of the 8 bit fixed point absolute value
75 */
76qint8_t sabs_qs8(qint8_t a);
77
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010078/** 16 bit fixed point scalar absolute value
79 *
80 * @param[in] a 16 bit fixed point input
81 *
82 * @return The result of the 16 bit fixed point absolute value
83 */
84qint16_t sabs_qs16(qint16_t a);
85
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086/** 8 bit fixed point scalar add
87 *
88 * @param[in] a First 8 bit fixed point input
89 * @param[in] b Second 8 bit fixed point input
90 *
91 * @return The result of the 8 bit fixed point addition
92 */
93qint8_t sadd_qs8(qint8_t a, qint8_t b);
94
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010095/** 16 bit fixed point scalar add
96 *
97 * @param[in] a First 16 bit fixed point input
98 * @param[in] b Second 16 bit fixed point input
99 *
100 * @return The result of the 16 bit fixed point addition
101 */
102qint16_t sadd_qs16(qint16_t a, qint16_t b);
103
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104/** 8 bit fixed point scalar saturating add
105 *
106 * @param[in] a First 8 bit fixed point input
107 * @param[in] b Second 8 bit fixed point input
108 *
109 * @return The result of the 8 bit fixed point addition. The result is saturated in case of overflow
110 */
111qint8_t sqadd_qs8(qint8_t a, qint8_t b);
112
113/** 16 bit fixed point scalar saturating add
114 *
115 * @param[in] a First 16 bit fixed point input
116 * @param[in] b Second 16 bit fixed point input
117 *
118 * @return The result of the 16 bit fixed point addition. The result is saturated in case of overflow
119 */
120qint16_t sqadd_qs16(qint16_t a, qint16_t b);
121
Georgios Pinitas9247c922017-06-28 18:29:47 +0100122/** 32 bit fixed point scalar saturating add
123 *
124 * @param[in] a First 32 bit fixed point input
125 * @param[in] b Second 32 bit fixed point input
126 *
127 * @return The result of the 32 bit fixed point addition. The result is saturated in case of overflow
128 */
129qint32_t sqadd_qs32(qint32_t a, qint32_t b);
130
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131/** 8 bit fixed point scalar subtraction
132 *
133 * @param[in] a First 8 bit fixed point input
134 * @param[in] b Second 8 bit fixed point input
135 *
136 * @return The result of the 8 bit fixed point subtraction
137 */
138qint8_t ssub_qs8(qint8_t a, qint8_t b);
139
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100140/** 16 bit fixed point scalar subtraction
141 *
142 * @param[in] a First 16 bit fixed point input
143 * @param[in] b Second 16 bit fixed point input
144 *
145 * @return The result of the 16 bit fixed point subtraction
146 */
147qint16_t ssub_qs16(qint16_t a, qint16_t b);
148
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100149/** 8 bit fixed point scalar saturating subtraction
150 *
151 * @param[in] a First 8 bit fixed point input
152 * @param[in] b Second 8 bit fixed point input
153 *
154 * @return The result of the 8 bit fixed point subtraction. The result is saturated in case of overflow
155 */
156qint8_t sqsub_qs8(qint8_t a, qint8_t b);
157
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100158/** 16 bit fixed point scalar saturating subtraction
159 *
160 * @param[in] a First 16 bit fixed point input
161 * @param[in] b Second 16 bit fixed point input
162 *
163 * @return The result of the 16 bit fixed point subtraction. The result is saturated in case of overflow
164 */
165qint16_t sqsub_qs16(qint16_t a, qint16_t b);
166
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100167/** 8 bit fixed point scalar multiply
168 *
169 * @param[in] a First 8 bit fixed point input
170 * @param[in] b Second 8 bit fixed point input
171 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
172 *
173 * @return The result of the 8 bit fixed point multiplication.
174 */
175qint8_t smul_qs8(qint8_t a, qint8_t b, int fixed_point_position);
176
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100177/** 16 bit fixed point scalar multiply
178 *
179 * @param[in] a First 16 bit fixed point input
180 * @param[in] b Second 16 bit fixed point input
181 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
182 *
183 * @return The result of the 16 bit fixed point multiplication.
184 */
185qint16_t smul_qs16(qint16_t a, qint16_t b, int fixed_point_position);
186
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100187/** 8 bit fixed point scalar saturating multiply
188 *
189 * @param[in] a First 8 bit fixed point input
190 * @param[in] b Second 8 bit fixed point input
191 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
192 *
193 * @return The result of the 8 bit fixed point multiplication. The result is saturated in case of overflow
194 */
195qint8_t sqmul_qs8(qint8_t a, qint8_t b, int fixed_point_position);
196
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100197/** 16 bit fixed point scalar saturating multiply
198 *
199 * @param[in] a First 16 bit fixed point input
200 * @param[in] b Second 16 bit fixed point input
201 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
202 *
203 * @return The result of the 16 bit fixed point multiplication. The result is saturated in case of overflow
204 */
205qint16_t sqmul_qs16(qint16_t a, qint16_t b, int fixed_point_position);
206
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100207/** 8 bit fixed point scalar multiply long
208 *
209 * @param[in] a First 8 bit fixed point input
210 * @param[in] b Second 8 bit fixed point input
211 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
212 *
213 * @return The result of the 8 bit fixed point multiplication long. The result is saturated in case of overflow
214 */
215qint16_t sqmull_qs8(qint8_t a, qint8_t b, int fixed_point_position);
216
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100217/** 16 bit fixed point scalar multiply long
218 *
219 * @param[in] a First 16 bit fixed point input
220 * @param[in] b Second 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 multiplication long. The result is saturated in case of overflow
224 */
225qint32_t sqmull_qs16(qint16_t a, qint16_t b, int fixed_point_position);
226
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100227/** 16 bit fixed point scalar saturating multiply
228*
229* @param[in] a First 16 bit fixed point input
230* @param[in] b Second 16 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 16 bit fixed point multiplication. The result is saturated in case of overflow
234*/
235qint16_t sqmul_qs16(qint16_t a, qint16_t b, int fixed_point_position);
236
237/** 8 bit fixed point scalar inverse square root
238*
239* @param[in] a 8 bit fixed point input
240* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
241*
242* @return The result of the 8 bit fixed point inverse square root.
243*/
244qint8_t sinvsqrt_qs8(qint8_t a, int fixed_point_position);
245
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100246/** 16 bit fixed point scalar inverse square root
247*
248* @param[in] a 16 bit fixed point input
249* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
250*
251* @return The result of the 16 bit fixed point inverse square root.
252*/
253qint16_t sinvsqrt_qs16(qint16_t a, int fixed_point_position);
254
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100255/** 8 bit fixed point scalar division
256*
257* @param[in] a First 8 bit fixed point input
258* @param[in] b Second 8 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 8 bit fixed point division.
262*/
263qint8_t sdiv_qs8(qint8_t a, qint8_t b, int fixed_point_position);
264
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100265/** 16 bit fixed point scalar division
266*
267* @param[in] a First 16 bit fixed point input
268* @param[in] b Second 16 bit fixed point input
269* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
270*
271* @return The result of the 16 bit fixed point division.
272*/
273qint16_t sdiv_qs16(qint16_t a, qint16_t b, int fixed_point_position);
274
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100275/** 8 bit fixed point scalar exponential
276*
277* @param[in] a 8 bit fixed point input
278* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
279*
280* @return The result of the 8 bit fixed point exponential.
281*/
Georgios Pinitasccc65d42017-06-27 17:39:11 +0100282qint8_t sqexp_qs8(qint8_t a, int fixed_point_position);
283
284/** 16 bit fixed point scalar exponential
285*
286* @param[in] a 16 bit fixed point input
287* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
288*
289* @return The result of the 16 bit fixed point exponential.
290*/
291qint16_t sqexp_qs16(qint16_t a, int fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100292
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100293/** 16 bit fixed point scalar exponential
294*
295* @param[in] a 16 bit fixed point input
296* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
297*
298* @return The result of the 16 bit fixed point exponential.
299*/
300qint16_t sexp_qs16(qint16_t a, int fixed_point_position);
301
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100302/** 8 bit fixed point scalar logarithm
303*
304* @param[in] a 8 bit fixed point input
305* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
306*
307* @return The result of the 8 bit fixed point logarithm.
308*/
309qint8_t slog_qs8(qint8_t a, int fixed_point_position);
310
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100311/** 16 bit fixed point scalar logarithm
312*
313* @param[in] a 16 bit fixed point input
314* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
315*
316* @return The result of the 16 bit fixed point logarithm.
317*/
318qint16_t slog_qs16(qint16_t a, int fixed_point_position);
319
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100320/** Convert an 8 bit fixed point to float
321 *
322 * @param[in] a Input to convert
323 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
324 *
325 * @return The result of the conversion 8 bit fixed point -> float
326 */
327float scvt_f32_qs8(qint8_t a, int fixed_point_position);
328
329/** Convert a float to 8 bit fixed point
330 *
331 * @param[in] a Input to convert
332 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
333 *
334 * @return The result of the conversion float -> 8 bit fixed point
335 */
Georgios Pinitas21efeb42017-07-04 12:47:17 +0100336qint8_t sqcvt_qs8_f32(float a, int fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100337
338/** Convert a 16 bit fixed point to float
339 *
340 * @param[in] a Input to convert
341 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
342 *
343 * @return The result of the conversion 16 bit fixed point -> float
344 */
345float scvt_f32_qs16(qint16_t a, int fixed_point_position);
346
347/** Convert a float to 16 bit fixed point
348 *
349 * @param[in] a Input to convert
350 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
351 *
352 * @return The result of the conversion float -> 16 bit fixed point
353 */
Georgios Pinitas21efeb42017-07-04 12:47:17 +0100354qint16_t sqcvt_qs16_f32(float a, int fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100355
356/** Scalar saturating move and narrow.
357 *
358 * @param[in] a Input to convert to 8 bit fixed point
359 *
360 * @return The narrowing conversion to 8 bit
361 */
362qint8_t sqmovn_qs16(qint16_t a);
Georgios Pinitas9247c922017-06-28 18:29:47 +0100363
364/** Scalar saturating move and narrow.
365 *
366 * @param[in] a Input to convert to 16 bit fixed point
367 *
368 * @return The narrowing conversion to 16 bit
369 */
370qint16_t sqmovn_qs32(qint32_t a);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100371}
372#include "arm_compute/core/FixedPoint.inl"
373#endif /* __ARM_COMPUTE_FIXEDPOINT_H__ */