Linux Audio

Check our new training course

Loading...
v6.9.4
  1/*
  2 * Copyright 2012-15 Advanced Micro Devices, Inc.
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the "Software"),
  6 * to deal in the Software without restriction, including without limitation
  7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8 * and/or sell copies of the Software, and to permit persons to whom the
  9 * Software is furnished to do so, subject to the following conditions:
 10 *
 11 * The above copyright notice and this permission notice shall be included in
 12 * all 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
 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 20 * OTHER DEALINGS IN THE SOFTWARE.
 21 *
 22 * Authors: AMD
 23 *
 24 */
 25
 26#ifndef __DAL_FIXED31_32_H__
 27#define __DAL_FIXED31_32_H__
 28
 29#ifndef LLONG_MAX
 30#define LLONG_MAX 9223372036854775807ll
 31#endif
 32#ifndef LLONG_MIN
 33#define LLONG_MIN (-LLONG_MAX - 1ll)
 34#endif
 35
 36#define FIXED31_32_BITS_PER_FRACTIONAL_PART 32
 37#ifndef LLONG_MIN
 38#define LLONG_MIN (1LL<<63)
 39#endif
 40#ifndef LLONG_MAX
 41#define LLONG_MAX (-1LL>>1)
 42#endif
 43
 44/*
 45 * @brief
 46 * Arithmetic operations on real numbers
 47 * represented as fixed-point numbers.
 48 * There are: 1 bit for sign,
 49 * 31 bit for integer part,
 50 * 32 bits for fractional part.
 51 *
 52 * @note
 53 * Currently, overflows and underflows are asserted;
 54 * no special result returned.
 55 */
 56
 57struct fixed31_32 {
 58	long long value;
 59};
 60
 61
 62/*
 63 * @brief
 64 * Useful constants
 65 */
 66
 67static const struct fixed31_32 dc_fixpt_zero = { 0 };
 68static const struct fixed31_32 dc_fixpt_epsilon = { 1LL };
 69static const struct fixed31_32 dc_fixpt_half = { 0x80000000LL };
 70static const struct fixed31_32 dc_fixpt_one = { 0x100000000LL };
 
 
 
 
 
 
 71
 72/*
 73 * @brief
 74 * Initialization routines
 75 */
 76
 77/*
 78 * @brief
 79 * result = numerator / denominator
 80 */
 81struct fixed31_32 dc_fixpt_from_fraction(long long numerator, long long denominator);
 
 
 82
 83/*
 84 * @brief
 85 * result = arg
 86 */
 87static inline struct fixed31_32 dc_fixpt_from_int(int arg)
 
 88{
 89	struct fixed31_32 res;
 90
 91	res.value = (long long) arg << FIXED31_32_BITS_PER_FRACTIONAL_PART;
 92
 93	return res;
 
 
 94}
 95
 96/*
 97 * @brief
 98 * Unary operators
 99 */
100
101/*
102 * @brief
103 * result = -arg
104 */
105static inline struct fixed31_32 dc_fixpt_neg(struct fixed31_32 arg)
106{
107	struct fixed31_32 res;
108
109	res.value = -arg.value;
110
111	return res;
112}
113
114/*
115 * @brief
116 * result = abs(arg) := (arg >= 0) ? arg : -arg
117 */
118static inline struct fixed31_32 dc_fixpt_abs(struct fixed31_32 arg)
119{
120	if (arg.value < 0)
121		return dc_fixpt_neg(arg);
122	else
123		return arg;
124}
125
126/*
127 * @brief
128 * Binary relational operators
129 */
130
131/*
132 * @brief
133 * result = arg1 < arg2
134 */
135static inline bool dc_fixpt_lt(struct fixed31_32 arg1, struct fixed31_32 arg2)
 
136{
137	return arg1.value < arg2.value;
138}
139
140/*
141 * @brief
142 * result = arg1 <= arg2
143 */
144static inline bool dc_fixpt_le(struct fixed31_32 arg1, struct fixed31_32 arg2)
 
145{
146	return arg1.value <= arg2.value;
147}
148
149/*
150 * @brief
151 * result = arg1 == arg2
152 */
153static inline bool dc_fixpt_eq(struct fixed31_32 arg1, struct fixed31_32 arg2)
 
