blob: f166d93c3e17ceae3c7e1fa32a74c4ce15b0eaf9 [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 Spyrou0a8334c2017-06-14 18:00:05 +010043/** 16 bit fixed point scalar saturating shift left
44 *
45 * @param[in] a First 16 bit fixed point input
46 * @param[in] shift Shift amount (positive only values)
47 *
48 * @return The result of the 16 bit fixed point shift. The result is saturated in case of overflow
49 */
50qint16_t sqshl_qs16(qint16_t a, int shift);
51
Anthony Barbier6ff3b192017-09-04 18:44:23 +010052/** 8 bit fixed point scalar absolute value
53 *
54 * @param[in] a 8 bit fixed point input
55 *
56 * @return The result of the 8 bit fixed point absolute value
57 */
58qint8_t sabs_qs8(qint8_t a);
59
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010060/** 16 bit fixed point scalar absolute value
61 *
62 * @param[in] a 16 bit fixed point input
63 *
64 * @return The result of the 16 bit fixed point absolute value
65 */
66qint16_t sabs_qs16(qint16_t a);
67
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068/** 8 bit fixed point scalar add
69 *
70 * @param[in] a First 8 bit fixed point input
71 * @param[in] b Second 8 bit fixed point input
72 *
73 * @return The result of the 8 bit fixed point addition
74 */
75qint8_t sadd_qs8(qint8_t a, qint8_t b);
76
Michalis Spyrou0a8334c2017-06-14 18:00:05 +010077/** 16 bit fixed point scalar add
78 *
79 * @param[in] a First 16 bit fixed point input
80 * @param[in] b Second 16 bit fixed point input
81 *
82 * @return The result of the 16 bit fixed point addition
83 */
84qint16_t sadd_qs16(qint16_t a, qint16_t b);
85
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086/** 8 bit fixed point scalar saturating 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. The result is saturated in case of overflow
92 */
93qint8_t sqadd_qs8(qint8_t a, qint8_t b);
94
95/** 16 bit fixed point scalar saturating 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. The result is saturated in case of overflow
101 */
102qint16_t sqadd_qs16(qint16_t a, qint16_t b);
103
Georgios Pinitas9247c922017-06-28 18:29:47 +0100104/** 32 bit fixed point scalar saturating add
105 *
106 * @param[in] a First 32 bit fixed point input
107 * @param[in] b Second 32 bit fixed point input
108 *
109 * @return The result of the 32 bit fixed point addition. The result is saturated in case of overflow
110 */
111qint32_t sqadd_qs32(qint32_t a, qint32_t b);
112
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113/** 8 bit fixed point scalar subtraction
114 *
115 * @param[in] a First 8 bit fixed point input
116 * @param[in] b Second 8 bit fixed point input
117 *
118 * @return The result of the 8 bit fixed point subtraction
119 */
120qint8_t ssub_qs8(qint8_t a, qint8_t b);
121
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100122/** 16 bit fixed point scalar subtraction
123 *
124 * @param[in] a First 16 bit fixed point input
125 * @param[in] b Second 16 bit fixed point input
126 *
127 * @return The result of the 16 bit fixed point subtraction
128 */
129qint16_t ssub_qs16(qint16_t a, qint16_t b);
130
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131/** 8 bit fixed point scalar saturating 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. The result is saturated in case of overflow
137 */
138qint8_t sqsub_qs8(qint8_t a, qint8_t b);
139
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100140/** 16 bit fixed point scalar saturating 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. The result is saturated in case of overflow
146 */
147qint16_t sqsub_qs16(qint16_t a, qint16_t b);
148
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100149/** 8 bit fixed point scalar multiply
150 *
151 * @param[in] a First 8 bit fixed point input
152 * @param[in] b Second 8 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 8 bit fixed point multiplication.
156 */
157qint8_t smul_qs8(qint8_t a, qint8_t b, int fixed_point_position);
158
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100159/** 16 bit fixed point scalar multiply
160 *
161 * @param[in] a First 16 bit fixed point input
162 * @param[in] b Second 16 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 16 bit fixed point multiplication.
166 */
167qint16_t smul_qs16(qint16_t a, qint16_t b, int fixed_point_position);
168
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100169/** 8 bit fixed point scalar saturating multiply
170 *
171 * @param[in] a First 8 bit fixed point input
172 * @param[in] b Second 8 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 8 bit fixed point multiplication. The result is saturated in case of overflow
176 */
177qint8_t sqmul_qs8(qint8_t a, qint8_t b, int fixed_point_position);
178
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100179/** 16 bit fixed point scalar saturating multiply
180 *
181 * @param[in] a First 16 bit fixed point input
182 * @param[in] b Second 16 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 16 bit fixed point multiplication. The result is saturated in case of overflow
186 */
187qint16_t sqmul_qs16(qint16_t a, qint16_t b, int fixed_point_position);
188
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189/** 8 bit fixed point scalar multiply long
190 *
191 * @param[in] a First 8 bit fixed point input
192 * @param[in] b Second 8 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 8 bit fixed point multiplication long. The result is saturated in case of overflow
196 */
197qint16_t sqmull_qs8(qint8_t a, qint8_t b, int fixed_point_position);
198
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100199/** 16 bit fixed point scalar multiply long
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 long. The result is saturated in case of overflow
206 */
207qint32_t sqmull_qs16(qint16_t a, qint16_t b, int fixed_point_position);
208
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100209/** 16 bit fixed point scalar saturating multiply
210*
211* @param[in] a First 16 bit fixed point input
212* @param[in] b Second 16 bit fixed point input
213* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
214*
215* @return The result of the 16 bit fixed point multiplication. The result is saturated in case of overflow
216*/
217qint16_t sqmul_qs16(qint16_t a, qint16_t b, int fixed_point_position);
218
219/** 8 bit fixed point scalar inverse square root
220*
221* @param[in] a 8 bit fixed point input
222* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
223*
224* @return The result of the 8 bit fixed point inverse square root.
225*/
226qint8_t sinvsqrt_qs8(qint8_t a, int fixed_point_position);
227
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100228/** 16 bit fixed point scalar inverse square root
229*
230* @param[in] a 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 inverse square root.
234*/
235qint16_t sinvsqrt_qs16(qint16_t a, int fixed_point_position);
236
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100237/** 8 bit fixed point scalar division
238*
239* @param[in] a First 8 bit fixed point input
240* @param[in] b Second 8 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 8 bit fixed point division.
244*/
245qint8_t sdiv_qs8(qint8_t a, qint8_t b, int fixed_point_position);
246
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100247/** 16 bit fixed point scalar division
248*
249* @param[in] a First 16 bit fixed point input
250* @param[in] b Second 16 bit fixed point input
251* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
252*
253* @return The result of the 16 bit fixed point division.
254*/
255qint16_t sdiv_qs16(qint16_t a, qint16_t b, int fixed_point_position);
256
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100257/** 8 bit fixed point scalar exponential
258*
259* @param[in] a 8 bit fixed point input
260* @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number
261*
262* @return The result of the 8 bit fixed point exponential.
263*/
Georgios Pinitasccc65d42017-06-27 17:39:11 +0100264qint8_t sqexp_qs8(qint8_t a, int fixed_point_position);
265
266/** 16 bit fixed point scalar exponential
267*
268* @param[in] a 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 exponential.
272*/
273qint16_t sqexp_qs16(qint16_t a, int fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100274
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100275/** 16 bit fixed point scalar exponential
276*
277* @param[in] a 16 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 16 bit fixed point exponential.
281*/
282qint16_t sexp_qs16(qint16_t a, int fixed_point_position);
283
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100284/** 8 bit fixed point scalar logarithm
285*
286* @param[in] a 8 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 8 bit fixed point logarithm.
290*/
291qint8_t slog_qs8(qint8_t a, int fixed_point_position);
292
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100293/** 16 bit fixed point scalar logarithm
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 logarithm.
299*/
300qint16_t slog_qs16(qint16_t a, int fixed_point_position);
301
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100302/** Convert an 8 bit fixed point to float
303 *
304 * @param[in] a Input to convert
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 conversion 8 bit fixed point -> float
308 */
309float scvt_f32_qs8(qint8_t a, int fixed_point_position);
310
311/** Convert a float to 8 bit fixed point
312 *
313 * @param[in] a Input to convert
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 conversion float -> 8 bit fixed point
317 */
Georgios Pinitas21efeb42017-07-04 12:47:17 +0100318qint8_t sqcvt_qs8_f32(float a, int fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100319
320/** Convert a 16 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 16 bit fixed point -> float
326 */
327float scvt_f32_qs16(qint16_t a, int fixed_point_position);
328
329/** Convert a float to 16 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 -> 16 bit fixed point
335 */
Georgios Pinitas21efeb42017-07-04 12:47:17 +0100336qint16_t sqcvt_qs16_f32(float a, int fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100337
338/** Scalar saturating move and narrow.
339 *
340 * @param[in] a Input to convert to 8 bit fixed point
341 *
342 * @return The narrowing conversion to 8 bit
343 */
344qint8_t sqmovn_qs16(qint16_t a);
Georgios Pinitas9247c922017-06-28 18:29:47 +0100345
346/** Scalar saturating move and narrow.
347 *
348 * @param[in] a Input to convert to 16 bit fixed point
349 *
350 * @return The narrowing conversion to 16 bit
351 */
352qint16_t sqmovn_qs32(qint32_t a);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100353}
354#include "arm_compute/core/FixedPoint.inl"
355#endif /* __ARM_COMPUTE_FIXEDPOINT_H__ */