2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #ifndef __ISP_OP2W_H_INCLUDED__
16 #define __ISP_OP2W_H_INCLUDED__
19 * This file is part of the Multi-precision vector operations exstension package.
23 * Double-precision vector operations
30 #include "storage_class.h"
32 #ifdef INLINE_ISP_OP2W
33 #define STORAGE_CLASS_ISP_OP2W_FUNC_H STORAGE_CLASS_INLINE
34 #define STORAGE_CLASS_ISP_OP2W_DATA_H STORAGE_CLASS_INLINE_DATA
35 #else /* INLINE_ISP_OP2W */
36 #define STORAGE_CLASS_ISP_OP2W_FUNC_H STORAGE_CLASS_EXTERN
37 #define STORAGE_CLASS_ISP_OP2W_DATA_H STORAGE_CLASS_EXTERN_DATA
38 #endif /* INLINE_ISP_OP2W */
41 * Double-precision data type specification
44 #include "isp_op2w_types.h"
47 * Double-precision prototype specification
52 /** @brief bitwise AND
54 * @param[in] _a first argument
55 * @param[in] _b second argument
57 * @return bitwise and of both input arguments
59 * This function will calculate the bitwise and.
62 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_and(
68 * @param[in] _a first argument
69 * @param[in] _b second argument
71 * @return bitwise or of both input arguments
73 * This function will calculate the bitwise or.
76 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_or(
80 /** @brief bitwise XOR
82 * @param[in] _a first argument
83 * @param[in] _b second argument
85 * @return bitwise xor of both input arguments
87 * This function will calculate the bitwise xor.
90 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_xor(
94 /** @brief bitwise inverse
96 * @param[in] _a first argument
98 * @return bitwise inverse of both input arguments
100 * This function will calculate the bitwise inverse.
103 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_inv(
110 * @param[in] _a first argument
111 * @param[in] _b second argument
113 * @return sum of both input arguments
115 * This function will calculate the sum of the input arguments.
116 * in case of overflow it will wrap around.
119 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_add(
123 /** @brief subtraction
125 * @param[in] _a first argument
126 * @param[in] _b second argument
128 * @return _b subtracted from _a.
130 * This function will subtract _b from _a.
131 * in case of overflow it will wrap around.
134 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_sub(
138 /** @brief saturated addition
140 * @param[in] _a first argument
141 * @param[in] _b second argument
143 * @return saturated sum of both input arguments
145 * This function will calculate the sum of the input arguments.
146 * in case of overflow it will saturate
147 * result = CLIP(_a + _b, MIN_RANGE, MAX_RANGE);
149 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_addsat(
153 /** @brief saturated subtraction
155 * @param[in] _a first argument
156 * @param[in] _b second argument
158 * @return saturated subtraction of both input arguments
160 * This function will subtract _b from _a.
161 * in case of overflow it will saturate
162 * result = CLIP(_a - _b, MIN_RANGE, MAX_RANGE);
164 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subsat(
168 /** @brief subtraction with shift right and rounding
170 * @param[in] _a first argument
171 * @param[in] _b second argument
173 * @return (a - b) >> 1
175 * This function subtracts _b from _a and right shifts
176 * the result by 1 bit with rounding.
177 * No overflow can occur.
178 * result = (_a - _b) >> 1
180 * Note: This function will be deprecated due to
181 * the naming confusion and it will be replaced
182 * by "OP_2w_subhalfrnd".
184 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subasr1(
188 /** @brief Subtraction with shift right and rounding
190 * @param[in] _a first operand
191 * @param[in] _b second operand
193 * @return (_a - _b) >> 1
195 * This function subtracts _b from _a and right shifts
196 * the result by 1 bit with rounding.
197 * No overflow can occur.
199 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subhalfrnd(
203 /** @brief Subtraction with shift right and no rounding
205 * @param[in] _a first operand
206 * @param[in] _b second operand
208 * @return (_a - _b) >> 1
210 * This function subtracts _b from _a and right shifts
211 * the result by 1 bit without rounding (i.e. truncation).
212 * No overflow can occur.
214 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subhalf(
218 /** @brief saturated absolute value
220 * @param[in] _a input
222 * @return saturated absolute value of the input
224 * This function will calculate the saturated absolute value of the input.
225 * In case of overflow it will saturate.
226 * if (_a > 0) return _a;<br>
227 * else return CLIP(-_a, MIN_RANGE, MAX_RANGE);<br>
229 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_abs(
232 /** @brief saturated absolute difference
234 * @param[in] _a first argument
235 * @param[in] _b second argument
237 * @return sat(abs(sat(a-b)));
239 * This function will calculate the saturated absolute value
240 * of the saturated difference of both inputs.
241 * result = sat(abs(sat(_a - _b)));
243 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subabssat(
249 /** @brief integer multiply
251 * @param[in] _a first argument
252 * @param[in] _b second argument
254 * @return product of _a and _b
256 * This function will calculate the product
257 * of the input arguments and returns the LSB
258 * aligned double precision result.
259 * In case of overflow it will wrap around.
262 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mul(
266 /** @brief fractional saturating multiply
268 * @param[in] _a first argument
269 * @param[in] _b second argument
271 * @return saturated product of _a and _b
273 * This function will calculate the fixed point
274 * product of the input arguments
275 * and returns a double precision result.
276 * In case of overflow it will saturate.
277 * result =((_a * _b) << 1) >> (2*NUM_BITS);
279 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_qmul(
283 /** @brief fractional saturating multiply with rounding
285 * @param[in] _a first argument
286 * @param[in] _b second argument
288 * @return product of _a and _b
290 * This function will calculate the fixed point
291 * product of the input arguments
292 * and returns a double precision result.
293 * Depending on the rounding mode of the core
294 * it will round to nearest or to nearest even.
295 * In case of overflow it will saturate.
296 * result = ((_a * _b) << 1) >> (2*NUM_BITS);
299 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_qrmul(
307 * @param[in] _a first argument
308 * @param[in] _b second argument
312 * This function will return true if both inputs
313 * are equal, and false if not equal.
315 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_eq(
321 * @param[in] _a first argument
322 * @param[in] _b second argument
326 * This function will return false if both inputs
327 * are equal, and true if not equal.
329 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_ne(
333 /** @brief less or equal
335 * @param[in] _a first argument
336 * @param[in] _b second argument
340 * This function will return true if _a is smaller
343 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_le(
349 * @param[in] _a first argument
350 * @param[in] _b second argument
354 * This function will return true if _a is smaller
357 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_lt(
361 /** @brief greater or equal
363 * @param[in] _a first argument
364 * @param[in] _b second argument
368 * This function will return true if _a is greater
371 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_ge(
375 /** @brief greater than
377 * @param[in] _a first argument
378 * @param[in] _b second argument
382 * This function will return true if _a is greater
385 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_gt(
391 /** @brief aritmetic shift right
393 * @param[in] _a input
394 * @param[in] _b shift amount
398 * This function will shift _a with _b bits to the right,
399 * preserving the sign bit.
400 * It asserts 0 <= _b <= MAX_SHIFT_2W.
401 * The operation count for this function assumes that
402 * the shift amount is a cloned scalar input.
404 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asr(
408 /** @brief aritmetic shift right with rounding
410 * @param[in] _a input
411 * @param[in] _b shift amount
415 * If _b < 2*NUM_BITS, this function will shift _a with _b bits to the right,
416 * preserving the sign bit, and depending on the rounding mode of the core
417 * it will round to nearest or to nearest even.
418 * If _b >= 2*NUM_BITS, this function will return 0.
419 * It asserts 0 <= _b <= MAX_SHIFT_2W.
420 * The operation count for this function assumes that
421 * the shift amount is a cloned scalar input.
423 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asrrnd(
427 /** @brief saturating aritmetic shift left
429 * @param[in] _a input
430 * @param[in] _b shift amount
434 * If _b < MAX_BITDEPTH, this function will shift _a with _b bits to the left,
435 * saturating at MIN_RANGE/MAX_RANGE in case of overflow.
436 * If _b >= MAX_BITDEPTH, this function will return MIN_RANGE if _a < 0,
437 * MAX_RANGE if _a > 0, 0 if _a == 0.
438 * (with MAX_BITDEPTH=64)
439 * It asserts 0 <= _b <= MAX_SHIFT_2W.
440 * The operation count for this function assumes that
441 * the shift amount is a cloned scalar input.
443 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asl(
447 /** @brief saturating aritmetic shift left
449 * @param[in] _a input
450 * @param[in] _b shift amount
454 * This function is identical to OP_2w_asl( )
456 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_aslsat(
460 /** @brief logical shift left
462 * @param[in] _a input
463 * @param[in] _b shift amount
467 * This function will shift _a with _b bits to the left.
468 * It will insert zeroes on the right.
469 * It asserts 0 <= _b <= MAX_SHIFT_2W.
470 * The operation count for this function assumes that
471 * the shift amount is a cloned scalar input.
473 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_lsl(
477 /** @brief logical shift right
479 * @param[in] _a input
480 * @param[in] _b shift amount
484 * This function will shift _a with _b bits to the right.
485 * It will insert zeroes on the left.
486 * It asserts 0 <= _b <= MAX_SHIFT_2W.
487 * The operation count for this function assumes that
488 * the shift amount is a cloned scalar input.
490 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_lsr(
496 /** @brief Clip asymmetrical
498 * @param[in] _a first argument
499 * @param[in] _b second argument
501 * @return _a clipped between ~_b and b
503 * This function will clip the first argument between
505 * It asserts _b >= 0.
507 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_clip_asym(
513 * @param[in] _a first argument
514 * @param[in] _b second argument
516 * @return _a clipped beteween 0 and _b
518 * This function will clip the first argument between
520 * It asserts _b >= 0.
522 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_clipz(
528 /** @brief Truncated division
530 * @param[in] _a first argument
531 * @param[in] _b second argument
533 * @return trunc( _a / _b )
535 * This function will divide the first argument by
536 * the second argument, with rounding toward 0.
537 * If _b == 0 and _a < 0, the function will return MIN_RANGE.
538 * If _b == 0 and _a == 0, the function will return 0.
539 * If _b == 0 and _a > 0, the function will return MAX_RANGE.
541 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_div(
545 /** @brief Saturating truncated division
547 * @param[in] _a first argument
548 * @param[in] _b second argument
550 * @return CLIP( trunc( _a / _b ), MIN_RANGE1w, MAX_RANGE1w )
552 * This function will divide the first argument by
553 * the second argument, with rounding toward 0, and
554 * saturate the result to the range of single precision.
555 * If _b == 0 and _a < 0, the function will return MIN_RANGE.
556 * If _b == 0 and _a == 0, the function will return 0.
557 * If _b == 0 and _a > 0, the function will return MAX_RANGE.
559 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector1w OP_2w_divh(
565 * @param[in] _a first argument
566 * @param[in] _b second argument
570 * This function has not yet been implemented.
572 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mod(
576 /** @brief Unsigned Integer Square root
578 * @param[in] _a input
580 * @return square root of _a
582 * This function will calculate the unsigned integer square root of _a
584 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector1w_unsigned OP_2w_sqrt_u(
585 const tvector2w_unsigned _a);
589 /** @brief Multiplexer
591 * @param[in] _a first argument
592 * @param[in] _b second argument
593 * @param[in] _c condition
595 * @return _c ? _a : _b
597 * This function will return _a if the condition _c
598 * is true and _b otherwise.
600 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mux(
605 /** @brief Average without rounding
607 * @param[in] _a first operand
608 * @param[in] _b second operand
610 * @return (_a + _b) >> 1
612 * This function will add _a and _b, and right shift
613 * the result by one without rounding. No overflow
614 * will occur because addition is performed in the
617 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_avg(
621 /** @brief Average with rounding
623 * @param[in] _a first argument
624 * @param[in] _b second argument
626 * @return (_a + _b) >> 1
628 * This function will add _a and _b at full precision,
629 * and right shift with rounding the result with 1 bit.
630 * Depending on the rounding mode of the core
631 * it will round to nearest or to nearest even.
633 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_avgrnd(
639 * @param[in] _a first argument
640 * @param[in] _b second argument
642 * @return (_a < _b) ? _a : _b;
644 * This function will return the smallest of both
647 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_min(
653 * @param[in] _a first argument
654 * @param[in] _b second argument
656 * @return (_a > _b) ? _a : _b;
658 * This function will return the largest of both
661 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_max(
665 #ifndef INLINE_ISP_OP2W
666 #define STORAGE_CLASS_ISP_OP2W_FUNC_C
667 #define STORAGE_CLASS_ISP_OP2W_DATA_C const
668 #else /* INLINE_ISP_OP2W */
669 #define STORAGE_CLASS_ISP_OP2W_FUNC_C STORAGE_CLASS_ISP_OP2W_FUNC_H
670 #define STORAGE_CLASS_ISP_OP2W_DATA_C STORAGE_CLASS_ISP_OP2W_DATA_H
671 #include "isp_op2w.c"
672 #define ISP_OP2W_INLINED
673 #endif /* INLINE_ISP_OP2W */
675 #endif /* __ISP_OP2W_H_INCLUDED__ */