154{
155	return arg1.value == arg2.value;
156}
157
158/*
159 * @brief
160 * result = min(arg1, arg2) := (arg1 <= arg2) ? arg1 : arg2
161 */
162static inline struct fixed31_32 dc_fixpt_min(struct fixed31_32 arg1, struct fixed31_32 arg2)
 
163{
164	if (arg1.value <= arg2.value)
165		return arg1;
166	else
167		return arg2;
168}
169
170/*
171 * @brief
172 * result = max(arg1, arg2) := (arg1 <= arg2) ? arg2 : arg1
173 */
174static inline struct fixed31_32 dc_fixpt_max(struct fixed31_32 arg1, struct fixed31_32 arg2)
 
175{
176	if (arg1.value <= arg2.value)
177		return arg2;
178	else
179		return arg1;
180}
181
182/*
183 * @brief
184 *          | min_value, when arg <= min_value
185 * result = | arg, when min_value < arg < max_value
186 *          | max_value, when arg >= max_value
187 */
188static inline struct fixed31_32 dc_fixpt_clamp(
189	struct fixed31_32 arg,
190	struct fixed31_32 min_value,
191	struct fixed31_32 max_value)
192{
193	if (dc_fixpt_le(arg, min_value))
194		return min_value;
195	else if (dc_fixpt_le(max_value, arg))
196		return max_value;
197	else
198		return arg;
199}
200
201/*
202 * @brief
203 * Binary shift operators
204 */
205
206/*
207 * @brief
208 * result = arg << shift
209 */
210static inline struct fixed31_32 dc_fixpt_shl(struct fixed31_32 arg, unsigned char shift)
211{
212	ASSERT(((arg.value >= 0) && (arg.value <= LLONG_MAX >> shift)) ||
213		((arg.value < 0) && (arg.value >= ~(LLONG_MAX >> shift))));
214
215	arg.value = arg.value << shift;
216
217	return arg;
218}
219
220/*
221 * @brief
222 * result = arg >> shift
223 */
224static inline struct fixed31_32 dc_fixpt_shr(struct fixed31_32 arg, unsigned char shift)
 
 
225{
226	bool negative = arg.value < 0;
227
228	if (negative)
229		arg.value = -arg.value;
230	arg.value = arg.value >> shift;
231	if (negative)
232		arg.value = -arg.value;
233	return arg;
234}
235
236/*
237 * @brief
238 * Binary additive operators
239 */
240
241/*
242 * @brief
243 * result = arg1 + arg2
244 */
245static inline struct fixed31_32 dc_fixpt_add(struct fixed31_32 arg1, struct fixed31_32 arg2)
246{
247	struct fixed31_32 res;
248
249	ASSERT(((arg1.value >= 0) && (LLONG_MAX - arg1.value >= arg2.value)) ||
250		((arg1.value < 0) && (LLONG_MIN - arg1.value <= arg2.value)));
251
252	res.value = arg1.value + arg2.value;
253
254	return res;
255}
256
257/*
258 * @brief
259 * result = arg1 + arg2
260 */
261static inline struct fixed31_32 dc_fixpt_add_int(struct fixed31_32 arg1, int arg2)
 
262{
263	return dc_fixpt_add(arg1, dc_fixpt_from_int(arg2));
 
264}
265
266/*
267 * @brief
268 * result = arg1 - arg2
269 */
270static inline struct fixed31_32 dc_fixpt_sub(struct fixed31_32 arg1, struct fixed31_32 arg2)
271{
272	struct fixed31_32 res;
273
274	ASSERT(((arg2.value >= 0) && (LLONG_MIN + arg2.value <= arg1.value)) ||
275		((arg2.value < 0) && (LLONG_MAX + arg2.value >= arg1.value)));
276
277	res.value = arg1.value - arg2.value;
278
279	return res;
280}
281
282/*
283 * @brief
284 * result = arg1 - arg2
285 */
286static inline struct fixed31_32 dc_fixpt_sub_int(struct fixed31_32 arg1, int arg2)
 
