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_OP1W_H_INCLUDED__
16 #define __ISP_OP1W_H_INCLUDED__
19 * This file is part of the Multi-precision vector operations exstension package.
23 * Single-precision vector operations
30 #include "storage_class.h"
32 #ifdef INLINE_ISP_OP1W
33 #define STORAGE_CLASS_ISP_OP1W_FUNC_H STORAGE_CLASS_INLINE
34 #define STORAGE_CLASS_ISP_OP1W_DATA_H STORAGE_CLASS_INLINE_DATA
35 #else /* INLINE_ISP_OP1W */
36 #define STORAGE_CLASS_ISP_OP1W_FUNC_H STORAGE_CLASS_EXTERN
37 #define STORAGE_CLASS_ISP_OP1W_DATA_H STORAGE_CLASS_EXTERN_DATA
38 #endif /* INLINE_ISP_OP1W */
41 * Single-precision data type specification
44 #include "isp_op1w_types.h"
45 #include "isp_op2w_types.h" // for doubling operations.
48 * Single-precision prototype specification
53 /** @brief bitwise AND
55 * @param[in] _a first argument
56 * @param[in] _b second argument
58 * @return bitwise and of both input arguments
60 * This function will calculate the bitwise and.
63 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_and(
69 * @param[in] _a first argument
70 * @param[in] _b second argument
72 * @return bitwise or of both input arguments
74 * This function will calculate the bitwise or.
77 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_or(
81 /** @brief bitwise XOR
83 * @param[in] _a first argument
84 * @param[in] _b second argument
86 * @return bitwise xor of both input arguments
88 * This function will calculate the bitwise xor.
91 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_xor(
95 /** @brief bitwise inverse
97 * @param[in] _a first argument
99 * @return bitwise inverse of both input arguments
101 * This function will calculate the bitwise inverse.
104 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_inv(
111 * @param[in] _a first argument
112 * @param[in] _b second argument
114 * @return sum of both input arguments
116 * This function will calculate the sum of the input arguments.
117 * in case of overflow it will wrap around.
120 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_add(
124 /** @brief subtraction
126 * @param[in] _a first argument
127 * @param[in] _b second argument
129 * @return _b subtracted from _a.
131 * This function will subtract _b from _a.
132 * in case of overflow it will wrap around.
135 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_sub(
139 /** @brief saturated addition
141 * @param[in] _a first argument
142 * @param[in] _b second argument
144 * @return saturated sum of both input arguments
146 * This function will calculate the sum of the input arguments.
147 * in case of overflow it will saturate.
148 * result = CLIP(_a + _b, MIN_RANGE, MAX_RANGE);
150 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_addsat(
154 /** @brief saturated subtraction
156 * @param[in] _a first argument
157 * @param[in] _b second argument
159 * @return saturated subtraction of both input arguments
161 * This function will subtract _b from _a.
162 * in case of overflow it will saturate.
163 * result = CLIP(_a - _b, MIN_RANGE, MAX_RANGE);
165 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_subsat(
170 /** @brief Unsigned saturated subtraction
172 * @param[in] _a first argument
173 * @param[in] _b second argument
175 * @return saturated subtraction of both input arguments
177 * This function will subtract _b from _a.
178 * in case of overflow it will saturate.
179 * result = CLIP(_a - _b, 0, MAX_RANGE);
181 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w_unsigned OP_1w_subsat_u(
182 const tvector1w_unsigned _a,
183 const tvector1w_unsigned _b);
186 /** @brief subtraction with shift right and rounding
188 * @param[in] _a first argument
189 * @param[in] _b second argument
191 * @return (a - b) >> 1
193 * This function subtracts _b from _a and right shifts
194 * the result by 1 bit with rounding.
195 * No overflow can occur.
196 * result = (_a - _b) >> 1
198 * Note: This function will be deprecated due to
199 * the naming confusion and it will be replaced
200 * by "OP_1w_subhalfrnd".
202 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_subasr1(
206 /** @brief Subtraction with shift right and rounding
208 * @param[in] _a first operand
209 * @param[in] _b second operand
211 * @return (_a - _b) >> 1
213 * This function subtracts _b from _a and right shifts
214 * the result by 1 bit with rounding.
215 * No overflow can occur.
217 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_subhalfrnd(
221 /** @brief Subtraction with shift right and no rounding
223 * @param[in] _a first operand
224 * @param[in] _b second operand
226 * @return (_a - _b) >> 1
228 * This function subtracts _b from _a and right shifts
229 * the result by 1 bit without rounding (i.e. truncation).
230 * No overflow can occur.
232 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_subhalf(
237 /** @brief saturated absolute value
239 * @param[in] _a input
241 * @return saturated absolute value of the input
243 * This function will calculate the saturated absolute value of the input.
244 * in case of overflow it will saturate.
245 * if (_a > 0) return _a;<br>
246 * else return CLIP(-_a, MIN_RANGE, MAX_RANGE);<br>
248 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_abs(
251 /** @brief saturated absolute difference
253 * @param[in] _a first argument
254 * @param[in] _b second argument
256 * @return sat(abs(a-b));
258 * This function will calculate the saturated absolute value
259 * of the saturated difference of both inputs.
260 * result = sat(abs(sat(_a - _b)));
262 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_subabssat(
268 /** @brief doubling multiply
270 * @param[in] _a first argument
271 * @param[in] _b second argument
273 * @return product of _a and _b
275 * This function will calculate the product
276 * of the input arguments and returns a double
278 * No overflow can occur.
281 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector2w OP_1w_muld(
285 /** @brief integer multiply
287 * @param[in] _a first argument
288 * @param[in] _b second argument
290 * @return product of _a and _b
292 * This function will calculate the product
293 * of the input arguments and returns the LSB
294 * aligned single precision result.
295 * In case of overflow it will wrap around.
298 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_mul(
302 /** @brief fractional saturating multiply
304 * @param[in] _a first argument
305 * @param[in] _b second argument
307 * @return saturated product of _a and _b
309 * This function will calculate the fixed point
310 * product of the input arguments
311 * and returns a single precision result.
312 * In case of overflow it will saturate.
313 * FP_UNITY * FP_UNITY => FP_UNITY.
314 * result = CLIP(_a * _b >> (NUM_BITS-1), MIN_RANGE, MAX_RANGE);
316 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_qmul(
320 /** @brief fractional saturating multiply with rounding
322 * @param[in] _a first argument
323 * @param[in] _b second argument
325 * @return product of _a and _b
327 * This function will calculate the fixed point
328 * product of the input arguments
329 * and returns a single precision result.
330 * FP_UNITY * FP_UNITY => FP_UNITY.
331 * Depending on the rounding mode of the core
332 * it will round to nearest or to nearest even.
333 * result = CLIP(_a * _b >> (NUM_BITS-1), MIN_RANGE, MAX_RANGE);
335 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_qrmul(
343 * @param[in] _a first argument
344 * @param[in] _b second argument
348 * This function will return true if both inputs
349 * are equal, and false if not equal.
351 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags OP_1w_eq(
357 * @param[in] _a first argument
358 * @param[in] _b second argument
362 * This function will return false if both inputs
363 * are equal, and true if not equal.
365 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags OP_1w_ne(
369 /** @brief less or equal
371 * @param[in] _a first argument
372 * @param[in] _b second argument
376 * This function will return true if _a is smaller
379 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags OP_1w_le(
385 * @param[in] _a first argument
386 * @param[in] _b second argument
390 * This function will return true if _a is smaller
393 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags OP_1w_lt(
397 /** @brief greater or equal
399 * @param[in] _a first argument
400 * @param[in] _b second argument
404 * This function will return true if _a is greater
407 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags OP_1w_ge(
411 /** @brief greater than
413 * @param[in] _a first argument
414 * @param[in] _b second argument
418 * This function will return true if _a is greater
421 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags OP_1w_gt(
427 /** @brief aritmetic shift right
429 * @param[in] _a input
430 * @param[in] _b shift amount
434 * This function will shift _a with _b bits to the right,
435 * preserving the sign bit.
436 * It asserts 0 <= _b <= MAX_SHIFT_1W.
438 * The operation count for this function assumes that
439 * the shift amount is a cloned scalar input.
441 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_asr(
445 /** @brief aritmetic shift right with rounding
447 * @param[in] _a input
448 * @param[in] _b shift amount
452 * If _b < NUM_BITS, this function will shift _a with _b bits to the right,
453 * preserving the sign bit, and depending on the rounding mode of the core
454 * it will round to nearest or to nearest even.
455 * If _b >= NUM_BITS, this function will return 0.
456 * It asserts 0 <= _b <= MAX_SHIFT_1W.
457 * The operation count for this function assumes that
458 * the shift amount is a cloned scalar input.
460 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_asrrnd(
464 /** @brief saturating arithmetic shift left
466 * @param[in] _a input
467 * @param[in] _b shift amount
471 * If _b < MAX_BITDEPTH, this function will shift _a with _b bits to the left,
472 * saturating at MIN_RANGE/MAX_RANGE in case of overflow.
473 * If _b >= MAX_BITDEPTH, this function will return MIN_RANGE if _a < 0,
474 * MAX_RANGE if _a > 0, 0 if _a == 0.
475 * (with MAX_BITDEPTH=64)
476 * It asserts 0 <= _b <= MAX_SHIFT_1W.
477 * The operation count for this function assumes that
478 * the shift amount is a cloned scalar input.
480 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_asl(
484 /** @brief saturating aritmetic shift left
486 * @param[in] _a input
487 * @param[in] _b shift amount
491 * This function is identical to OP_1w_asl( )
493 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_aslsat(
497 /** @brief logical shift left
499 * @param[in] _a input
500 * @param[in] _b shift amount
504 * This function will shift _a with _b bits to the left.
505 * It will insert zeroes on the right.
506 * It asserts 0 <= _b <= MAX_SHIFT_1W.
507 * The operation count for this function assumes that
508 * the shift amount is a cloned scalar input.
510 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_lsl(
514 /** @brief logical shift right
516 * @param[in] _a input
517 * @param[in] _b shift amount
521 * This function will shift _a with _b bits to the right.
522 * It will insert zeroes on the left.
523 * It asserts 0 <= _b <= MAX_SHIFT_1W.
524 * The operation count for this function assumes that
525 * the shift amount is a cloned scalar input.
527 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_lsr(
532 /** @brief bidirectional saturating arithmetic shift
534 * @param[in] _a input
535 * @param[in] _b shift amount
537 * @return _a << |_b| if _b is positive
538 * _a >> |_b| if _b is negative
540 * If _b > 0, this function will shift _a with _b bits to the left,
541 * saturating at MIN_RANGE/MAX_RANGE in case of overflow.
542 * if _b < 0, this function will shift _a with _b bits to the right.
543 * It asserts -MAX_SHIFT_1W <= _b <= MAX_SHIFT_1W.
544 * If _b = 0, it returns _a.
546 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_ashift_sat(
550 /** @brief bidirectional non-saturating arithmetic shift
552 * @param[in] _a input
553 * @param[in] _b shift amount
555 * @return _a << |_b| if _b is positive
556 * _a >> |_b| if _b is negative
558 * If _b > 0, this function will shift _a with _b bits to the left,
559 * no saturation is performed in case of overflow.
560 * if _b < 0, this function will shift _a with _b bits to the right.
561 * It asserts -MAX_SHIFT_1W <= _b <= MAX_SHIFT_1W.
562 * If _b = 0, it returns _a.
564 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_ashift(
569 /** @brief bidirectional logical shift
571 * @param[in] _a input
572 * @param[in] _b shift amount
574 * @return _a << |_b| if _b is positive
575 * _a >> |_b| if _b is negative
577 * This function will shift _a with _b bits to the left if _b is positive.
578 * This function will shift _a with _b bits to the right if _b is negative.
579 * It asserts -MAX_SHIFT_1W <= _b <= MAX_SHIFT_1W.
580 * It inserts zeros on the left or right depending on the shift direction:
582 * The operation count for this function assumes that
583 * the shift amount is a cloned scalar input.
585 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_lshift(
592 /** @brief Cast from int to 1w
594 * @param[in] _a input
598 * This function casts the input from integer type to
599 * single precision. It asserts there is no overflow.
602 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_int_cast_to_1w(
605 /** @brief Cast from 1w to int
607 * @param[in] _a input
611 * This function casts the input from single precision type to
612 * integer, preserving value and sign.
615 STORAGE_CLASS_ISP_OP1W_FUNC_H int OP_1w_cast_to_int(
618 /** @brief Cast from 1w to 2w
620 * @param[in] _a input
624 * This function casts the input from single precision type to
625 * double precision, preserving value and sign.
628 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector2w OP_1w_cast_to_2w(
631 /** @brief Cast from 2w to 1w
633 * @param[in] _a input
637 * This function casts the input from double precision type to
638 * single precision. In case of overflow it will wrap around.
641 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_2w_cast_to_1w(
645 /** @brief Cast from 2w to 1w with saturation
647 * @param[in] _a input
651 * This function casts the input from double precision type to
652 * single precision after saturating it to the range of single
656 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_2w_sat_cast_to_1w(
661 /** @brief Clip asymmetrical
663 * @param[in] _a first argument
664 * @param[in] _b second argument
666 * @return _a clipped between ~_b and b
668 * This function will clip the first argument between
670 * It asserts _b >= 0.
673 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_clip_asym(
679 * @param[in] _a first argument
680 * @param[in] _b second argument
682 * @return _a clipped beteween 0 and _b
684 * This function will clip the first argument between
686 * It asserts _b >= 0.
689 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_clipz(
695 /** @brief Truncated division
697 * @param[in] _a first argument
698 * @param[in] _b second argument
700 * @return trunc( _a / _b )
702 * This function will divide the first argument by
703 * the second argument, with rounding toward 0.
704 * If _b == 0 and _a < 0, the function will return MIN_RANGE.
705 * If _b == 0 and _a == 0, the function will return 0.
706 * If _b == 0 and _a > 0, the function will return MAX_RANGE.
708 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_div(
712 /** @brief Fractional saturating divide
714 * @param[in] _a first argument
715 * @param[in] _b second argument
719 * This function will perform fixed point division of
720 * the first argument by the second argument, with rounding toward 0.
721 * In case of overflow it will saturate.
722 * If _b == 0 and _a < 0, the function will return MIN_RANGE.
723 * If _b == 0 and _a == 0, the function will return 0.
724 * If _b == 0 and _a > 0, the function will return MAX_RANGE.
726 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_qdiv(
732 * @param[in] _a first argument
733 * @param[in] _b second argument
737 * This function will return the remainder r = _a - _b * trunc( _a / _b ),
738 * Note that the sign of the remainder is always equal to the sign of _a.
739 * If _b == 0 the function will return _a.
741 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_mod(
745 /** @brief Unsigned integer Square root
747 * @param[in] _a input
749 * @return Integer square root of _a
751 * This function will calculate the Integer square root of _a
753 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w_unsigned OP_1w_sqrt_u(
754 const tvector1w_unsigned _a);
758 /** @brief Multiplexer
760 * @param[in] _a first argument
761 * @param[in] _b second argument
762 * @param[in] _c condition
764 * @return _c ? _a : _b
766 * This function will return _a if the condition _c
767 * is true and _b otherwise.
769 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_mux(
774 /** @brief Average without rounding
776 * @param[in] _a first operand
777 * @param[in] _b second operand
779 * @return (_a + _b) >> 1
781 * This function will add _a and _b, and right shift
782 * the result by one without rounding. No overflow
783 * will occur because addition is performed in the
786 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_avg(
790 /** @brief Average with rounding
792 * @param[in] _a first argument
793 * @param[in] _b second argument
795 * @return (_a + _b) >> 1
797 * This function will add _a and _b at full precision,
798 * and right shift with rounding the result with 1 bit.
799 * Depending on the rounding mode of the core
800 * it will round to nearest or to nearest even.
802 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_avgrnd(
808 * @param[in] _a first argument
809 * @param[in] _b second argument
811 * @return (_a < _b) ? _a : _b;
813 * This function will return the smallest of both
816 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_min(
822 * @param[in] _a first argument
823 * @param[in] _b second argument
825 * @return (_a > _b) ? _a : _b;
827 * This function will return the largest of both
830 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w OP_1w_max(
834 #ifndef INLINE_ISP_OP1W
835 #define STORAGE_CLASS_ISP_OP1W_FUNC_C
836 #define STORAGE_CLASS_ISP_OP1W_DATA_C const
837 #else /* INLINE_ISP_OP1W */
838 #define STORAGE_CLASS_ISP_OP1W_FUNC_C STORAGE_CLASS_ISP_OP1W_FUNC_H
839 #define STORAGE_CLASS_ISP_OP1W_DATA_C STORAGE_CLASS_ISP_OP1W_DATA_H
840 #include "isp_op1w.c"
841 #define ISP_OP1W_INLINED
842 #endif /* INLINE_ISP_OP1W */
844 #endif /* __ISP_OP1W_H_INCLUDED__ */