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
31 #ifdef INLINE_ISP_OP2W
32 #define STORAGE_CLASS_ISP_OP2W_FUNC_H static inline
33 #define STORAGE_CLASS_ISP_OP2W_DATA_H static inline_DATA
34 #else /* INLINE_ISP_OP2W */
35 #define STORAGE_CLASS_ISP_OP2W_FUNC_H extern
36 #define STORAGE_CLASS_ISP_OP2W_DATA_H extern_DATA
37 #endif /* INLINE_ISP_OP2W */
40 * Double-precision data type specification
43 #include "isp_op2w_types.h"
46 * Double-precision prototype specification
53 * @param[in] _a first argument
54 * @param[in] _b second argument
56 * @return bitwise and of both input arguments
58 * This function will calculate the bitwise and.
61 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_and(
67 * @param[in] _a first argument
68 * @param[in] _b second argument
70 * @return bitwise or of both input arguments
72 * This function will calculate the bitwise or.
75 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_or(
81 * @param[in] _a first argument
82 * @param[in] _b second argument
84 * @return bitwise xor of both input arguments
86 * This function will calculate the bitwise xor.
89 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_xor(
93 /* @brief bitwise inverse
95 * @param[in] _a first argument
97 * @return bitwise inverse of both input arguments
99 * This function will calculate the bitwise inverse.
102 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_inv(
109 * @param[in] _a first argument
110 * @param[in] _b second argument
112 * @return sum of both input arguments
114 * This function will calculate the sum of the input arguments.
115 * in case of overflow it will wrap around.
118 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_add(
122 /* @brief subtraction
124 * @param[in] _a first argument
125 * @param[in] _b second argument
127 * @return _b subtracted from _a.
129 * This function will subtract _b from _a.
130 * in case of overflow it will wrap around.
133 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_sub(
137 /* @brief saturated addition
139 * @param[in] _a first argument
140 * @param[in] _b second argument
142 * @return saturated sum of both input arguments
144 * This function will calculate the sum of the input arguments.
145 * in case of overflow it will saturate
146 * result = CLIP(_a + _b, MIN_RANGE, MAX_RANGE);
148 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_addsat(
152 /* @brief saturated subtraction
154 * @param[in] _a first argument
155 * @param[in] _b second argument
157 * @return saturated subtraction of both input arguments
159 * This function will subtract _b from _a.
160 * in case of overflow it will saturate
161 * result = CLIP(_a - _b, MIN_RANGE, MAX_RANGE);
163 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subsat(
167 /* @brief subtraction with shift right and rounding
169 * @param[in] _a first argument
170 * @param[in] _b second argument
172 * @return (a - b) >> 1
174 * This function subtracts _b from _a and right shifts
175 * the result by 1 bit with rounding.
176 * No overflow can occur.
177 * result = (_a - _b) >> 1
179 * Note: This function will be deprecated due to
180 * the naming confusion and it will be replaced
181 * by "OP_2w_subhalfrnd".
183 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subasr1(
187 /* @brief Subtraction with shift right and rounding
189 * @param[in] _a first operand
190 * @param[in] _b second operand
192 * @return (_a - _b) >> 1
194 * This function subtracts _b from _a and right shifts
195 * the result by 1 bit with rounding.
196 * No overflow can occur.
198 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subhalfrnd(
202 /* @brief Subtraction with shift right and no rounding
204 * @param[in] _a first operand
205 * @param[in] _b second operand
207 * @return (_a - _b) >> 1
209 * This function subtracts _b from _a and right shifts
210 * the result by 1 bit without rounding (i.e. truncation).
211 * No overflow can occur.
213 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subhalf(
217 /* @brief saturated absolute value
219 * @param[in] _a input
221 * @return saturated absolute value of the input
223 * This function will calculate the saturated absolute value of the input.
224 * In case of overflow it will saturate.
225 * if (_a > 0) return _a;<br>
226 * else return CLIP(-_a, MIN_RANGE, MAX_RANGE);<br>
228 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_abs(
231 /* @brief saturated absolute difference
233 * @param[in] _a first argument
234 * @param[in] _b second argument
236 * @return sat(abs(sat(a-b)));
238 * This function will calculate the saturated absolute value
239 * of the saturated difference of both inputs.
240 * result = sat(abs(sat(_a - _b)));
242 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subabssat(
248 /* @brief integer multiply
250 * @param[in] _a first argument
251 * @param[in] _b second argument
253 * @return product of _a and _b
255 * This function will calculate the product
256 * of the input arguments and returns the LSB
257 * aligned double precision result.
258 * In case of overflow it will wrap around.
261 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mul(
265 /* @brief fractional saturating multiply
267 * @param[in] _a first argument
268 * @param[in] _b second argument
270 * @return saturated product of _a and _b
272 * This function will calculate the fixed point
273 * product of the input arguments
274 * and returns a double precision result.
275 * In case of overflow it will saturate.
276 * result =((_a * _b) << 1) >> (2*NUM_BITS);
278 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_qmul(
282 /* @brief fractional saturating multiply with rounding
284 * @param[in] _a first argument
285 * @param[in] _b second argument
287 * @return product of _a and _b
289 * This function will calculate the fixed point
290 * product of the input arguments
291 * and returns a double precision result.
292 * Depending on the rounding mode of the core
293 * it will round to nearest or to nearest even.
294 * In case of overflow it will saturate.
295 * result = ((_a * _b) << 1) >> (2*NUM_BITS);
298 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_qrmul(
306 * @param[in] _a first argument
307 * @param[in] _b second argument
311 * This function will return true if both inputs
312 * are equal, and false if not equal.
314 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_eq(
320 * @param[in] _a first argument
321 * @param[in] _b second argument
325 * This function will return false if both inputs
326 * are equal, and true if not equal.
328 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_ne(
332 /* @brief less or equal
334 * @param[in] _a first argument
335 * @param[in] _b second argument
339 * This function will return true if _a is smaller
342 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_le(
348 * @param[in] _a first argument
349 * @param[in] _b second argument
353 * This function will return true if _a is smaller
356 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_lt(
360 /* @brief greater or equal
362 * @param[in] _a first argument
363 * @param[in] _b second argument
367 * This function will return true if _a is greater
370 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_ge(
374 /* @brief greater than
376 * @param[in] _a first argument
377 * @param[in] _b second argument
381 * This function will return true if _a is greater
384 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_gt(
390 /* @brief aritmetic shift right
392 * @param[in] _a input
393 * @param[in] _b shift amount
397 * This function will shift _a with _b bits to the right,
398 * preserving the sign bit.
399 * It asserts 0 <= _b <= MAX_SHIFT_2W.
400 * The operation count for this function assumes that
401 * the shift amount is a cloned scalar input.
403 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asr(
407 /* @brief aritmetic shift right with rounding
409 * @param[in] _a input
410 * @param[in] _b shift amount
414 * If _b < 2*NUM_BITS, this function will shift _a with _b bits to the right,
415 * preserving the sign bit, and depending on the rounding mode of the core
416 * it will round to nearest or to nearest even.
417 * If _b >= 2*NUM_BITS, this function will return 0.
418 * It asserts 0 <= _b <= MAX_SHIFT_2W.
419 * The operation count for this function assumes that
420 * the shift amount is a cloned scalar input.
422 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asrrnd(
426 /* @brief saturating aritmetic shift left
428 * @param[in] _a input
429 * @param[in] _b shift amount
433 * If _b < MAX_BITDEPTH, this function will shift _a with _b bits to the left,
434 * saturating at MIN_RANGE/MAX_RANGE in case of overflow.
435 * If _b >= MAX_BITDEPTH, this function will return MIN_RANGE if _a < 0,
436 * MAX_RANGE if _a > 0, 0 if _a == 0.
437 * (with MAX_BITDEPTH=64)
438 * It asserts 0 <= _b <= MAX_SHIFT_2W.
439 * The operation count for this function assumes that
440 * the shift amount is a cloned scalar input.
442 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asl(
446 /* @brief saturating aritmetic shift left
448 * @param[in] _a input
449 * @param[in] _b shift amount
453 * This function is identical to OP_2w_asl( )
455 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_aslsat(
459 /* @brief logical shift left
461 * @param[in] _a input
462 * @param[in] _b shift amount
466 * This function will shift _a with _b bits to the left.
467 * It will insert zeroes on the right.
468 * It asserts 0 <= _b <= MAX_SHIFT_2W.
469 * The operation count for this function assumes that
470 * the shift amount is a cloned scalar input.
472 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_lsl(
476 /* @brief logical shift right
478 * @param[in] _a input
479 * @param[in] _b shift amount
483 * This function will shift _a with _b bits to the right.
484 * It will insert zeroes on the left.
485 * It asserts 0 <= _b <= MAX_SHIFT_2W.
486 * The operation count for this function assumes that
487 * the shift amount is a cloned scalar input.
489 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_lsr(
495 /* @brief Clip asymmetrical
497 * @param[in] _a first argument
498 * @param[in] _b second argument
500 * @return _a clipped between ~_b and b
502 * This function will clip the first argument between
504 * It asserts _b >= 0.
506 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_clip_asym(
512 * @param[in] _a first argument
513 * @param[in] _b second argument
515 * @return _a clipped beteween 0 and _b
517 * This function will clip the first argument between
519 * It asserts _b >= 0.
521 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_clipz(
527 /* @brief Truncated division
529 * @param[in] _a first argument
530 * @param[in] _b second argument
532 * @return trunc( _a / _b )
534 * This function will divide the first argument by
535 * the second argument, with rounding toward 0.
536 * If _b == 0 and _a < 0, the function will return MIN_RANGE.
537 * If _b == 0 and _a == 0, the function will return 0.
538 * If _b == 0 and _a > 0, the function will return MAX_RANGE.
540 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_div(
544 /* @brief Saturating truncated division
546 * @param[in] _a first argument
547 * @param[in] _b second argument
549 * @return CLIP( trunc( _a / _b ), MIN_RANGE1w, MAX_RANGE1w )
551 * This function will divide the first argument by
552 * the second argument, with rounding toward 0, and
553 * saturate the result to the range of single precision.
554 * If _b == 0 and _a < 0, the function will return MIN_RANGE.
555 * If _b == 0 and _a == 0, the function will return 0.
556 * If _b == 0 and _a > 0, the function will return MAX_RANGE.
558 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector1w OP_2w_divh(
564 * @param[in] _a first argument
565 * @param[in] _b second argument
569 * This function has not yet been implemented.
571 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mod(
575 /* @brief Unsigned Integer Square root
577 * @param[in] _a input
579 * @return square root of _a
581 * This function will calculate the unsigned integer square root of _a
583 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector1w_unsigned OP_2w_sqrt_u(
584 const tvector2w_unsigned _a);
588 /* @brief Multiplexer
590 * @param[in] _a first argument
591 * @param[in] _b second argument
592 * @param[in] _c condition
594 * @return _c ? _a : _b
596 * This function will return _a if the condition _c
597 * is true and _b otherwise.
599 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mux(
604 /* @brief Average without rounding
606 * @param[in] _a first operand
607 * @param[in] _b second operand
609 * @return (_a + _b) >> 1
611 * This function will add _a and _b, and right shift
612 * the result by one without rounding. No overflow
613 * will occur because addition is performed in the
616 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_avg(
620 /* @brief Average with rounding
622 * @param[in] _a first argument
623 * @param[in] _b second argument
625 * @return (_a + _b) >> 1
627 * This function will add _a and _b at full precision,
628 * and right shift with rounding the result with 1 bit.
629 * Depending on the rounding mode of the core
630 * it will round to nearest or to nearest even.
632 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_avgrnd(
638 * @param[in] _a first argument
639 * @param[in] _b second argument
641 * @return (_a < _b) ? _a : _b;
643 * This function will return the smallest of both
646 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_min(
652 * @param[in] _a first argument
653 * @param[in] _b second argument
655 * @return (_a > _b) ? _a : _b;
657 * This function will return the largest of both
660 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_max(
664 #ifndef INLINE_ISP_OP2W
665 #define STORAGE_CLASS_ISP_OP2W_FUNC_C
666 #define STORAGE_CLASS_ISP_OP2W_DATA_C const
667 #else /* INLINE_ISP_OP2W */
668 #define STORAGE_CLASS_ISP_OP2W_FUNC_C STORAGE_CLASS_ISP_OP2W_FUNC_H
669 #define STORAGE_CLASS_ISP_OP2W_DATA_C STORAGE_CLASS_ISP_OP2W_DATA_H
670 #include "isp_op2w.c"
671 #define ISP_OP2W_INLINED
672 #endif /* INLINE_ISP_OP2W */
674 #endif /* __ISP_OP2W_H_INCLUDED__ */