287{
288	return dc_fixpt_sub(arg1, dc_fixpt_from_int(arg2));
 
289}
290
291
292/*
293 * @brief
294 * Binary multiplicative operators
295 */
296
297/*
298 * @brief
299 * result = arg1 * arg2
300 */
301struct fixed31_32 dc_fixpt_mul(struct fixed31_32 arg1, struct fixed31_32 arg2);
 
 
302
303
304/*
305 * @brief
306 * result = arg1 * arg2
307 */
308static inline struct fixed31_32 dc_fixpt_mul_int(struct fixed31_32 arg1, int arg2)
 
309{
310	return dc_fixpt_mul(arg1, dc_fixpt_from_int(arg2));
 
311}
312
313/*
314 * @brief
315 * result = square(arg) := arg * arg
316 */
317struct fixed31_32 dc_fixpt_sqr(struct fixed31_32 arg);
 
318
319/*
320 * @brief
321 * result = arg1 / arg2
322 */
323static inline struct fixed31_32 dc_fixpt_div_int(struct fixed31_32 arg1, long long arg2)
 
324{
325	return dc_fixpt_from_fraction(arg1.value, dc_fixpt_from_int((int)arg2).value);
 
326}
327
328/*
329 * @brief
330 * result = arg1 / arg2
331 */
332static inline struct fixed31_32 dc_fixpt_div(struct fixed31_32 arg1, struct fixed31_32 arg2)
 
333{
334	return dc_fixpt_from_fraction(arg1.value, arg2.value);
 
335}
336
337/*
338 * @brief
339 * Reciprocal function
340 */
341
342/*
343 * @brief
344 * result = reciprocal(arg) := 1 / arg
345 *
346 * @note
347 * No special actions taken in case argument is zero.
348 */
349struct fixed31_32 dc_fixpt_recip(struct fixed31_32 arg);
 
350
351/*
352 * @brief
353 * Trigonometric functions
354 */
355
356/*
357 * @brief
358 * result = sinc(arg) := sin(arg) / arg
359 *
360 * @note
361 * Argument specified in radians,
362 * internally it's normalized to [-2pi...2pi] range.
363 */
364struct fixed31_32 dc_fixpt_sinc(struct fixed31_32 arg);
 
365
366/*
367 * @brief
368 * result = sin(arg)
369 *
370 * @note
371 * Argument specified in radians,
372 * internally it's normalized to [-2pi...2pi] range.
373 */
374struct fixed31_32 dc_fixpt_sin(struct fixed31_32 arg);
 
375
376/*
377 * @brief
378 * result = cos(arg)
379 *
380 * @note
381 * Argument specified in radians
382 * and should be in [-2pi...2pi] range -
383 * passing arguments outside that range
384 * will cause incorrect result!
385 */
386struct fixed31_32 dc_fixpt_cos(struct fixed31_32 arg);
 
387
388/*
389 * @brief
390 * Transcendent functions
391 */
392
393/*
394 * @brief
395 * result = exp(arg)
396 *
397 * @note
398 * Currently, function is verified for abs(arg) <= 1.
399 */
400struct fixed31_32 dc_fixpt_exp(struct fixed31_32 arg);
 
401
402/*
403 * @brief
404 * result = log(arg)
405 *
406 * @note
407 * Currently, abs(arg) should be less than 1.
408 * No normalization is done.
409 * Currently, no special actions taken
410 * in case of invalid argument(s). Take care!
411 */
412struct fixed31_32 dc_fixpt_log(struct fixed31_32 arg);
 
