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
31 #ifdef INLINE_ISP_OP1W
32 #define STORAGE_CLASS_ISP_OP1W_FUNC_H static inline
33 #define STORAGE_CLASS_ISP_OP1W_DATA_H static inline_DATA
34 #else /* INLINE_ISP_OP1W */
35 #define STORAGE_CLASS_ISP_OP1W_FUNC_H extern
36 #define STORAGE_CLASS_ISP_OP1W_DATA_H extern_DATA
37 #endif /* INLINE_ISP_OP1W */
40 * Single-precision data type specification
43 #include "isp_op1w_types.h"
44 #include "isp_op2w_types.h" // for doubling operations.
47 * Single-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_OP1W_FUNC_H tvector1w
OP_1w_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_OP1W_FUNC_H tvector1w
OP_1w_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_OP1W_FUNC_H tvector1w
OP_1w_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_OP1W_FUNC_H tvector1w
OP_1w_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_OP1W_FUNC_H tvector1w
OP_1w_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_OP1W_FUNC_H tvector1w
OP_1w_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_OP1W_FUNC_H tvector1w
OP_1w_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_OP1W_FUNC_H tvector1w
OP_1w_subsat(
169 /** @brief Unsigned saturated subtraction
171 * @param[in] _a first argument
172 * @param[in] _b second argument
174 * @return saturated subtraction of both input arguments
176 * This function will subtract _b from _a.
177 * in case of overflow it will saturate.
178 * result = CLIP(_a - _b, 0, MAX_RANGE);
180 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w_unsigned
OP_1w_subsat_u(
181 const tvector1w_unsigned _a
,
182 const tvector1w_unsigned _b
);
185 /** @brief subtraction with shift right and rounding
187 * @param[in] _a first argument
188 * @param[in] _b second argument
190 * @return (a - b) >> 1
192 * This function subtracts _b from _a and right shifts
193 * the result by 1 bit with rounding.
194 * No overflow can occur.
195 * result = (_a - _b) >> 1
197 * Note: This function will be deprecated due to
198 * the naming confusion and it will be replaced
199 * by "OP_1w_subhalfrnd".
201 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_subasr1(
205 /** @brief Subtraction with shift right and rounding
207 * @param[in] _a first operand
208 * @param[in] _b second operand
210 * @return (_a - _b) >> 1
212 * This function subtracts _b from _a and right shifts
213 * the result by 1 bit with rounding.
214 * No overflow can occur.
216 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_subhalfrnd(
220 /** @brief Subtraction with shift right and no rounding
222 * @param[in] _a first operand
223 * @param[in] _b second operand
225 * @return (_a - _b) >> 1
227 * This function subtracts _b from _a and right shifts
228 * the result by 1 bit without rounding (i.e. truncation).
229 * No overflow can occur.
231 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_subhalf(
236 /** @brief saturated absolute value
238 * @param[in] _a input
240 * @return saturated absolute value of the input
242 * This function will calculate the saturated absolute value of the input.
243 * in case of overflow it will saturate.
244 * if (_a > 0) return _a;<br>
245 * else return CLIP(-_a, MIN_RANGE, MAX_RANGE);<br>
247 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_abs(
250 /** @brief saturated absolute difference
252 * @param[in] _a first argument
253 * @param[in] _b second argument
255 * @return sat(abs(a-b));
257 * This function will calculate the saturated absolute value
258 * of the saturated difference of both inputs.
259 * result = sat(abs(sat(_a - _b)));
261 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_subabssat(
267 /** @brief doubling multiply
269 * @param[in] _a first argument
270 * @param[in] _b second argument
272 * @return product of _a and _b
274 * This function will calculate the product
275 * of the input arguments and returns a double
277 * No overflow can occur.
280 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector2w
OP_1w_muld(
284 /** @brief integer multiply
286 * @param[in] _a first argument
287 * @param[in] _b second argument
289 * @return product of _a and _b
291 * This function will calculate the product
292 * of the input arguments and returns the LSB
293 * aligned single precision result.
294 * In case of overflow it will wrap around.
297 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_mul(
301 /** @brief fractional saturating multiply
303 * @param[in] _a first argument
304 * @param[in] _b second argument
306 * @return saturated product of _a and _b
308 * This function will calculate the fixed point
309 * product of the input arguments
310 * and returns a single precision result.
311 * In case of overflow it will saturate.
312 * FP_UNITY * FP_UNITY => FP_UNITY.
313 * result = CLIP(_a * _b >> (NUM_BITS-1), MIN_RANGE, MAX_RANGE);
315 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_qmul(
319 /** @brief fractional saturating multiply with rounding
321 * @param[in] _a first argument
322 * @param[in] _b second argument
324 * @return product of _a and _b
326 * This function will calculate the fixed point
327 * product of the input arguments
328 * and returns a single precision result.
329 * FP_UNITY * FP_UNITY => FP_UNITY.
330 * Depending on the rounding mode of the core
331 * it will round to nearest or to nearest even.
332 * result = CLIP(_a * _b >> (NUM_BITS-1), MIN_RANGE, MAX_RANGE);
334 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_qrmul(
342 * @param[in] _a first argument
343 * @param[in] _b second argument
347 * This function will return true if both inputs
348 * are equal, and false if not equal.
350 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags
OP_1w_eq(
356 * @param[in] _a first argument
357 * @param[in] _b second argument
361 * This function will return false if both inputs
362 * are equal, and true if not equal.
364 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags
OP_1w_ne(
368 /** @brief less or equal
370 * @param[in] _a first argument
371 * @param[in] _b second argument
375 * This function will return true if _a is smaller
378 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags
OP_1w_le(
384 * @param[in] _a first argument
385 * @param[in] _b second argument
389 * This function will return true if _a is smaller
392 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags
OP_1w_lt(
396 /** @brief greater or equal
398 * @param[in] _a first argument
399 * @param[in] _b second argument
403 * This function will return true if _a is greater
406 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags
OP_1w_ge(
410 /** @brief greater than
412 * @param[in] _a first argument
413 * @param[in] _b second argument
417 * This function will return true if _a is greater
420 STORAGE_CLASS_ISP_OP1W_FUNC_H tflags
OP_1w_gt(
426 /** @brief aritmetic shift right
428 * @param[in] _a input
429 * @param[in] _b shift amount
433 * This function will shift _a with _b bits to the right,
434 * preserving the sign bit.
435 * It asserts 0 <= _b <= MAX_SHIFT_1W.
437 * The operation count for this function assumes that
438 * the shift amount is a cloned scalar input.
440 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_asr(
444 /** @brief aritmetic shift right with rounding
446 * @param[in] _a input
447 * @param[in] _b shift amount
451 * If _b < NUM_BITS, this function will shift _a with _b bits to the right,
452 * preserving the sign bit, and depending on the rounding mode of the core
453 * it will round to nearest or to nearest even.
454 * If _b >= NUM_BITS, this function will return 0.
455 * It asserts 0 <= _b <= MAX_SHIFT_1W.
456 * The operation count for this function assumes that
457 * the shift amount is a cloned scalar input.
459 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_asrrnd(
463 /** @brief saturating arithmetic shift left
465 * @param[in] _a input
466 * @param[in] _b shift amount
470 * If _b < MAX_BITDEPTH, this function will shift _a with _b bits to the left,
471 * saturating at MIN_RANGE/MAX_RANGE in case of overflow.
472 * If _b >= MAX_BITDEPTH, this function will return MIN_RANGE if _a < 0,
473 * MAX_RANGE if _a > 0, 0 if _a == 0.
474 * (with MAX_BITDEPTH=64)
475 * It asserts 0 <= _b <= MAX_SHIFT_1W.
476 * The operation count for this function assumes that
477 * the shift amount is a cloned scalar input.
479 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_asl(
483 /** @brief saturating aritmetic shift left
485 * @param[in] _a input
486 * @param[in] _b shift amount
490 * This function is identical to OP_1w_asl( )
492 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_aslsat(
496 /** @brief logical shift left
498 * @param[in] _a input
499 * @param[in] _b shift amount
503 * This function will shift _a with _b bits to the left.
504 * It will insert zeroes on the right.
505 * It asserts 0 <= _b <= MAX_SHIFT_1W.
506 * The operation count for this function assumes that
507 * the shift amount is a cloned scalar input.
509 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_lsl(
513 /** @brief logical shift right
515 * @param[in] _a input
516 * @param[in] _b shift amount
520 * This function will shift _a with _b bits to the right.
521 * It will insert zeroes on the left.
522 * It asserts 0 <= _b <= MAX_SHIFT_1W.
523 * The operation count for this function assumes that
524 * the shift amount is a cloned scalar input.
526 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_lsr(
531 /** @brief bidirectional saturating arithmetic shift
533 * @param[in] _a input
534 * @param[in] _b shift amount
536 * @return _a << |_b| if _b is positive
537 * _a >> |_b| if _b is negative
539 * If _b > 0, this function will shift _a with _b bits to the left,
540 * saturating at MIN_RANGE/MAX_RANGE in case of overflow.
541 * if _b < 0, this function will shift _a with _b bits to the right.
542 * It asserts -MAX_SHIFT_1W <= _b <= MAX_SHIFT_1W.
543 * If _b = 0, it returns _a.
545 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_ashift_sat(
549 /** @brief bidirectional non-saturating arithmetic shift
551 * @param[in] _a input
552 * @param[in] _b shift amount
554 * @return _a << |_b| if _b is positive
555 * _a >> |_b| if _b is negative
557 * If _b > 0, this function will shift _a with _b bits to the left,
558 * no saturation is performed in case of overflow.
559 * if _b < 0, this function will shift _a with _b bits to the right.
560 * It asserts -MAX_SHIFT_1W <= _b <= MAX_SHIFT_1W.
561 * If _b = 0, it returns _a.
563 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_ashift(
568 /** @brief bidirectional logical shift
570 * @param[in] _a input
571 * @param[in] _b shift amount
573 * @return _a << |_b| if _b is positive
574 * _a >> |_b| if _b is negative
576 * This function will shift _a with _b bits to the left if _b is positive.
577 * This function will shift _a with _b bits to the right if _b is negative.
578 * It asserts -MAX_SHIFT_1W <= _b <= MAX_SHIFT_1W.
579 * It inserts zeros on the left or right depending on the shift direction:
581 * The operation count for this function assumes that
582 * the shift amount is a cloned scalar input.
584 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_lshift(
591 /** @brief Cast from int to 1w
593 * @param[in] _a input
597 * This function casts the input from integer type to
598 * single precision. It asserts there is no overflow.
601 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_int_cast_to_1w(
604 /** @brief Cast from 1w to int
606 * @param[in] _a input
610 * This function casts the input from single precision type to
611 * integer, preserving value and sign.
614 STORAGE_CLASS_ISP_OP1W_FUNC_H
int OP_1w_cast_to_int(
617 /** @brief Cast from 1w to 2w
619 * @param[in] _a input
623 * This function casts the input from single precision type to
624 * double precision, preserving value and sign.
627 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector2w
OP_1w_cast_to_2w(
630 /** @brief Cast from 2w to 1w
632 * @param[in] _a input
636 * This function casts the input from double precision type to
637 * single precision. In case of overflow it will wrap around.
640 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_2w_cast_to_1w(
644 /** @brief Cast from 2w to 1w with saturation
646 * @param[in] _a input
650 * This function casts the input from double precision type to
651 * single precision after saturating it to the range of single
655 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_2w_sat_cast_to_1w(
660 /** @brief Clip asymmetrical
662 * @param[in] _a first argument
663 * @param[in] _b second argument
665 * @return _a clipped between ~_b and b
667 * This function will clip the first argument between
669 * It asserts _b >= 0.
672 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_clip_asym(
678 * @param[in] _a first argument
679 * @param[in] _b second argument
681 * @return _a clipped beteween 0 and _b
683 * This function will clip the first argument between
685 * It asserts _b >= 0.
688 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_clipz(
694 /** @brief Truncated division
696 * @param[in] _a first argument
697 * @param[in] _b second argument
699 * @return trunc( _a / _b )
701 * This function will divide the first argument by
702 * the second argument, with rounding toward 0.
703 * If _b == 0 and _a < 0, the function will return MIN_RANGE.
704 * If _b == 0 and _a == 0, the function will return 0.
705 * If _b == 0 and _a > 0, the function will return MAX_RANGE.
707 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_div(
711 /** @brief Fractional saturating divide
713 * @param[in] _a first argument
714 * @param[in] _b second argument
718 * This function will perform fixed point division of
719 * the first argument by the second argument, with rounding toward 0.
720 * In case of overflow it will saturate.
721 * If _b == 0 and _a < 0, the function will return MIN_RANGE.
722 * If _b == 0 and _a == 0, the function will return 0.
723 * If _b == 0 and _a > 0, the function will return MAX_RANGE.
725 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_qdiv(
731 * @param[in] _a first argument
732 * @param[in] _b second argument
736 * This function will return the remainder r = _a - _b * trunc( _a / _b ),
737 * Note that the sign of the remainder is always equal to the sign of _a.
738 * If _b == 0 the function will return _a.
740 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_mod(
744 /** @brief Unsigned integer Square root
746 * @param[in] _a input
748 * @return Integer square root of _a
750 * This function will calculate the Integer square root of _a
752 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w_unsigned
OP_1w_sqrt_u(
753 const tvector1w_unsigned _a
);
757 /** @brief Multiplexer
759 * @param[in] _a first argument
760 * @param[in] _b second argument
761 * @param[in] _c condition
763 * @return _c ? _a : _b
765 * This function will return _a if the condition _c
766 * is true and _b otherwise.
768 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_mux(
773 /** @brief Average without rounding
775 * @param[in] _a first operand
776 * @param[in] _b second operand
778 * @return (_a + _b) >> 1
780 * This function will add _a and _b, and right shift
781 * the result by one without rounding. No overflow
782 * will occur because addition is performed in the
785 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_avg(
789 /** @brief Average with rounding
791 * @param[in] _a first argument
792 * @param[in] _b second argument
794 * @return (_a + _b) >> 1
796 * This function will add _a and _b at full precision,
797 * and right shift with rounding the result with 1 bit.
798 * Depending on the rounding mode of the core
799 * it will round to nearest or to nearest even.
801 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_avgrnd(
807 * @param[in] _a first argument
808 * @param[in] _b second argument
810 * @return (_a < _b) ? _a : _b;
812 * This function will return the smallest of both
815 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_min(
821 * @param[in] _a first argument
822 * @param[in] _b second argument
824 * @return (_a > _b) ? _a : _b;
826 * This function will return the largest of both
829 STORAGE_CLASS_ISP_OP1W_FUNC_H tvector1w
OP_1w_max(
833 #ifndef INLINE_ISP_OP1W
834 #define STORAGE_CLASS_ISP_OP1W_FUNC_C
835 #define STORAGE_CLASS_ISP_OP1W_DATA_C const
836 #else /* INLINE_ISP_OP1W */
837 #define STORAGE_CLASS_ISP_OP1W_FUNC_C STORAGE_CLASS_ISP_OP1W_FUNC_H
838 #define STORAGE_CLASS_ISP_OP1W_DATA_C STORAGE_CLASS_ISP_OP1W_DATA_H
839 #include "isp_op1w.c"
840 #define ISP_OP1W_INLINED
841 #endif /* INLINE_ISP_OP1W */
843 #endif /* __ISP_OP1W_H_INCLUDED__ */