GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / hive_isp_css_include / host / isp_op2w.h
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, Intel Corporation.
4  *
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.
8  *
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
12  * more details.
13  */
14
15 #ifndef __ISP_OP2W_H_INCLUDED__
16 #define __ISP_OP2W_H_INCLUDED__
17
18 /*
19  * This file is part of the Multi-precision vector operations exstension package.
20  */
21
22 /*
23  * Double-precision vector operations
24  */
25
26 /*
27  * Prerequisites:
28  *
29  */
30 #include "storage_class.h"
31
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 */
39
40 /*
41  * Double-precision data type specification
42  */
43
44 #include "isp_op2w_types.h"
45
46 /*
47  * Double-precision prototype specification
48  */
49
50 /* Arithmetic */
51
52 /** @brief bitwise AND
53  *
54  * @param[in] _a        first argument
55  * @param[in] _b        second argument
56  *
57  * @return              bitwise and of both input arguments
58  *
59  * This function will calculate the bitwise and.
60  * result = _a & _b
61  */
62 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_and(
63     const tvector2w     _a,
64     const tvector2w     _b);
65
66 /** @brief bitwise OR
67  *
68  * @param[in] _a        first argument
69  * @param[in] _b        second argument
70  *
71  * @return              bitwise or of both input arguments
72  *
73  * This function will calculate the bitwise or.
74  * result = _a | _b
75  */
76 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_or(
77     const tvector2w     _a,
78     const tvector2w     _b);
79
80 /** @brief bitwise XOR
81  *
82  * @param[in] _a        first argument
83  * @param[in] _b        second argument
84  *
85  * @return              bitwise xor of both input arguments
86  *
87  * This function will calculate the bitwise xor.
88  * result = _a ^ _b
89  */
90 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_xor(
91     const tvector2w     _a,
92     const tvector2w     _b);
93
94 /** @brief bitwise inverse
95  *
96  * @param[in] _a        first argument
97  *
98  * @return              bitwise inverse of both input arguments
99  *
100  * This function will calculate the bitwise inverse.
101  * result = ~_a
102  */
103 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_inv(
104     const tvector2w     _a);
105
106 /* Additive */
107
108 /** @brief addition
109  *
110  * @param[in] _a        first argument
111  * @param[in] _b        second argument
112  *
113  * @return              sum of both input arguments
114  *
115  * This function will calculate the sum of the input arguments.
116  * in case of overflow it will wrap around.
117  * result = _a + _b
118  */
119 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_add(
120     const tvector2w     _a,
121     const tvector2w     _b);
122
123 /** @brief subtraction
124  *
125  * @param[in] _a        first argument
126  * @param[in] _b        second argument
127  *
128  * @return              _b subtracted from _a.
129  *
130  * This function will subtract _b from _a.
131  * in case of overflow it will wrap around.
132  * result = _a - _b
133  */
134 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_sub(
135     const tvector2w     _a,
136     const tvector2w     _b);
137
138 /** @brief saturated addition
139  *
140  * @param[in] _a        first argument
141  * @param[in] _b        second argument
142  *
143  * @return              saturated sum of both input arguments
144  *
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);
148  */
149 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_addsat(
150     const tvector2w     _a,
151     const tvector2w     _b);
152
153 /** @brief saturated subtraction
154  *
155  * @param[in] _a        first argument
156  * @param[in] _b        second argument
157  *
158  * @return              saturated subtraction of both input arguments
159  *
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);
163  */
164 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subsat(
165     const tvector2w     _a,
166     const tvector2w     _b);
167
168 /** @brief subtraction with shift right and rounding
169  *
170  * @param[in] _a        first argument
171  * @param[in] _b        second argument
172  *
173  * @return              (a - b) >> 1
174  *
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
179  *
180  * Note: This function will be deprecated due to
181  * the naming confusion and it will be replaced
182  * by "OP_2w_subhalfrnd".
183  */
184 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subasr1(
185     const tvector2w     _a,
186     const tvector2w     _b);
187
188 /** @brief Subtraction with shift right and rounding
189  *
190  * @param[in] _a        first operand
191  * @param[in] _b        second operand
192  *
193  * @return              (_a - _b) >> 1
194  *
195  * This function subtracts _b from _a and right shifts
196  * the result by 1 bit with rounding.
197  * No overflow can occur.
198  */
199 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subhalfrnd(
200     const tvector2w     _a,
201     const tvector2w     _b);
202
203 /** @brief Subtraction with shift right and no rounding
204  *
205  * @param[in] _a        first operand
206  * @param[in] _b        second operand
207  *
208  * @return              (_a - _b) >> 1
209  *
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.
213  */
214 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subhalf(
215     const tvector2w     _a,
216     const tvector2w     _b);
217
218 /** @brief saturated absolute value
219  *
220  * @param[in] _a        input
221  *
222  * @return              saturated absolute value of the input
223  *
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>
228  */
229 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_abs(
230     const tvector2w     _a);
231
232 /** @brief saturated absolute difference
233  *
234  * @param[in] _a        first argument
235  * @param[in] _b        second argument
236  *
237  * @return              sat(abs(sat(a-b)));
238  *
239  * This function will calculate the saturated absolute value
240  * of the saturated difference of both inputs.
241  * result = sat(abs(sat(_a - _b)));
242  */
243 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subabssat(
244     const tvector2w     _a,
245     const tvector2w     _b);
246
247 /* Multiplicative */
248
249 /** @brief integer multiply
250  *
251  * @param[in] _a        first argument
252  * @param[in] _b        second argument
253  *
254  * @return              product of _a and _b
255  *
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.
260  * result = _a * _b;
261  */
262 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mul(
263     const tvector2w     _a,
264     const tvector2w     _b);
265
266 /** @brief fractional saturating multiply
267  *
268  * @param[in] _a        first argument
269  * @param[in] _b        second argument
270  *
271  * @return              saturated product of _a and _b
272  *
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);
278  */
279 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_qmul(
280     const tvector2w     _a,
281     const tvector2w     _b);
282
283 /** @brief fractional saturating multiply with rounding
284  *
285  * @param[in] _a        first argument
286  * @param[in] _b        second argument
287  *
288  * @return              product of _a and _b
289  *
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);
297  */
298
299 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_qrmul(
300     const tvector2w     _a,
301     const tvector2w     _b);
302
303 /* Comparative */
304
305 /** @brief equal
306  *
307  * @param[in] _a        first argument
308  * @param[in] _b        second argument
309  *
310  * @return              _a == _b
311  *
312  * This function will return true if both inputs
313  * are equal, and false if not equal.
314  */
315 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_eq(
316     const tvector2w     _a,
317     const tvector2w     _b);
318
319 /** @brief not equal
320  *
321  * @param[in] _a        first argument
322  * @param[in] _b        second argument
323  *
324  * @return              _a != _b
325  *
326  * This function will return false if both inputs
327  * are equal, and true if not equal.
328  */
329 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_ne(
330     const tvector2w     _a,
331     const tvector2w     _b);
332
333 /** @brief less or equal
334  *
335  * @param[in] _a        first argument
336  * @param[in] _b        second argument
337  *
338  * @return              _a <= _b
339  *
340  * This function will return true if _a is smaller
341  * or equal than _b.
342  */
343 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_le(
344     const tvector2w     _a,
345     const tvector2w     _b);
346
347 /** @brief less then
348  *
349  * @param[in] _a        first argument
350  * @param[in] _b        second argument
351  *
352  * @return              _a < _b
353  *
354  * This function will return true if _a is smaller
355  * than _b.
356  */
357 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_lt(
358     const tvector2w     _a,
359     const tvector2w     _b);
360
361 /** @brief greater or equal
362  *
363  * @param[in] _a        first argument
364  * @param[in] _b        second argument
365  *
366  * @return              _a >= _b
367  *
368  * This function will return true if _a is greater
369  * or equal than _b.
370  */
371 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_ge(
372     const tvector2w     _a,
373     const tvector2w     _b);
374
375 /** @brief greater than
376  *
377  * @param[in] _a        first argument
378  * @param[in] _b        second argument
379  *
380  * @return              _a > _b
381  *
382  * This function will return true if _a is greater
383  * than _b.
384  */
385 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_gt(
386     const tvector2w     _a,
387     const tvector2w     _b);
388
389 /* Shift */
390
391 /** @brief aritmetic shift right
392  *
393  * @param[in] _a        input
394  * @param[in] _b        shift amount
395  *
396  * @return              _a >> _b
397  *
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.
403  */
404 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asr(
405     const tvector2w     _a,
406     const tvector2w     _b);
407
408 /** @brief aritmetic shift right with rounding
409  *
410  * @param[in] _a        input
411  * @param[in] _b        shift amount
412  *
413  * @return              _a >> _b
414  *
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.
422  */
423 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asrrnd(
424     const tvector2w     _a,
425     const tvector2w     _b);
426
427 /** @brief saturating aritmetic shift left
428  *
429  * @param[in] _a        input
430  * @param[in] _b        shift amount
431  *
432  * @return              _a << _b
433  *
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.
442  */
443 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asl(
444     const tvector2w     _a,
445     const tvector2w     _b);
446
447 /** @brief saturating aritmetic shift left
448  *
449  * @param[in] _a        input
450  * @param[in] _b        shift amount
451  *
452  * @return              _a << _b
453  *
454  * This function is identical to OP_2w_asl( )
455  */
456 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_aslsat(
457     const tvector2w     _a,
458     const tvector2w     _b);
459
460 /** @brief logical shift left
461  *
462  * @param[in] _a        input
463  * @param[in] _b        shift amount
464  *
465  * @return              _a << _b
466  *
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.
472  */
473 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_lsl(
474     const tvector2w     _a,
475     const tvector2w     _b);
476
477 /** @brief logical shift right
478  *
479  * @param[in] _a        input
480  * @param[in] _b        shift amount
481  *
482  * @return              _a >> _b
483  *
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.
489  */
490 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_lsr(
491     const tvector2w     _a,
492     const tvector2w     _b);
493
494 /* clipping */
495
496 /** @brief Clip asymmetrical
497  *
498  * @param[in] _a        first argument
499  * @param[in] _b        second argument
500  *
501  * @return              _a clipped between ~_b and b
502  *
503  * This function will clip the first argument between
504  * (-_b - 1) and _b.
505  * It asserts _b >= 0.
506  */
507 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_clip_asym(
508     const tvector2w     _a,
509     const tvector2w     _b);
510
511 /** @brief Clip zero
512  *
513  * @param[in] _a        first argument
514  * @param[in] _b        second argument
515  *
516  * @return              _a clipped beteween 0 and _b
517  *
518  * This function will clip the first argument between
519  * zero and _b.
520  * It asserts _b >= 0.
521  */
522 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_clipz(
523     const tvector2w     _a,
524     const tvector2w     _b);
525
526 /* division */
527
528 /** @brief Truncated division
529  *
530  * @param[in] _a        first argument
531  * @param[in] _b        second argument
532  *
533  * @return              trunc( _a / _b )
534  *
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.
540  */
541 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_div(
542     const tvector2w     _a,
543     const tvector2w     _b);
544
545 /** @brief Saturating truncated division
546  *
547  * @param[in] _a        first argument
548  * @param[in] _b        second argument
549  *
550  * @return              CLIP( trunc( _a / _b ), MIN_RANGE1w, MAX_RANGE1w )
551  *
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.
558  */
559 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector1w OP_2w_divh(
560     const tvector2w     _a,
561     const tvector1w     _b);
562
563 /** @brief Modulo
564  *
565  * @param[in] _a        first argument
566  * @param[in] _b        second argument
567  *
568  * @return              n/a
569  *
570  * This function has not yet been implemented.
571  */
572 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mod(
573     const tvector2w     _a,
574     const tvector2w     _b);
575
576 /** @brief Unsigned Integer Square root
577  *
578  * @param[in] _a        input
579  *
580  * @return              square root of _a
581  *
582  * This function will calculate the unsigned integer square root of _a
583  */
584 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector1w_unsigned OP_2w_sqrt_u(
585         const tvector2w_unsigned     _a);
586
587 /* Miscellaneous */
588
589 /** @brief Multiplexer
590  *
591  * @param[in] _a        first argument
592  * @param[in] _b        second argument
593  * @param[in] _c        condition
594  *
595  * @return              _c ? _a : _b
596  *
597  * This function will return _a if the condition _c
598  * is true and _b otherwise.
599  */
600 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mux(
601     const tvector2w     _a,
602     const tvector2w     _b,
603     const tflags           _c);
604
605 /** @brief Average without rounding
606  *
607  * @param[in] _a        first operand
608  * @param[in] _b        second operand
609  *
610  * @return              (_a + _b) >> 1
611  *
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
615  * proper precision.
616  */
617 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w  OP_2w_avg(
618     const tvector2w     _a,
619     const tvector2w     _b);
620
621 /** @brief Average with rounding
622  *
623  * @param[in] _a        first argument
624  * @param[in] _b        second argument
625  *
626  * @return              (_a + _b) >> 1
627  *
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.
632  */
633 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_avgrnd(
634     const tvector2w     _a,
635     const tvector2w     _b);
636
637 /** @brief Minimum
638  *
639  * @param[in] _a        first argument
640  * @param[in] _b        second argument
641  *
642  * @return              (_a < _b) ? _a : _b;
643  *
644  * This function will return the smallest of both
645  * input arguments.
646  */
647 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_min(
648     const tvector2w     _a,
649     const tvector2w     _b);
650
651 /** @brief Maximum
652  *
653  * @param[in] _a        first argument
654  * @param[in] _b        second argument
655  *
656  * @return              (_a > _b) ? _a : _b;
657  *
658  * This function will return the largest of both
659  * input arguments.
660  */
661 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_max(
662     const tvector2w     _a,
663     const tvector2w     _b);
664
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 */
674
675 #endif /* __ISP_OP2W_H_INCLUDED__ */