413
414/*
415 * @brief
416 * Power function
417 */
418
419/*
420 * @brief
421 * result = pow(arg1, arg2)
422 *
423 * @note
424 * Currently, abs(arg1) should be less than 1. Take care!
425 */
426static inline struct fixed31_32 dc_fixpt_pow(struct fixed31_32 arg1, struct fixed31_32 arg2)
427{
428	if (arg1.value == 0)
429		return arg2.value == 0 ? dc_fixpt_one : dc_fixpt_zero;
430
431	return dc_fixpt_exp(
432		dc_fixpt_mul(
433			dc_fixpt_log(arg1),
434			arg2));
435}
436
437/*
438 * @brief
439 * Rounding functions
440 */
441
442/*
443 * @brief
444 * result = floor(arg) := greatest integer lower than or equal to arg
445 */
446static inline int dc_fixpt_floor(struct fixed31_32 arg)
447{
448	unsigned long long arg_value = arg.value > 0 ? arg.value : -arg.value;
449
450	if (arg.value >= 0)
451		return (int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
452	else
453		return -(int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
454}
455
456/*
457 * @brief
458 * result = round(arg) := integer nearest to arg
459 */
460static inline int dc_fixpt_round(struct fixed31_32 arg)
461{
462	unsigned long long arg_value = arg.value > 0 ? arg.value : -arg.value;
463
464	const long long summand = dc_fixpt_half.value;
465
466	ASSERT(LLONG_MAX - (long long)arg_value >= summand);
467
468	arg_value += summand;
469
470	if (arg.value >= 0)
471		return (int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
472	else
473		return -(int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
474}
475
476/*
477 * @brief
478 * result = ceil(arg) := lowest integer greater than or equal to arg
479 */
480static inline int dc_fixpt_ceil(struct fixed31_32 arg)
481{
482	unsigned long long arg_value = arg.value > 0 ? arg.value : -arg.value;
483
484	const long long summand = dc_fixpt_one.value -
485		dc_fixpt_epsilon.value;
486
487	ASSERT(LLONG_MAX - (long long)arg_value >= summand);
488
489	arg_value += summand;
490
491	if (arg.value >= 0)
492		return (int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
493	else
494		return -(int)(arg_value >> FIXED31_32_BITS_PER_FRACTIONAL_PART);
495}
496
497/* the following two function are used in scaler hw programming to convert fixed
498 * point value to format 2 bits from integer part and 19 bits from fractional
499 * part. The same applies for u0d19, 0 bits from integer part and 19 bits from
500 * fractional
501 */
502
503unsigned int dc_fixpt_u4d19(struct fixed31_32 arg);
 
504
505unsigned int dc_fixpt_u3d19(struct fixed31_32 arg);
 
506
507unsigned int dc_fixpt_u2d19(struct fixed31_32 arg);
508
509unsigned int dc_fixpt_u0d19(struct fixed31_32 arg);
 
510
511unsigned int dc_fixpt_clamp_u0d14(struct fixed31_32 arg);
 
512
513unsigned int dc_fixpt_clamp_u0d10(struct fixed31_32 arg);
514
515int dc_fixpt_s4d19(struct fixed31_32 arg);
516
517static inline struct fixed31_32 dc_fixpt_truncate(struct fixed31_32 arg, unsigned int frac_bits)
518{
519	bool negative = arg.value < 0;
520
521	if (frac_bits >= FIXED31_32_BITS_PER_FRACTIONAL_PART) {
522		ASSERT(frac_bits == FIXED31_32_BITS_PER_FRACTIONAL_PART);
523		return arg;
524	}
525
526	if (negative)
527		arg.value = -arg.value;
528	arg.value &= (~0ULL) << (FIXED31_32_BITS_PER_FRACTIONAL_PART - frac_bits);
529	if (negative)
530		arg.value = -arg.value;
531	return arg;
532}
533
534#endif
v4.17
  1/*
  2 * Copyright 2012-15 Advanced Micro Devices, Inc.
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the "Software"),
  6 * to deal in the Software without restriction, including without limitation
  7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8 * and/or sell copies of the Software, and to permit persons to whom the
  9 * Software is furnished to do so, subject to the following conditions:
 10 *
 11 * The above copyright notice and this permission notice shall be included in
 12 * all 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
 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 20 * OTHER DEALINGS IN THE SOFTWARE.
 21 *
 22 * Authors: AMD
 23 *
 24 */
 25
 26#ifndef __DAL_FIXED31_32_H__
 27#define __DAL_FIXED31_32_H__
 28
 29#include "os_types.h"
 
 
 
 
 
 30
 31#define FIXED31_32_BITS_PER_FRACTIONAL_PART 32
 
 
 
 
 
 
 32
 33/*
 34 * @brief
 35 * Arithmetic operations on real numbers
 36 * represented as fixed-point numbers.
 37 * There are: 1 bit for sign,
 38 * 31 bit for integer part,
 39 * 32 bits for fractional part.
 40 *
 41 * @note
 42 * Currently, overflows and underflows are asserted;
 43 * no special result returned.
 44 */
 45
 46struct fixed31_32 {
 47	int64_t value;
 48};
 49
 
 50/*
 51 * @brief
 52 * Useful constants
 53 */
 54
 55static const struct fixed31_32 dal_fixed31_32_zero = { 0 };
 56static const struct fixed31_32 dal_fixed31_32_epsilon = { 1LL };
 57static const struct fixed31_32 dal_fixed31_32_half = { 0x80000000LL };
 58static const struct fixed31_32 dal_fixed31_32_one = { 0x100000000LL };
 59
 60static const struct fixed31_32 dal_fixed31_32_pi = { 13493037705LL };
 61static const struct fixed31_32 dal_fixed31_32_two_pi = { 26986075409LL };
 62static const struct fixed31_32 dal_fixed31_32_e = { 11674931555LL };
 63static const struct fixed31_32 dal_fixed31_32_ln2 = { 2977044471LL };
 64static const struct fixed31_32 dal_fixed31_32_ln2_div_2 = { 1488522236LL };
 65
 66/*
 67 * @brief
 68 * Initialization routines
 69 */
 70
 71/*
 72 * @brief
 73 * result = numerator / denominator
 74 */
 75struct fixed31_32 dal_fixed31_32_from_fraction(
 76	int64_t numerator,
 77	int64_t denominator);
 78
 79/*
 80 * @brief
 81 * result = arg
 82 */
 83struct fixed31_32 dal_fixed31_32_from_int_nonconst(int64_t arg);
 84static inline struct fixed31_32 dal_fixed31_32_from_int(int64_t arg)
 85{
 86	if (__builtin_constant_p(arg)) {
 87		struct fixed31_32 res;
 88		BUILD_BUG_ON((LONG_MIN > arg) || (arg > LONG_MAX));
 89		res.value = arg << FIXED31_32_BITS_PER_FRACTIONAL_PART;
 90		return res;
 91	} else
 92		return dal_fixed31_32_from_int_nonconst(arg);
 93}
 94
 95/*
 96 * @brief
 97 * Unary operators
 98 */
 99
100/*
101 * @brief
102 * result = -arg
103 */
104static inline struct fixed31_32 dal_fixed31_32_neg(struct fixed31_32 arg)
105{
106	struct fixed31_32 res;
107
108	res.value = -arg.value;
109
110	return res;
111}
112
113/*
114 * @brief
115 * result = abs(arg) := (arg >= 0) ? arg : -arg
116 */
117static inline struct fixed31_32 dal_fixed31_32_abs(struct fixed31_32 arg)
118{
119	if (arg.value < 0)
120		return dal_fixed31_32_neg(arg);
121	else
122		return arg;
123}
124
125/*
126 * @brief
127 * Binary relational operators
128 */
129
130/*
131 * @brief
132 * result = arg1 < arg2
133 */
134static inline bool dal_fixed31_32_lt(struct fixed31_32 arg1,
135				     struct fixed31_32 arg2)
136{
137	return arg1.value < arg2.value;
138}
139
140/*
141 * @brief
142 * result = arg1 <= arg2
143 */
144static inline bool dal_fixed31_32_le(struct fixed31_32 arg1,
145				     struct fixed31_32 arg2)
146{
147	return arg1.value <= arg2.value;
148}
149
150/*
151 * @brief
152 * result = arg1 == arg2
153 */
154static inline bool dal_fixed31_32_eq(struct fixed31_32 arg1,
155				     struct fixed31_32 arg2)
156{
157	return arg1.value == arg2.value;
158}
159
160/*
161 * @brief
162 * result = min(arg1, arg2) := (arg1 <= arg2) ? arg1 : arg2
163 */
164static inline struct fixed31_32 dal_fixed31_32_min(struct fixed31_32 arg1,
165						   struct fixed31_32 arg2)
166{
167	if (arg1.value <= arg2.value)
168		return arg1;
169	else
170		return arg2;
171}
172
173/*
174 * @brief
175 * result = max(arg1, arg2) := (arg1 <= arg2) ? arg2 : arg1
176 */
177static inline struct fixed31_32 dal_fixed31_32_max(struct fixed31_32 arg1,
178						   struct fixed31_32 arg2)
179{
180	if (arg1.value <= arg2.value)
181		return arg2;
182	else
183		return arg1;
184}
185
186/*
187 * @brief
188 *          | min_value, when arg <= min_value
189 * result = | arg, when min_value < arg < max_value
190 *          | max_value, when arg >= max_value
191 */
192static inline struct fixed31_32 dal_fixed31_32_clamp(
193	struct fixed31_32 arg,
194	struct fixed31_32 min_value,
195	struct fixed31_32 max_value)
196{
197	if (dal_fixed31_32_le(arg, min_value))
198		return min_value;
199	else if (dal_fixed31_32_le(max_value, arg))
200		return max_value;
201	else
202		return arg;
203}
204
205/*
206 * @brief
207 * Binary shift operators
208 */
209
210/*
211 * @brief
212 * result = arg << shift
213 */
214struct fixed31_32 dal_fixed31_32_shl(
215	struct fixed31_32 arg,
216	uint8_t shift);
 
 
 
 
 
 
217
218/*
219 * @brief
220 * result = arg >> shift
221 */
222static inline struct fixed31_32 dal_fixed31_32_shr(
223	struct fixed31_32 arg,
224	uint8_t shift)
225{
226	struct fixed31_32 res;
227	res.value = arg.value >> shift;
228	return res;
 
 
 
 
 
229}
230
231/*
232 * @brief
233 * Binary additive operators
234 */
235
236/*
237 * @brief
238 * result = arg1 + arg2
239 */
240struct fixed31_32 dal_fixed31_32_add(
241	struct fixed31_32 arg1,
242	struct fixed31_32 arg2);
 
 
 
 
 
 
 
 
243
244/*
245 * @brief
246 * result = arg1 + arg2
247 */
248static inline struct fixed31_32 dal_fixed31_32_add_int(struct fixed31_32 arg1,
249						       int32_t arg2)
250{
251	return dal_fixed31_32_add(arg1,
252				  dal_fixed31_32_from_int(arg2));
253}
254
255/*
256 * @brief
257 * result = arg1 - arg2
258 */
259struct fixed31_32 dal_fixed31_32_sub(
260	struct fixed31_32 arg1,
261	struct fixed31_32 arg2);
 
 
 
 
 
 
 
 
262
263/*
264 * @brief
265 * result = arg1 - arg2
266 */
267static inline struct fixed31_32 dal_fixed31_32_sub_int(struct fixed31_32 arg1,
268						       int32_t arg2)
269{
270	return dal_fixed31_32_sub(arg1,
271				  dal_fixed31_32_from_int(arg2));
272}
273
274
275/*
276 * @brief
277 * Binary multiplicative operators
278 */
279
280/*
281 * @brief
282 * result = arg1 * arg2
283 */
284struct fixed31_32 dal_fixed31_32_mul(
285	struct fixed31_32 arg1,
286	struct fixed31_32 arg2);
287
288
289/*
290 * @brief
291 * result = arg1 * arg2
292 */
293static inline struct fixed31_32 dal_fixed31_32_mul_int(struct fixed31_32 arg1,
294						       int32_t arg2)
295{
296	return dal_fixed31_32_mul(arg1,
297				  dal_fixed31_32_from_int(arg2));
298}
299
300/*
301 * @brief
302 * result = square(arg) := arg * arg
303 */
304struct fixed31_32 dal_fixed31_32_sqr(
305	struct fixed31_32 arg);
306
307/*
308 * @brief
309 * result = arg1 / arg2
310 */
311static inline struct fixed31_32 dal_fixed31_32_div_int(struct fixed31_32 arg1,
312						       int64_t arg2)
313{
314	return dal_fixed31_32_from_fraction(arg1.value,
315					    dal_fixed31_32_from_int(arg2).value);
316}
317
318/*
319 * @brief
320 * result = arg1 / arg2
321 */
322static inline struct fixed31_32 dal_fixed31_32_div(struct fixed31_32 arg1,
323						   struct fixed31_32 arg2)
324{
325	return dal_fixed31_32_from_fraction(arg1.value,
326					    arg2.value);
327}
328
329/*
330 * @brief
331 * Reciprocal function
332 */
333
334/*
335 * @brief
336 * result = reciprocal(arg) := 1 / arg
337 *
338 * @note
339 * No special actions taken in case argument is zero.
340 */
341struct fixed31_32 dal_fixed31_32_recip(
342	struct fixed31_32 arg);
343
344/*
345 * @brief
346 * Trigonometric functions
347 */
348
349/*
350 * @brief
351 * result = sinc(arg) := sin(arg) / arg
352 *
353 * @note
354 * Argument specified in radians,
355 * internally it's normalized to [-2pi...2pi] range.
356 */
357struct fixed31_32 dal_fixed31_32_sinc(
358	struct fixed31_32 arg);
359
360/*
361 * @brief
362 * result = sin(arg)
363 *
364 * @note
365 * Argument specified in radians,
366 * internally it's normalized to [-2pi...2pi] range.
367 */
368struct fixed31_32 dal_fixed31_32_sin(
369	struct fixed31_32 arg);
370
371/*
372 * @brief
373 * result = cos(arg)
374 *
375 * @note
376 * Argument specified in radians
377 * and should be in [-2pi...2pi] range -
378 * passing arguments outside that range
379 * will cause incorrect result!
380 */
381struct fixed31_32 dal_fixed31_32_cos(
382	struct fixed31_32 arg);
383
384/*
385 * @brief
386 * Transcendent functions
387 */
388
389/*
390 * @brief
391 * result = exp(arg)
392 *
393 * @note
394 * Currently, function is verified for abs(arg) <= 1.
395 */
396struct fixed31_32 dal_fixed31_32_exp(
397	struct fixed31_32 arg);
398
399/*
400 * @brief
401 * result = log(arg)
402 *
403 * @note
404 * Currently, abs(arg) should be less than 1.
405 * No normalization is done.
406 * Currently, no special actions taken
407 * in case of invalid argument(s). Take care!
408 */
409struct fixed31_32 dal_fixed31_32_log(
410	struct fixed31_32 arg);
411
412/*
413 * @brief
414 * Power function
415 */
416
417/*
418 * @brief
419 * result = pow(arg1, arg2)
420 *
421 * @note
422 * Currently, abs(arg1) should be less than 1. Take care!
423 */
424struct fixed31_32 dal_fixed31_32_pow(
425	struct fixed31_32 arg1,
426	struct fixed31_32 arg2);
 
 
 
 
 
 
 
427
428/*
429 * @brief
430 * Rounding functions
431 */
432
433/*
434 * @brief
435 * result = floor(arg) := greatest integer lower than or equal to arg
436 */
437int32_t dal_fixed31_32_floor(
438	struct fixed31_32 arg);
 
 
 
 
 
 
 
439
440/*
441 * @brief
442 * result = round(arg) := integer nearest to arg
443 */
444int32_t dal_fixed31_32_round(
445	struct fixed31_32 arg);
 
 
 
 
 
 
 
 
 
 
 
 
 
446
447/*
448 * @brief
449 * result = ceil(arg) := lowest integer greater than or equal to arg
450 */
451int32_t dal_fixed31_32_ceil(
452	struct fixed31_32 arg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
453
454/* the following two function are used in scaler hw programming to convert fixed
455 * point value to format 2 bits from integer part and 19 bits from fractional
456 * part. The same applies for u0d19, 0 bits from integer part and 19 bits from
457 * fractional
458 */
459
460uint32_t dal_fixed31_32_u2d19(
461	struct fixed31_32 arg);
462
463uint32_t dal_fixed31_32_u0d19(
464	struct fixed31_32 arg);
465
 
466
467uint32_t dal_fixed31_32_clamp_u0d14(
468	struct fixed31_32 arg);
469
470uint32_t dal_fixed31_32_clamp_u0d10(
471	struct fixed31_32 arg);
472
473int32_t dal_fixed31_32_s4d19(
474	struct fixed31_32 arg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
476#endif